creating 2 dummies? or casting 2 of the same spell?

waaaks!

Zinctified
Reaction score
255
In the first thread I posted, I posted about stopping the locust swarm by killing the dummy unit, now I solved the problem, but it still has problems, the dummy kinda uses the spell twice, or maybe 2 dummies are created, because when I deactivated the immolation based spell, it kills the created dummy unit, but looks like there's another dummy unit remaining and still following my hero, but was not killed by the trigger.

I really don't have any idea why does the trigger created two units, it also has weird issues like if I removed the line that sets the global boolean back to false at the same instance the struct and timer was destroyed, it was like creating only 1 dummy. I need this global boolean to check if the spell was deactivated.

JASS:
scope LocustSwarm initializer init

globals
    private constant integer spell = 'A01R'
    private constant integer dspell = 'A01U'
    private boolean array done
endglobals

private struct data
    unit c
    unit u
endstruct

private function con takes nothing returns boolean
    return GetUnitAbilityLevel(GetLearningUnit(),spell) == 1
endfunction

private function callback takes nothing returns boolean
    local timer t = GetExpiredTimer()
    local data d = GetTimerData(t)
    call SetUnitX(d.u,GetUnitX(d.c))
    call SetUnitY(d.u,GetUnitY(d.c))
    call BJDebugMsg("running")
    if done[GetUnitId(d.c)] then
        call KillUnit(d.u)
        set d.u = null
        call ReleaseTimer(t)
        call d.destroy()
        call BJDebugMsg("destroyed")
    endif
    set t = null
    return true
endfunction

private function act2 takes nothing returns boolean
    local unit c = GetTriggerUnit()
    local timer t = NewTimer()
    local integer l = GetUnitAbilityLevel(c,spell)
    local data d = data.create()
    set d.c = c
    if GetIssuedOrderId() == OrderId("immolation") then
        set done[GetUnitId(c)] = false
        set d.u = CreateUnit(GetOwningPlayer(c),'e006',GetUnitX(c),GetUnitY(c),0.0)
        call UnitAddAbility(d.u,dspell)
        call SetUnitAbilityLevel(d.u,dspell,l)
        call IssueImmediateOrder(d.u,"locustswarm")
        call TimerStart(t,0.035,true,function callback)
        call SetTimerData(t,d)
        call BJDebugMsg("start")
    elseif GetIssuedOrderId() == OrderId("unimmolation") then
        set done[GetUnitId(c)] = true
        call BJDebugMsg("done")
    endif
    set c = null
    set t = null
    return true
endfunction

private function act takes nothing returns nothing
    local trigger t = CreateTrigger()
    local unit c = GetLearningUnit()
    call TriggerRegisterUnitEvent( t, c, EVENT_UNIT_ISSUED_ORDER )
    call TriggerAddAction(t,function act2)
    set c = null
    set t = null
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call XE_PreloadAbility(dspell)
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_HERO_SKILL)
    call TriggerAddCondition(t,Condition(function con))
    call TriggerAddAction(t,function act)
endfunction

endscope

EDIT:
updated the code, now working correctly, but with the debug message I added, it really is acting weird, it posted two "start", I'll show you how does it look like:
start
start
running
running
running
running
running
running
running
running
done
done
running
destroyed
running
destroyed
even though the 2 dummy units are successfully killed, the spell is not yet fixed, for I want only an exact number of locusts when the spell is activated, I don't want to double them, also I want to learn how to fix this for future use, thanks!
 

themean

Active Member
Reaction score
7
i want to help

I cant see were your function "GetUnitId()"
I cant understand why your function "callback" return boolean
and why you set d.u=createunit(...) before create him
maybe you must use
call createunit(...)
set d.u=GetLastCreatedUnit
test this and tell me what is happend???
Good luck:thup::thup:
and maybe after kill unit in "callback" remove him whit call removeunit(d.u)
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
and why you set d.u=createunit(...) before create him
maybe you must use
call createunit(...)
set d.u=GetLastCreatedUnit

there is nothing wrong with that because CreateUnit() function returns a unit

anyway, you're leaking the whole struct

every time you issue an order to your unit, you will create a struct because the act2 will run and if the order is not equal to "immolation" it will leak because struct never gets destroyed

JASS:
if GetIssuedOrderId() == OrderId("immolation") then


try replacing it with:

JASS:
if GetIssuedOrderId() == OrderId("immolation") and done[GetUnitId(c)] = true then


remember that you can always give your dummy a visible model so you can see how much dummies get created
 

themean

Active Member
Reaction score
7
lol

man maybe you must ignore init function because you dont need
use only act function with condition con
tell me what happened
struct is no problem for you
struct no cause leak just fulled (or filled) but every time when you need you destroy them
JASS:
if GetIssuedOrderId() == OrderId("immolation") and done[GetUnitId(c)] = true then

is no ofer for you because done is no have starting value
i think problem is in jass structure with 2 events like yours maybe cause bug who fire second event 2 times
use call destroytimer(getexpiratetimer) not only set to null to avoid lag
i hope you can do:thup::thup:
 

waaaks!

Zinctified
Reaction score
255
still not working
JASS:
scope LocustSwarm initializer init

globals
    private constant integer spell = 'A01R'
    private constant integer dspell = 'A01U'
    private boolean array done
endglobals

private struct data
    unit c
    unit u
endstruct

private function con takes nothing returns boolean
    return GetUnitAbilityLevel(GetLearningUnit(),spell) == 1
endfunction

private function callback takes nothing returns boolean
    local timer t = GetExpiredTimer()
    local data d = GetTimerData(t)
    call SetUnitX(d.u,GetUnitX(d.c))
    call SetUnitY(d.u,GetUnitY(d.c))
    call BJDebugMsg("running")
    if done[GetUnitId(d.c)] then
        call KillUnit(d.u)
        set d.u = null
        call ReleaseTimer(t)
        call d.destroy()
        call BJDebugMsg("destroyed")
    endif
    set t = null
    return true
endfunction

private function act2 takes nothing returns boolean
    local unit c = GetTriggerUnit()
    local timer t
    local integer l = GetUnitAbilityLevel(c,spell)
    local data d
    if GetIssuedOrderId() == OrderId("immolation") then
        set t = NewTimer()
        set d = data.create()
        set d.c = c
        set done[GetUnitId(c)] = false
        set d.u = CreateUnit(GetOwningPlayer(c),'e006',GetUnitX(c),GetUnitY(c),0.0)
        call UnitAddAbility(d.u,dspell)
        call SetUnitAbilityLevel(d.u,dspell,l)
        call IssueImmediateOrder(d.u,"locustswarm")
        call TimerStart(t,0.035,true,function callback)
        call SetTimerData(t,d)
        set t = null
        call BJDebugMsg("start")
    elseif GetIssuedOrderId() == OrderId("unimmolation") then
        set done[GetUnitId(c)] = true
        call BJDebugMsg("done")
    endif
    set c = null
    return true
endfunction

private function act takes nothing returns nothing
    local trigger t = CreateTrigger()
    local unit c = GetLearningUnit()
    call TriggerRegisterUnitEvent( t, c, EVENT_UNIT_ISSUED_ORDER )
    call TriggerAddAction(t,function act2)
    set c = null
    set t = null
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call XE_PreloadAbility(dspell)
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_HERO_SKILL)
    call TriggerAddCondition(t,Condition(function con))
    call TriggerAddAction(t,function act)
endfunction

endscope


if add this
JASS:
if GetIssuedOrderId() == OrderId("immolation") and done[GetUnitId(c)] == true then

it doesn't run on first cast, but works in the second cast, and it leaks more, starts only 1 timer, and destroys 2 timers, also when my hero drains mana, until the immolation deactivates itself, it does'nt kill the dummy unit
 

themean

Active Member
Reaction score
7
!!

man try without init function
JASS:
scope LocustSwarm initializer act

JASS:


private function con2 takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(),spell) != 0
endfunction

 
private function act takes nothing returns nothing
    local trigger t = CreateTrigger()
    local unit c = GetLearningUnit()
    call TriggerRegisterUnitEvent( t, c, EVENT_UNIT_ISSUED_ORDER )
    call TriggerAddCondition(t,Condition(function con2))
    call TriggerAddAction(t,function act2)
//    set c = null
 //   set t = null
endfunction

try this maybe work
if work remake skill
pls try
 

Tom Jones

N/A
Reaction score
437
Function callback shouldn't return a boolean.
Neither should act2.
I'm amazed that it doesn't crash your editor, it would in the old days.

EVENT_PLAYER_HERO_SKILL gives you access to GetLearnedSkillLevel().

Always use GetTriggerUnit() when appliable, in this case GetLearningUnit() == GetTriggerUnit().

Did you add the spell twice to the hero in the object editor?
 

waaaks!

Zinctified
Reaction score
255
man try without init function
JASS:
scope LocustSwarm initializer act

JASS:
private function con2 takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(),spell) != 0
endfunction

 
private function act takes nothing returns nothing
    local trigger t = CreateTrigger()
    local unit c = GetLearningUnit()
    call TriggerRegisterUnitEvent( t, c, EVENT_UNIT_ISSUED_ORDER )
    call TriggerAddCondition(t,Condition(function con2))
    call TriggerAddAction(t,function act2)
//    set c = null
 //   set t = null
endfunction

try this maybe work
if work remake skill
pls try
don't force me to remake the skill if it doesn't work, there's always a solution for everything, and why the hell should I remove the init function, for I need to register the learning unit as the unit used in my trigger
Function callback shouldn't return a boolean.
Neither should act2.
I'm amazed that it doesn't crash your editor, it would in the old days.

EVENT_PLAYER_HERO_SKILL gives you access to GetLearnedSkillLevel().

Always use GetTriggerUnit() when appliable, in this case GetLearningUnit() == GetTriggerUnit().

Did you add the spell twice to the hero in the object editor?
some member here used to tell me to return booleans when using timer call backs or triggers that are created in the actions or anywhere except init functions (dynamic triggers? is that what they've called it)

and the hero has full abilities in the object editor (5 hero abilities)

EDIT: got it working, I just lack a condition and just positioned some true or false
 

themean

Active Member
Reaction score
7
Im not force you :)

Im not force you just give you an idea
for consultation unit cant use spell before learning(have at lvl 1 or more)
and this event is unnecessary by my opinion
if you find solution pls post
im curious:rolleyes:
sorry if you need because
JASS:
 call XE_PreloadAbility(dspell)

you can create another trigger with this init function
just see whether is a bug in jass
 

saw792

Is known to say things. That is all.
Reaction score
280
Alright themean, stop posting when you clearly don't understand a single word of his code.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top