- Joined
- Sep 12, 2008
- Messages
- 657
hey.. i made a struct, and i made a spell for a request
that uses a loop to go forward, then backwards..
it uses grouputils and timerutils..
but i still cant figure out why the loop wont run..
no matter what i do..
Thanks in advance.
that uses a loop to go forward, then backwards..
it uses grouputils and timerutils..
but i still cant figure out why the loop wont run..
no matter what i do..
JASS:
scope Boomerang initializer OnInit
globals
private timer Tim = null
endglobals
private struct BR
unit u = null
unit t = null
static unit st = null
static unit tttu = null
real x = 0
real y = 0
real x2 = 0
real y2 = 0
real di = 0
real md = 0
real dc = 0
real da = 0
real aoe = 0
boolean bool = false
static group g = null
static method OnCond takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endmethod
static method GroupCond takes nothing returns boolean
return GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.405 and IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(tttu)) == true
endmethod
static method OnLoop takes nothing returns nothing
local real dx
local real dy
local timer t = GetExpiredTimer()
local thistype this
loop
if this == GetTimerData(t) then
set this = 1
else
set this = this + 1
endif
call DisplayTextToForce(GetPlayersAll(), I2S(this))
set tttu = .u
if .dc < .md then
set .dc = .dc + .di
call SetUnitX(.t, GetUnitX(.t) + .di * Cos (GetUnitFacing(.t) * bj_DEGTORAD))
call SetUnitY(.t, GetUnitY(.t) + .di * Sin (GetUnitFacing(.t) * bj_DEGTORAD))
call DisplayTextToForce(GetPlayersAll(), "3")
else
set .dc = .dc - .di
call SetUnitX(.t, GetUnitX(.t) + .di * Cos (GetUnitFacing(.t) * bj_DEGTORAD))
call SetUnitY(.t, GetUnitY(.t) + .di * Sin (GetUnitFacing(.t) * bj_DEGTORAD))
call DisplayTextToForce(GetPlayersAll(), "4")
if SquareRoot(dx * dx + dy * dy) < 25 then
set .bool = false
call DisplayTextToForce(GetPlayersAll(), "5")
endif
endif
if .bool == true then
set g = NewGroup()
call GroupRefresh(g)
call ReleaseGroup(g)
call GroupEnumUnitsInArea(ENUM_GROUP, GetUnitX(.t), GetUnitY(.t), .aoe, Condition(function BR.GroupCond))
loop
set st = FirstOfGroup(ENUM_GROUP)
exitwhen st == null
call UnitDamageTarget(.t, st, .da, true, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
call GroupRemoveUnit(ENUM_GROUP, st)
set st = null
endloop
endif
if .bool == false then
call RemoveUnit(.t)
set .u = null
set .t = null
set .dc = 0
set .md = 0
set .di = 0
endif
exitwhen this == GetTimerData(t)
endloop
endmethod
static method OnCast takes nothing returns nothing
local thistype this = BR.allocate()
call SetTimerData(Tim,this)
call DisplayTextToForce(GetPlayersAll(), I2S(this))
set .u = GetTriggerUnit()
set .x = GetUnitX(.u)
set .y = GetUnitY(.u)
set .t = CreateUnit(GetOwningPlayer(.u), 'h001', .x, .y, 0)
set .x2 = GetLocationX(GetSpellTargetLoc())
set .y2 = GetLocationY(GetSpellTargetLoc())
set .di = 300
set .md = 700
set .aoe = 250
set .da = 100
set .dc = 0
set .bool = true
endmethod
endstruct
private function OnInit takes nothing returns nothing
local trigger DM = CreateTrigger()
set Tim = NewTimer()
call TriggerRegisterAnyUnitEventBJ(DM, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(DM, Condition(function BR.OnCond))
call TriggerAddAction(DM, function BR.OnCast)
call TimerStart(Tim, 0.032, true, function BR.OnLoop)
set DM = null
endfunction
endscope
Thanks in advance.