Don't do knockback in non-PvP areas (#2)
parent
ef9d5f454d
commit
e8ee792fc6
57
interact.lua
57
interact.lua
|
@ -29,16 +29,24 @@ minetest.register_on_protection_violation(function(pos, name)
|
||||||
end
|
end
|
||||||
local player_pos = player:get_pos()
|
local player_pos = player:get_pos()
|
||||||
if pos.y < player_pos.y then
|
if pos.y < player_pos.y then
|
||||||
player:set_pos({
|
player_pos.y = player_pos.y + 1
|
||||||
x = player_pos.x,
|
player:set_pos(player_pos)
|
||||||
y = player_pos.y + 1,
|
|
||||||
z = player_pos.z
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local function can_pvp_at(pos)
|
||||||
|
for id in pairs(areas:getAreasAtPos(pos)) do
|
||||||
|
-- This uses areas:canPvP instead of area.canPvP in case areas:canPvP
|
||||||
|
-- is overridden
|
||||||
|
if areas:canPvP(id) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch)
|
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch)
|
||||||
if not enable_damage then
|
if not enable_damage then
|
||||||
return true
|
return true
|
||||||
|
@ -57,37 +65,22 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local hitterInPvP
|
-- Allow PvP if both players are in a PvP area
|
||||||
-- Check if the hitter is in an area with allowed PvP
|
if can_pvp_at(hitter:get_pos()) and can_pvp_at(player:get_pos()) then
|
||||||
local hitterAreas = areas:getAreasAtPos(hitter:get_pos())
|
|
||||||
-- If the table is empty, PvP is not allowed
|
|
||||||
if not next(hitterAreas) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
-- Do any of the areas have allowed PvP?
|
|
||||||
for _, area in pairs(hitterAreas) do
|
|
||||||
if area.canPvP then
|
|
||||||
hitterInPvP = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if hitterInPvP then
|
|
||||||
-- Check if the victim is in an area with allowed PvP
|
|
||||||
local victimAreas = areas:getAreasAtPos(player:get_pos())
|
|
||||||
-- If the table is empty, PvP is not allowed
|
|
||||||
if not next(victimAreas) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
-- Do any of the areas have allowed PvP?
|
|
||||||
for _, area in pairs(victimAreas) do
|
|
||||||
if area.canPvP then
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Otherwise, it doesn't do damage
|
-- Otherwise, it doesn't do damage
|
||||||
minetest.chat_send_player(player_name, S("PvP is not allowed in this area!"))
|
minetest.chat_send_player(player_name, S("PvP is not allowed in this area!"))
|
||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local old_calculate_knockback = minetest.calculate_knockback
|
||||||
|
function minetest.calculate_knockback(player, hitter, time_from_last_punch, ...)
|
||||||
|
if player:is_player() and hitter and hitter:is_player() and
|
||||||
|
(time_from_last_punch < 0.25 or not can_pvp_at(player:get_pos()) or
|
||||||
|
not can_pvp_at(hitter:get_pos())) then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
return old_calculate_knockback(player, hitter, time_from_last_punch, ...)
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue