Good day ,
I'm working on a script for a game that involves casting a spell at a party. The idea is that the spell can only be cast if all party members are within a certain distance of the caster.
This my code:
The problem I'm having is that even though the code checks that all party members are within the specified distance before casting the spell, invited players can cast the spell from any area without any checks and the code works in the leader only.
I'm not sure why this is happening, and I would appreciate any help or insight anyone can offer. Thank you!
I'm working on a script for a game that involves casting a spell at a party. The idea is that the spell can only be cast if all party members are within a certain distance of the caster.
This my code:
Lua:
local DISTANCE_SQM = 2
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_INVISIBLE)
combat:setArea(createCombatArea(AREA_CIRCLE3X3))
function onCastSpell(creature, variant)
local party = creature:getParty()
if not party then
creature:sendCancelMessage("You are not in a party.")
return false
end
local partyMembers = party:getMembers()
if #partyMembers == 0 then
creature:sendCancelMessage("Your party has no members.")
return false
end
for i, member in ipairs(partyMembers) do
if member:getPosition():getDistance(creature:getPosition()) > DISTANCE_SQM then
creature:sendCancelMessage("Not all party members are within "..DISTANCE_SQM.." sqm.")
return false
end
end
return combat:execute(creature, variant)
end
I'm not sure why this is happening, and I would appreciate any help or insight anyone can offer. Thank you!