Cover all instances

This commit is contained in:
James David Clarke
2024-01-05 14:45:16 +00:00
parent d75b569118
commit 2bb63d1475
2 changed files with 17 additions and 15 deletions

View File

@@ -1,26 +1,27 @@
pvp_choice = {} pvp_choice = {}
-- Function to remove nearby mcl_bows:arrow_entity around a player -- Function to remove all arrow objects attached to a player
local function remove_nearby_arrows(player, radius) local function remove_attached_arrows(player)
if not player or not player:is_player() then if not player or not player:is_player() then
return return
end end
local pos = player:get_pos() -- Get objects within a small radius around the player
local radius = radius or 5 -- default radius of 5 units local nearby_objects = minetest.get_objects_inside_radius(player:get_pos(), 5)
for _, obj in ipairs(nearby_objects) do
-- 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() local luaentity = obj:get_luaentity()
-- Check if the object is the specific arrow entity -- Check if the object is an arrow entity
if luaentity and luaentity.name == "mcl_bows:arrow_entity" then if luaentity and luaentity.name == "mcl_bows:arrow_entity" then
obj:remove() -- Remove the arrow entity -- Check if the arrow is attached to the player
if obj:get_attach() == player then
obj:remove() -- Remove the arrow
end
end end
end end
end end
-- Function to toggle PvP for a player -- Function to toggle PvP for a player
local function toggle_pvp(player) local function toggle_pvp(player)
local pvp_setting = player:get_meta():get_string("pvp_enabled") local pvp_setting = player:get_meta():get_string("pvp_enabled")
@@ -85,12 +86,13 @@ if minetest.get_modpath("mcl_inventory") then
local original_damage_function = mcl_damage.run_modifiers local original_damage_function = mcl_damage.run_modifiers
mcl_damage.run_modifiers = function(obj, damage, reason) mcl_damage.run_modifiers = function(obj, damage, reason)
-- Check if obj and reason.source are valid and if the damage is caused by a projectile -- Check if obj and reason.source are valid and if the damage is caused by a projectile
if obj and obj:is_player() and reason.source and reason.source:is_player() and if obj and obj:is_player() and reason.source and reason.source:is_player() then
(reason.type == "arrow" or reason.type == "fireball") then
-- Check PvP settings for both players -- Check PvP settings for both players
if not is_pvp_enabled(obj) or not is_pvp_enabled(reason.source) then if not is_pvp_enabled(obj) or not is_pvp_enabled(reason.source) then
remove_nearby_arrows(obj, 5) -- Remove nearby arrows within 5 units remove_attached_arrows(obj) -- Remove attached arrows to the player
mcl_burning.extinguish(obj) mcl_hunger.stop_poison(obj) -- Stop poisoning the player
mcl_potions._reset_player_effects(obj) -- Remove all potion effects from the player
mcl_burning.extinguish(obj) -- Extinguish the player if they are on fire
return 0 -- No damage if PvP is disabled for either player return 0 -- No damage if PvP is disabled for either player
end end
end end

View File

@@ -2,4 +2,4 @@ name = pvp_choice
title = PVP Choice title = PVP Choice
description = Enables you to choose weather you want to PVP or not. description = Enables you to choose weather you want to PVP or not.
supported_games = * supported_games = *
optional_depends = mcl_inventory, mcl_damage,mcl_burning optional_depends = mcl_inventory, mcl_damage, mcl_burning, mcl_hunger, mcl_potions