Jonnycakes
New Member
- Reaction score
- 6
Hi, I am working on a skill that is for some reason STILL not working correctly...I think it has to do with the way I am indexing hashtables, but I can't seem to find what is going wrong.
This is a skill that is supposed to spawn a dummy wisp (with vision and true sight) above a tree when cast (the skill is based off of eat tree). When 3 wisps are already there and a 4th one is created, the 1st wisp is then destroyed. This works absolutely fine until the 6th time this ability is cast-then the old wisps stop disappearing. Why is this happening?
This is a skill that is supposed to spawn a dummy wisp (with vision and true sight) above a tree when cast (the skill is based off of eat tree). When 3 wisps are already there and a 4th one is created, the 1st wisp is then destroyed. This works absolutely fine until the 6th time this ability is cast-then the old wisps stop disappearing. Why is this happening?
JASS:
scope wards initializer init
globals
private integer wisps=0
private hashtable h=InitHashtable()
private unit array wards
endglobals
private function conditions takes nothing returns boolean
return GetSpellAbilityId()==039;A00N039;
endfunction
private function destroy takes nothing returns nothing
local integer i=GetHandleId(GetTriggerDestructable())
local unit u=LoadUnitHandle(h, i, 0)
local integer x=wisps-2
set i=GetHandleId(u)
call KillUnit(u)
set wisps=wisps-1
call FlushChildHashtable(h, i)
call DestroyTrigger(GetTriggeringTrigger())
set u=null
endfunction
private function actions takes nothing returns nothing
local unit u=GetTriggerUnit()
local integer id=GetHandleId(u)
local destructable tree=GetSpellTargetDestructable()
local player p=GetOwningPlayer(u)
local unit v=CreateUnit(p, 039;h008039;, GetDestructableX(tree), GetDestructableY(tree), 0)
local trigger t=CreateTrigger()
local integer x=0
call IssueImmediateOrder(GetTriggerUnit(), "stop")
if wisps==3 then
call DestroyTrigger(LoadTriggerHandle(h, GetHandleId(wards[0]), 0))
call KillUnit(wards[0])
loop
exitwhen x==1
set wards[x]=wards[x+1]
set x=x+1
endloop
set wisps=wisps-1
endif
call BJDebugMsg("created..."+I2S(wisps+1))
set wisps=wisps+1
set wards[wisps-1]=v
call RemoveSavedHandle(h, GetHandleId(tree), 0)
call SaveUnitHandle(h, GetHandleId(tree), 0, v)
call TriggerAddAction(t, function destroy)
call TriggerRegisterDeathEvent(t, tree)
call SaveTriggerHandle(h, GetHandleId(v), 0, t)
set t=null
set tree=null
set u=null
set v=null
set p=null
endfunction
//===========================================================================
private function init takes nothing returns nothing
local trigger t=CreateTrigger()
local integer x=0
call TriggerAddAction(t, function actions)
call TriggerAddCondition(t, Condition(function conditions))
loop
exitwhen x==12
call TriggerRegisterPlayerUnitEvent(t, Player(x), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
set x=x+1
endloop
set t=null
endfunction
endscope