Cover all instances
This commit is contained in:
30
init.lua
30
init.lua
@@ -1,26 +1,27 @@
|
||||
pvp_choice = {}
|
||||
|
||||
-- Function to remove nearby mcl_bows:arrow_entity around a player
|
||||
local function remove_nearby_arrows(player, radius)
|
||||
-- Function to remove all arrow objects attached to a player
|
||||
local function remove_attached_arrows(player)
|
||||
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
|
||||
-- Get objects within a small radius around the player
|
||||
local nearby_objects = minetest.get_objects_inside_radius(player:get_pos(), 5)
|
||||
for _, obj in ipairs(nearby_objects) do
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
|
||||
-- Function to toggle PvP for a player
|
||||
local function toggle_pvp(player)
|
||||
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
|
||||
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
|
||||
if obj and obj:is_player() and reason.source and reason.source:is_player() and
|
||||
(reason.type == "arrow" or reason.type == "fireball") then
|
||||
if obj and obj:is_player() and reason.source and reason.source:is_player() then
|
||||
-- Check PvP settings for both players
|
||||
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
|
||||
mcl_burning.extinguish(obj)
|
||||
remove_attached_arrows(obj) -- Remove attached arrows to the player
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
2
mod.conf
2
mod.conf
@@ -2,4 +2,4 @@ name = pvp_choice
|
||||
title = PVP Choice
|
||||
description = Enables you to choose weather you want to PVP or not.
|
||||
supported_games = *
|
||||
optional_depends = mcl_inventory, mcl_damage,mcl_burning
|
||||
optional_depends = mcl_inventory, mcl_damage, mcl_burning, mcl_hunger, mcl_potions
|
||||
Reference in New Issue
Block a user