Difference between revisions of "minetest.register on protection violation"
Jump to navigation
Jump to search
ShadowNinja (talk | contribs) (Create page) |
|||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:minetest.register_on_protection_violation}} | {{DISPLAYTITLE:minetest.register_on_protection_violation}} | ||
== Syntax == | == Syntax == | ||
− | <source>minetest.register_on_protection_violation( | + | <source>minetest.register_on_protection_violation(function(pos, playername))</source> |
== Description == | == Description == |
Revision as of 19:01, 2 November 2013
Syntax
minetest.register_on_protection_violation(function(pos, playername))
Description
Registers a function to be called when a player violates protection.
Example
-- Show a message to protection violators
minetest.register_on_protection_violation(function(pos, name)
if not mymod:can_interact(pos, name) then
local pos_string = minetest.pos_to_string(pos)
local owner_string = mymod:get_owner_string(pos)
minetest.chat_send_player(name, pos_string.." is protected by "..owner_string)
end
end)
-- Damage protection violators
minetest.register_on_protection_violation(function(pos, name)
local player = minetest.get_player_by_name(name)
if not player then return end
player:set_hp(math.max(player:get_hp() - 1, 0))
end)