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.
  • 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 The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top