interact.lua 854 B

1234567891011121314151617181920212223242526
  1. local old_is_protected = minetest.is_protected
  2. function minetest.is_protected(pos, name)
  3. if not areas:canInteract(pos, name) then
  4. return true
  5. end
  6. return old_is_protected(pos, name)
  7. end
  8. minetest.register_on_protection_violation(function(pos, name)
  9. if not areas:canInteract(pos, name) then
  10. local player = minetest.get_player_by_name(name)
  11. if player then
  12. local yaw = player:get_look_horizontal() + math.pi
  13. if yaw > 2 * math.pi then
  14. yaw = yaw - 2 * math.pi
  15. end
  16. player:set_look_horizontal(yaw)
  17. player:set_look_vertical(-player:get_look_vertical())
  18. local owners = areas:getNodeOwners(pos)
  19. minetest.chat_send_player(name,("%s is protected by %s."):format(
  20. minetest.pos_to_string(pos), table.concat(owners, ", ")))
  21. end
  22. end
  23. end)