pvp.lua 1.8 KB

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