Changed recipe to give 1 protector, added + button to formspec, tweaked and tidied...
[protector.git] / pvp.lua
1
2 -- get static spawn position
3 local statspawn = (minetest.setting_get_pos("static_spawnpoint") or {x = 0, y = 2, z = 0})
4
5 -- is pvp protection enabled and spawn protected
6 protector.pvp = minetest.setting_getbool("protector_pvp")
7 protector.spawn = (tonumber(minetest.setting_get("protector_pvp_spawn")) or 0)
8
9 -- Disable PVP in your own protected areas
10 if minetest.setting_getbool("enable_pvp") and protector.pvp then
11
12 if minetest.register_on_punchplayer then
13
14 minetest.register_on_punchplayer(
15 function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
16
17 if not player
18 or not hitter then
19 print("[Protector] on_punchplayer called with nil objects")
20 end
21
22 if not hitter:is_player() then
23 return false
24 end
25
26 -- no pvp at spawn area
27 local pos = player:getpos()
28
29 if pos.x < statspawn.x + protector.spawn
30 and pos.x > statspawn.x - protector.spawn
31 and pos.y < statspawn.y + protector.spawn
32 and pos.y > statspawn.y - protector.spawn
33 and pos.z < statspawn.z + protector.spawn
34 and pos.z > statspawn.z - protector.spawn then
35 return true
36 end
37
38 if minetest.is_protected(pos, hitter:get_player_name()) then
39 return true
40 else
41 return false
42 end
43
44 end)
45 else
46 print("[Protector] pvp_protect not active, update your version of Minetest")
47
48 end
49 else
50 print("[Protector] pvp_protect is disabled")
51 end