- Joined
- May 21, 2011
- Messages
- 31
Good Evening everyone,
I'm working on transitioning to LUA. I'm trying to remake the melee Blizzard spell in LUA. I have my code almost finished, but I've run into a minor hiccup. I've been banging my head against a wall for hours, so I hope somebody else can see my mistake.
The problem essentially is that a call to GetSpellAbilityUnit() does not return a valid unit depending on where I use it in code. I'm not sure how this function gets the casting unit. I am only using this within the trigger's actions.
The spell is supposed to pick a group of enemies in a range and damage them. I can successfully create a unit group with the enemies in it, and iterate through each enemy. In the callback for iterating through the unit group I try to call GetSpellAbilityUnit() to get the caster, however, this variable seems to be empty. The print statement doesn't print anything, and the damage function doesn't do any damage either.
I made this spell by first coding it the way I would in GUI (and of course testing it), observing the generated LUA, then rewriting it in my own way in a custom trigger. The format and process is identical.
The following is the code
I apologize in advance for the spaghetti code.
I'm working on transitioning to LUA. I'm trying to remake the melee Blizzard spell in LUA. I have my code almost finished, but I've run into a minor hiccup. I've been banging my head against a wall for hours, so I hope somebody else can see my mistake.
The problem essentially is that a call to GetSpellAbilityUnit() does not return a valid unit depending on where I use it in code. I'm not sure how this function gets the casting unit. I am only using this within the trigger's actions.
The spell is supposed to pick a group of enemies in a range and damage them. I can successfully create a unit group with the enemies in it, and iterate through each enemy. In the callback for iterating through the unit group I try to call GetSpellAbilityUnit() to get the caster, however, this variable seems to be empty. The print statement doesn't print anything, and the damage function doesn't do any damage either.
I made this spell by first coding it the way I would in GUI (and of course testing it), observing the generated LUA, then rewriting it in my own way in a custom trigger. The format and process is identical.
The following is the code
Code:
--Globals
fakeBlizzTrg = nil
--End Globals
function valid1()
return (IsUnitAliveBJ(GetFilterUnit()) == true)
end
function valid2()
return (IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetSpellAbilityUnit())) == true)
end
function unitValid()
return GetBooleanAnd(valid1(), valid2())
end
function Trig_Fake_Blizzard_Func001A()
print("Effect Start")
local target = GetEnumUnit()
print(GetUnitName(target))
print(GetUnitName(GetSpellAbilityUnit()))
local damage = 50.0
print(damage)
UnitDamageTargetBJ(GetSpellAbilityUnit(), target, 50.0, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL)
SetUnitMoveSpeed(target, GetUnitDefaultMoveSpeed(target) * 0.35)
print("Effect End")
end
function runTrig()
print("Run")
if (GetSpellAbilityId() == FourCC('AHbz')) then --Ability was blizzard
local caster = GetSpellAbilityUnit()
local castLoc = GetSpellTargetLoc()
IssueImmediateOrderBJ(caster, "stop")
--Blizzard timer
local t1 = CreateTimer()
local count = 0
local maxWaves = 5
local group = CreateGroup() --Holds all units hit by this spell. Used to undo spell effects
print("Start")
TimerStart(t1, 1.00, true, function()
--createBlizzardEffect(caster, castLoc, group)
local ug = GetUnitsInRangeOfLocMatching(
2000.00,
castLoc,
Condition(unitValid)
)
print("Made")
print(CountUnitsInGroup(ug))
ForGroupBJ(ug, Trig_Fake_Blizzard_Func001A)
print("Wave end")
count = count + 1
if(count >= maxWaves) then
--End blizzard
print("End")
PauseTimer(t1)
DestroyTimer(t1)
end
end)
end
end
function initFakeBlizzard()
print("Blizz init")
fakeBlizzTrg = CreateTrigger()
TriggerRegisterAnyUnitEventBJ(fakeBlizzTrg , EVENT_PLAYER_UNIT_SPELL_EFFECT)
TriggerAddAction(fakeBlizzTrg , runTrig)
print("Blizz initialized")
end
I apologize in advance for the spaghetti code.