44 lines
1.5 KiB
Lua
44 lines
1.5 KiB
Lua
pvp_zones = {}
|
|
|
|
-- Function to remove nearby mcl_bows:arrow_entity around a player
|
|
local function remove_nearby_arrows(player, radius)
|
|
if not player or not player:is_player() then
|
|
return
|
|
end
|
|
|
|
local pos = player:get_pos()
|
|
local radius = radius or 5 -- default radius of 5 units
|
|
|
|
-- Get all objects within the radius
|
|
local objects = minetest.get_objects_inside_radius(pos, radius)
|
|
for _, obj in ipairs(objects) do
|
|
local luaentity = obj:get_luaentity()
|
|
-- Check if the object is the specific arrow entity
|
|
if luaentity and luaentity.name == "mcl_bows:arrow_entity" then
|
|
obj:remove() -- Remove the arrow entity
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Register the on punch player event
|
|
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
|
|
if not player or not hitter or not player:is_player() or not hitter:is_player() then
|
|
return
|
|
end
|
|
-- allow PvP only when either player's Y coordinate is below 0
|
|
local ppos = player:get_pos()
|
|
local hpos = hitter:get_pos()
|
|
if not (ppos and hpos) then
|
|
return
|
|
end
|
|
if not (ppos.y < 0 or hpos.y < 0) then
|
|
if minetest.get_modpath("mcl_burning") then
|
|
mcl_burning.extinguish(player)
|
|
end
|
|
core.chat_send_player(hitter:get_player_name(), "No PvP in Y > 0")
|
|
return true -- cancel punch when neither is below y < 0
|
|
end
|
|
-- otherwise allow PvP (fall through)
|
|
end)
|
|
|