Hi!
I've decided to get into Lua scripting, and I want to make a (very) simple spell just to become more familiar with it. However, I'm struggling quite a bit with getting unit groups to work. I have this code:
IsValidEnemyTarget and tempGroup are kept in another custom script in the World Editor, and look like this:
I've tried troubleshooting for a while now, but I can't figure out why I can't get GroupEnumUnitsInRange to work properly.
If I remove the filter, it seems to work, but of course without actually filtering the units.
Thank you for any help!
I've decided to get into Lua scripting, and I want to make a (very) simple spell just to become more familiar with it. However, I'm struggling quite a bit with getting unit groups to work. I have this code:
Code:
EXPLOSION_ID = 1093677104
EXPLOSION_DAMAGE_EFFECT = 'Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl'
EXPLOSION_DAMAGE = 100.0
EXPLOSION_DAMAGE_MOD = 0.75
EXPLOSION_RADIUS = 450.0
function InitTrig_explosion()
local gg_trg_explosion = CreateTrigger()
TriggerRegisterAnyUnitEventBJ(gg_trg_explosion, EVENT_PLAYER_UNIT_SPELL_EFFECT)
TriggerAddAction(gg_trg_explosion, Trig_explosion_Actions)
end
function Trig_explosion_Actions()
if GetSpellAbilityId() == EXPLOSION_ID then
local caster = GetTriggerUnit()
local p = GetUnitLoc(caster)
--Filters out invalid targets, i.e. dead and friendly units.
GroupEnumUnitsInRangeOfLoc(tempGroup, p, EXPLOSION_RADIUS, Filter(IsValidEnemyTarget()))
--Iterates through the filtered group by picking the first unit, executing actions, and then removing it from the group.
for i = 1, CountUnitsInGroup(tempGroup) do
u = FirstOfGroup(tempGroup)
GroupRemoveUnit(tempGroup, u)
UnitDamageTarget(caster, u, EXPLOSION_DAMAGE * EXPLOSION_DAMAGE_MOD, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, null)
end
DestroyEffect(AddSpecialEffectLoc(EXPLOSION_DAMAGE_EFFECT, p))
RemoveLocation(p)
p = null
u = null
end
end
IsValidEnemyTarget and tempGroup are kept in another custom script in the World Editor, and look like this:
Code:
tempGroup = CreateGroup()
Code:
function IsValidEnemyTarget()
local u = GetFilterUnit()
return IsUnitEnemy(u, GetOwningPlayer(GetTriggerUnit())) and GetWidgetLife(u) > .405
end
I've tried troubleshooting for a while now, but I can't figure out why I can't get GroupEnumUnitsInRange to work properly.
If I remove the filter, it seems to work, but of course without actually filtering the units.
Thank you for any help!