Difference between revisions of "minetest.register on protection violation"

From Minetest Developer Wiki
Jump to navigation Jump to search
m (Add sort key)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
{{UnofficialLua}}
 
{{DISPLAYTITLE:minetest.register_on_protection_violation}}
 
{{DISPLAYTITLE:minetest.register_on_protection_violation}}
== Syntax ==
 
<source>minetest.register_on_protection_violation(function(pos, playername))</source>
 
  
== Description ==
+
See [https://minetest.gitlab.io/minetest/minetest-namespace-reference/ minetest.register_on_protection_violation] in the Lua API documentation.
Registers a function to be called when a player violates protection.
 
  
 
== Example ==
 
== Example ==

Latest revision as of 13:51, 25 October 2022

Mbox warning.png This page contains unofficial, low-quality Lua API documentation and is likely to be outdated or wrong. Do not rely on it!
For the official and up-to-date documentation, see Lua API Documentation.
Mbox warning.png This page has been proposed for deletion for the following reason: "Contains unofficial and potentially outdated, redundant and inconsistent Lua API information"
If you don't think that this page should be deleted, please explain why on the talk page.


See minetest.register_on_protection_violation in the Lua API documentation.

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)