Been trying to make timed abilities but can't seem to work ;_;.. Like when I use ability1 and add ability2 in I can't seem to get the trigger of ability2 to work.
I think that the problem lies in the remove function. Any ideas? Thanks :^)
JASS:
struct Punch
private static constant integer SPELL_ID = 'A002'
private static constant integer SPELL_ID1 = 'A001'
private static constant integer BUFF_CODE = 'B000'
private static constant integer UNIT_CODE = 'u000'
private static constant real TIMEOUT = 1.5 //0.03125
private thistype next
private thistype prev
private static timer iterator = CreateTimer()
private static integer count = 0
private unit caster
private unit target
private integer spell
private real damage = 10.
private method destroy takes nothing returns nothing
/*
* Deallocate this instance.
*/
call this.deallocate()
/*
* We remove the instance from the linked list.
*/
set this.next.prev = this.prev
set this.prev.next = this.next
/*
* We decrease the count by 1.
* If the count is 0, we pause the timer.
*/
set count = count - 1
if count == 0 then
call PauseTimer(iterator)
endif
/*
* We null the data in the struct.
* This is completely optional. It doesn't really make a difference
* at all. (Unless you're casting the spell some hundreds of times.)
* If you have some real memory intense systems in your map,
* you might want to do this, especially if your struct has a lot of data.
*
* These are global variables, so they will be recycled eventually.
* It's all up to you, my friend.
*/
set this.caster = null
set this.target = null
// Code.
endmethod
private static method periodic takes nothing returns nothing
/*
* Starting from the first instance, we loop
* over all the instance in the list until we hit
* a dead-end.
*/
local thistype this = thistype(0).next
local group g = CreateGroup()
local unit u
local real x
local real y
local real face
local real angBetween
local real theta
loop
exitwhen this == 0
debug call BJDebugMsg(I2S(this))
if this.spell == SPELL_ID then //if spell is punch
//debug call BJDebugMsg("Right Punch")
call UnitRemoveAbility(this.caster, SPELL_ID) //remove punch
call UnitAddAbility(this.caster, SPELL_ID1) //add combo punch
elseif this.spell == SPELL_ID1 then
//debug call BJDebugMsg("Left Punch")
call UnitRemoveAbility(this.caster, SPELL_ID1) //remove combo punch
call UnitAddAbility(this.caster, SPELL_ID) //add punch
endif
set x = GetUnitX(this.caster)
set y = GetUnitY(this.caster)
set face = GetUnitFacing(this.caster)
//call BJDebugMsg(I2S(this.spell) + " id")
call GroupEnumUnitsInRange(g, x, y, 200., null)
loop
set u = FirstOfGroup(g)
if u != null then
call GroupRemoveUnit(g, u)
set angBetween = Atan2(GetUnitY(u)-y,GetUnitX(u)-x)
set theta = Cos(face-angBetween)
if not IsUnitAlly(this.caster, GetOwningPlayer(u)) and theta>0. then
call UnitDamageTarget(this.caster, u, damage, true, false, null, null, null)
endif
endif
endloop
call DestroyGroup(g)
set u = null
// Code.
set this = this.next
endloop
endmethod
private static method run takes nothing returns boolean
/*
* We allocate an instance.
*/
local thistype this = thistype.allocate()
local unit u = GetTriggerUnit()
/*
* We add the instance to the linked list.
*/
set this.next = 0
set this.prev = thistype(0).prev
set thistype(0).prev.next = this
set thistype(0).prev = this
/*
* We increase the count by 1.
* If the count is 1, we start the timer to loop through
* the instances. This is because recasting the spell while
* an instance is already running shouldn't restart the timer.
*/
set count = count + 1
if count == 1 then
call TimerStart(iterator, TIMEOUT, true, function thistype.periodic)
endif
/*
* We set our struct data.
*/
set this.caster = u
set this.spell = GetSpellAbilityId()
//call SetUnitTimeScale(this.caster, 1.)
call SetUnitAnimation(this.caster, "attack")
// Code.
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call RegisterSpellEffectEvent(SPELL_ID, function thistype.run)
call RegisterSpellEffectEvent(SPELL_ID1, function thistype.run)
//call TriggerAddCondition(t, Condition(function thistype.run))
set t = null
endmethod
endstruct
I think that the problem lies in the remove function. Any ideas? Thanks :^)