2015-11-13 12:23:30 +01:00
|
|
|
|
2016-06-07 21:29:06 +02:00
|
|
|
local S = protector.intllib
|
|
|
|
|
2015-11-13 12:23:30 +01:00
|
|
|
-- get static spawn position
|
2017-10-09 14:58:19 +02:00
|
|
|
local statspawn = minetest.string_to_pos(minetest.settings:get("static_spawnpoint"))
|
|
|
|
or {x = 0, y = 2, z = 0}
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2018-09-27 13:52:52 +02:00
|
|
|
-- is spawn protected
|
|
|
|
local protector_spawn = tonumber(minetest.settings:get("protector_spawn")
|
|
|
|
or minetest.settings:get("protector_pvp_spawn")) or 0
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2017-06-06 11:26:54 +02:00
|
|
|
-- is night-only pvp enabled
|
2018-09-27 13:52:52 +02:00
|
|
|
local protector_night_pvp = minetest.settings:get_bool("protector_night_pvp")
|
2017-06-06 11:26:54 +02:00
|
|
|
|
2016-11-02 17:54:19 +01:00
|
|
|
-- disables PVP in your own protected areas
|
2018-09-27 13:52:52 +02:00
|
|
|
if minetest.settings:get_bool("enable_pvp")
|
|
|
|
and minetest.settings:get_bool("protector_pvp") then
|
2015-11-13 12:23:30 +01:00
|
|
|
|
|
|
|
if minetest.register_on_punchplayer then
|
|
|
|
|
2017-06-06 11:26:54 +02:00
|
|
|
minetest.register_on_punchplayer(function(player, hitter,
|
|
|
|
time_from_last_punch, tool_capabilities, dir, damage)
|
2015-11-13 12:23:30 +01:00
|
|
|
|
|
|
|
if not player
|
|
|
|
or not hitter then
|
2022-12-19 19:16:48 +01:00
|
|
|
print("[MOD] Protector - on_punchplayer called with nil objects")
|
2015-11-13 12:23:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if not hitter:is_player() then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
-- no pvp at spawn area
|
2017-10-09 16:29:04 +02:00
|
|
|
local pos = player:get_pos()
|
2015-11-13 12:23:30 +01:00
|
|
|
|
2018-09-27 13:52:52 +02:00
|
|
|
if pos.x < statspawn.x + protector_spawn
|
|
|
|
and pos.x > statspawn.x - protector_spawn
|
|
|
|
and pos.y < statspawn.y + protector_spawn
|
|
|
|
and pos.y > statspawn.y - protector_spawn
|
|
|
|
and pos.z < statspawn.z + protector_spawn
|
|
|
|
and pos.z > statspawn.z - protector_spawn then
|
2015-11-13 12:23:30 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-06-06 11:26:54 +02:00
|
|
|
-- do we enable pvp at night time only ?
|
2018-09-27 13:52:52 +02:00
|
|
|
if protector_night_pvp then
|
2017-06-06 11:26:54 +02:00
|
|
|
|
|
|
|
-- get time of day
|
|
|
|
local tod = minetest.get_timeofday() or 0
|
|
|
|
|
|
|
|
if tod > 0.2 and tod < 0.8 then
|
|
|
|
--
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- is player being punched inside a protected area ?
|
2015-11-13 12:23:30 +01:00
|
|
|
if minetest.is_protected(pos, hitter:get_player_name()) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2017-06-06 11:26:54 +02:00
|
|
|
return false
|
|
|
|
|
2015-11-13 12:23:30 +01:00
|
|
|
end)
|
|
|
|
else
|
2022-12-19 19:16:48 +01:00
|
|
|
print("[MOD] Protector - pvp_protect not active, update your version of Minetest")
|
2015-11-13 12:23:30 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
else
|
2022-12-19 19:16:48 +01:00
|
|
|
print("[MOD] Protector - pvp_protect is disabled")
|
2015-11-13 12:23:30 +01:00
|
|
|
end
|