pvp.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. local S = protector.intllib
  2. -- get static spawn position
  3. local statspawn = minetest.string_to_pos(minetest.settings:get("static_spawnpoint"))
  4. or {x = 0, y = 2, z = 0}
  5. -- is pvp protection enabled
  6. protector.pvp = minetest.settings:get_bool("protector_pvp")
  7. -- is night-only pvp enabled
  8. protector.night_pvp = minetest.settings:get_bool("protector_night_pvp")
  9. -- disables PVP in your own protected areas
  10. if minetest.settings:get_bool("enable_pvp") and protector.pvp then
  11. if minetest.register_on_punchplayer then
  12. minetest.register_on_punchplayer(function(player, hitter,
  13. time_from_last_punch, tool_capabilities, dir, damage)
  14. if not player
  15. or not hitter then
  16. print(S("[Protector] on_punchplayer called with nil objects"))
  17. end
  18. if not hitter:is_player() then
  19. return false
  20. end
  21. -- no pvp at spawn area
  22. local pos = player:get_pos()
  23. if pos.x < statspawn.x + protector.spawn
  24. and pos.x > statspawn.x - protector.spawn
  25. and pos.y < statspawn.y + protector.spawn
  26. and pos.y > statspawn.y - protector.spawn
  27. and pos.z < statspawn.z + protector.spawn
  28. and pos.z > statspawn.z - protector.spawn then
  29. return true
  30. end
  31. -- do we enable pvp at night time only ?
  32. if protector.night_pvp then
  33. -- get time of day
  34. local tod = minetest.get_timeofday() or 0
  35. if tod > 0.2 and tod < 0.8 then
  36. --
  37. else
  38. return false
  39. end
  40. end
  41. -- is player being punched inside a protected area ?
  42. if minetest.is_protected(pos, hitter:get_player_name()) then
  43. return true
  44. end
  45. return false
  46. end)
  47. else
  48. print(S("[Protector] pvp_protect not active, update your version of Minetest"))
  49. end
  50. else
  51. print(S("[Protector] pvp_protect is disabled"))
  52. end