Improve PvP: check hitter areas
parent
758b3d0dd0
commit
db9ca5535e
31
interact.lua
31
interact.lua
|
@ -71,9 +71,9 @@ minetest.register_on_protection_violation(function(pos, name)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, _, _, damage)
|
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch)
|
||||||
if not enable_damage then
|
if not enable_damage then
|
||||||
return false
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If it's a mob, deal damage as usual
|
-- If it's a mob, deal damage as usual
|
||||||
|
@ -87,16 +87,33 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch,
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if the victim is in an area with allowed PvP or in an unprotected area
|
local hitterInPvP
|
||||||
local inAreas = areas:getAreasAtPos(player:get_pos())
|
-- Check if the hitter is in an area with allowed PvP
|
||||||
|
local hitterAreas = areas:getAreasAtPos(hitter:get_pos())
|
||||||
-- If the table is empty, PvP is not allowed
|
-- If the table is empty, PvP is not allowed
|
||||||
if not next(inAreas) then
|
if not next(hitterAreas) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
-- Do any of the areas have allowed PvP?
|
-- Do any of the areas have allowed PvP?
|
||||||
for id, area in pairs(inAreas) do
|
for id, area in pairs(hitterAreas) do
|
||||||
if area.canPvP then
|
if area.canPvP then
|
||||||
return false
|
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 id, area in pairs(victimAreas) do
|
||||||
|
if area.canPvP then
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ PvP enabled=PvP включен
|
||||||
|
|
||||||
@1 is protected by @2.=@1 защищено @2.
|
@1 is protected by @2.=@1 защищено @2.
|
||||||
Wow, wow, take it easy!=Вау-вау, полегче!
|
Wow, wow, take it easy!=Вау-вау, полегче!
|
||||||
PvP is not allowed in this area!=PvP отключено в этой в этой зоне!
|
PvP is not allowed in this area!=PvP отключено в этой зоне!
|
||||||
|
|
||||||
### internal.lua ###
|
### internal.lua ###
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue