Bugged event trigger

Darius34

New Member
Reaction score
30
Code:
function Trig_Spirit_Call_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A003'
endfunction

function SpiritCallEnd takes nothing returns nothing
    local trigger t = GetTriggeringTrigger()
    local unit caster = GetHandleUnit(t,"caster")
    local unit summoned = GetHandleUnit(t,"summoned")
    local integer i = 1
    local integer j = 6
    
    call DisplayTextToForce(GetPlayersAll(),"Summoned has died.")
    
    call PauseUnitBJ(false,caster)
    call SelectUnitForPlayerSingle( caster, GetOwningPlayer(caster) )
    call SetHeroXP( caster, GetHeroXP(summoned), false )
    loop
        exitwhen i > j
        call UnitAddItemByIdSwapped( GetItemTypeId(UnitItemInSlotBJ(summoned, i)), caster )
        set i = i + 1
    endloop
    call DisplayTextToForce(GetPlayersAll(),"Items transferred back.")
    set caster = null
    set summoned = null
endfunction

function Trig_Spirit_Call_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local location targetpt = GetSpellTargetLoc()
    local integer level = GetUnitAbilityLevel(caster,'A003')
    local unit summoned
    local trigger t
    local integer i = 1
    local integer j = 6
    local real facing = GetUnitFacing(caster)

    call PauseUnitBJ(true,caster)
    if level==1 then
        call CreateNUnitsAtLoc(1,'H002',GetOwningPlayer(caster),targetpt,facing)
    elseif level==2 then
        call CreateNUnitsAtLoc(1,'H003',GetOwningPlayer(caster),targetpt,facing)
    elseif level==3 then
        call CreateNUnitsAtLoc(1,'H001',GetOwningPlayer(caster),targetpt,facing)
    endif
    set summoned = GetLastCreatedUnit()
    call DisplayTextToForce(GetPlayersAll(),"Summoned has been created.")
    call SelectUnitForPlayerSingle( summoned, GetOwningPlayer(caster) )
    call UnitApplyTimedLifeBJ( 18, 'BTLF', summoned )
    call SetHeroXP( summoned, GetHeroXP(caster), false )
    loop
        exitwhen i > j
        call UnitAddItemByIdSwapped( GetItemTypeId(UnitItemInSlotBJ(caster, i)), summoned )
        set i = i + 1
    endloop
    call DisplayTextToForce(GetPlayersAll(),"Items transferred.")
    
    call TriggerRegisterUnitEvent(t,summoned,EVENT_UNIT_DEATH)
    call TriggerAddAction(t,function SpiritCallEnd)
    call SetHandleHandle(t, "caster",caster)
    call SetHandleHandle(t, "summoned", summoned)
    call PolledWait(18.)
    call DisplayTextToForce(GetPlayersAll(),"Summoned has died (supposedly).")
    
    call ShowUnit(summoned,false)
    call SpiritCallEnd()
    call RemoveUnit(summoned)
    
    call FlushHandleLocals(t)
    call DestroyTrigger(t)
    set caster = null
    call RemoveLocation(targetpt)
    set summoned = null
    call DisplayTextToForce(GetPlayersAll(),"Done.")    
endfunction

//===========================================================================
function InitTrig_Spirit_Call takes nothing returns nothing
    set gg_trg_Spirit_Call = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Spirit_Call, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Spirit_Call, Condition( function Trig_Spirit_Call_Conditions ) )
    call TriggerAddAction( gg_trg_Spirit_Call, function Trig_Spirit_Call_Actions )
endfunction
This is my trigger. A Unit Dies event does not fire at all. Basically it creates another hero unit at the target point, pauses the caster and after 18 seconds, kills the unit (hence the expiration timer) and returns control to the caster. If the summoned unit dies before the 18 second timer, control will be transferred back anyway.

Now, I have no idea why the event of the trigger t does not fire. I am using Handle Vars, am I doing something wrong there? Also, my code might not be very efficient or 100% leak free, so please correct me if you notice any such errors. Thanks.
 
D

dadads

Guest
Check these:
- Is the "Trigger Enabled" checkbox checked already?
- Have you initialized the game cache somewhere inside your map?
- Is the spell really 'A003' ?
 

Darius34

New Member
Reaction score
30
Have you initialized the game cache somewhere inside your map?
No, I haven't. But I don't remember doing that the last time I used Handle Vars, and it worked. I'll check again.

As for the rest, yes, I've checked those. The spell works all the way to the point where it creates the summoned unit. Then, when the summoned unit expires and dies, nothing more happens, i.e. the dying event does not fire.

I even tried killing the unit manually with a trigger. Didn't work.
 

SFilip

Gone but not forgotten
Reaction score
634
> But I don't remember doing that the last time I used Handle Vars, and it worked.
Game Cache has to be initialized, it can't work without it.
Did you change the LocalVars function so that it returns a global variable? Have you initialized that local variable?
 
L

leetslay

Guest
You need to create the trigger before you can use it.
as it is now your trigger var doesn't point to anything.
your code says "local trigger t"
you have to put "set t = CreateTrigger()"
somewhere after that and before you use it.
 

Darius34

New Member
Reaction score
30
@leetslay
Thanks a lot! The spell works fine now. I completely forgot about that part. :)

I'm sorry SFlip, but I don't understand what you're saying at all. :D I'm very new to the concept Handle Vars uses, and I have no idea how it worked without the game cache. Still, it did work, and it worked the previous time too. Could you explain, please? I'd like to take the chance to learn more.
___________

EDIT: Oh yes, and this may be more of a semantic question, but I thought I'd ask anyway.

When the spell begins the caster is paused and a summoned hero is created. It is set to the level of the caster hero and gains all the caster hero's items. Thus when the spell ends, I transfer the items and experience back from the summoned hero to the caster hero, in the event of the summoned one gaining additionals.

This is where my problem lies: the original caster hero ends up with two of every item it started with. Is it possible for me to check the items of both efficiently and remove all the duplicates, or to prevent the summoned hero from acquiring items? (So that I wouldn't have to transfer at all.) Thanks again, in advance.
 

SFilip

Gone but not forgotten
Reaction score
634
Well in the official handle variables system (found here) you have this little function...
Code:
function LocalVars takes nothing returns gamecache
    // Replace InitGameCache("jasslocalvars.w3v") with a global variable!!
    return InitGameCache("jasslocalvars.w3v")
endfunction
Its used by almost all the functions to access the game cache and it works sort of fine the way it is...
Yet it initializes the gamecache again on every use which is both slow and causes a leak.
Because of this you need to create a global variable of type gamecache (called cache for example) and replace that function with this.
Code:
function LocalVars takes nothing returns gamecache
    return udg_cache
endfunction
And call this on map initialization to initialize the actual gamecache:
set udg_cache = InitGameCache("jasslocalvars.w3v")
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top