- Joined
- Aug 11, 2009
- Messages
- 22
Hello, I tried to create a simple trigger but ran into a problem. Apparently my "function Targets" or "function Enum" isn't right, I don't know why though (new to JASS and vJASS). It doesn't use the global unit U and therefore no units pass the check.
JASS:
scope IllusoryAssault initializer Init
//===============SETUP================
globals
private constant integer SPELL_ID = 'A000'
private constant integer DUMMY_ID = 'h000'
private constant integer DMG_DUMMY_ID = 'h001'
private constant string SFX = "Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl"
private constant damagetype D_TYPE = DAMAGE_TYPE_NORMAL
private constant attacktype A_TYPE = ATTACK_TYPE_SIEGE
endglobals
private function AoE takes nothing returns real
return 200.
endfunction
private function Damage takes integer lvl, integer hstr returns real
return (lvl * 300. + 2. * hstr + 150.)/4
endfunction
!!! private function Targets takes unit target, unit U returns boolean
return (GetWidgetLife(target) > 0.405) and (IsUnitAlly(target, GetOwningPlayer(U)) == false)
endfunction
//==============SETUP ENDS============
globals
private hashtable Hash
private group Group
private unit U
endglobals
!!! private function Enum takes nothing returns boolean
return Targets(GetFilterUnit(), U)
endfunction
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == SPELL_ID
endfunction
private function Timer2 takes nothing returns nothing
local timer t2 = GetExpiredTimer()
local unit u = LoadUnitHandle(Hash, GetHandleId(t2), 0)
local real x = LoadReal(Hash, GetHandleId(t2), 1)
local real y = LoadReal(Hash, GetHandleId(t2), 2)
local real r = LoadReal(Hash, GetHandleId(t2), 3)
local integer i
local real dmg
local unit fog
local unit d
call BJDebugMsg(R2S(r))
call DestroyEffect(AddSpecialEffect(SFX, x, y))
set U = u
call BJDebugMsg(GetUnitName(U))
call GroupEnumUnitsInRange(Group, x, y, AoE, Condition(function Enum))
set i = CountUnitsInGroup(Group)
if (i > 0) then
call BJDebugMsg(I2S(i))
set dmg = r / i
call BJDebugMsg(R2S(dmg))
call CreateUnit(GetOwningPlayer(u), 'hfoo', x, y, 0.)
set d = GetLastCreatedUnit()
loop
set fog = FirstOfGroup(Group)
exitwhen (fog == null)
call UnitDamageTarget(u, fog, dmg, false, false, ATTACK_TYPE_SIEGE, DAMAGE_TYPE_NORMAL, null)
call GroupRemoveUnit(Group, fog)
endloop
endif
call DestroyTimer(t2)
set t2 = null
set u = null
endfunction
private function Timer1 takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit u = LoadUnitHandle(Hash, GetHandleId(t), 0)
call SetUnitTimeScale(u, 1.)
call SetUnitFlyHeight(u, 0., 1000.)
call DestroyTimer(t)
set t = null
set u = null
endfunction
private function Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer lvl = GetUnitAbilityLevel(u, SPELL_ID)
local integer hstr = GetHeroStr(u, true)
local timer t = CreateTimer()
local timer t2 = CreateTimer()
call UnitAddAbility(u, 'Arav')
call UnitRemoveAbility(u, 'Arav')
call SaveUnitHandle(Hash, GetHandleId(t), 0, u)
call SaveUnitHandle(Hash, GetHandleId(t2), 0, u)
call SaveReal(Hash, GetHandleId(t2), 1, GetSpellTargetX())
call SaveReal(Hash, GetHandleId(t2), 2, GetSpellTargetY())
call SaveReal(Hash, GetHandleId(t2), 3, Damage(lvl, hstr))
call SetUnitTimeScale(u, 0.2)
call SetUnitFlyHeight(u, 300., 200.)
call TimerStart(t, 1.3, false, function Timer1)
call TimerStart(t2, 1.8, false, function Timer2)
set u = null
set t = null
set t2 = null
endfunction
private function Init takes nothing returns nothing
local trigger RecklessAssaultTrg = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(RecklessAssaultTrg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition(RecklessAssaultTrg, Condition( function Conditions ) )
call TriggerAddAction( RecklessAssaultTrg, function Actions )
//setting globals
set Hash = InitHashtable()
set Group = CreateGroup()
//preloading effects
call Preload(SFX)
endfunction
endscope