• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Trigger No Longer Works

Status
Not open for further replies.
Level 4
Joined
Jun 8, 2007
Messages
89
#1
Okay, so I had a spell trigger, and I changed some of the function names and messed with scope a bit. Then I changed the Registered Event from the BJ to what it is now, and it stopped working after all of those changes. This is what it is now, and it still wont work, any ideas?

JASS:
function bsLeapConditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A003'
endfunction

function bsLeapActions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit temp
    
    local location loc = GetSpellTargetLoc()
    
    local group enemies = CreateGroup()
    local integer abiLevel = GetUnitAbilityLevel(u, 'A003')
    local integer dmg = R2I(20 + abiLevel * 40)
    local real coeff = 1

    local real x
    local real y
    local real angle
    local real distance
    local real time
    
    //if (IsLocPathable(loc) == false) then
    //    set loc = GetNearestPathableLoc(loc)
        //call DisplayTextToPlayer( GetOwningPlayer(u), "|cffff5000Target Location is not pathable!|r" )
    //endif
        
        // set vars
    set distance = DistanceBetweenPoints(GetUnitLoc(u), loc)
    set time = distance / GetUnitMoveSpeed(GetTriggerUnit())
        
        // initiate jump
    call DCJS_Jump(u, loc, distance/3, time)
    
        //animate walking
    call SetUnitFacingToFaceLocTimed( u, loc, 0.50 )
    call SetUnitAnimation( u, "walk" )
    call SetUnitTimeScalePercent( u, 25.00 )
    
        // wait until jump finishes
    call PolledWait(time)
        // end the animation
    call SetUnitAnimation(u, "stand")
    call SetUnitTimeScalePercent( u, 100.00 )
    
        // find affected enemies
    set loc = GetUnitLoc(u)
    call GroupEnumUnitsInRangeOfLoc(enemies, loc, 350.0, null)
    
    set x = GetUnitX(u)
    set y = GetUnitY(u)
    
        // loop the group, doing knockback
    loop
        set temp = FirstOfGroup(enemies)
        exitwhen temp == null
    
        if IsUnitEnemy(temp, GetOwningPlayer(u)) then
                //damage units
        call damageUnit(u, temp, dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_PHYSICAL, coeff, false)
            
                // knockback units
            set angle = 57.29582 * Atan2(GetUnitY(temp) - y, GetUnitX(temp) - x)
            call KnockbackTarget(temp, angle, 600, 60, true)
        endif
    
        call GroupRemoveUnit(enemies, temp)
    endloop
    
        // delete data
    call RemoveLocation(loc)
    call DestroyGroup(enemies)
        // clear leaks
    set enemies = null
    set u = null
    set temp = null
    set loc = null
endfunction

//===========================================================================
function InitTrig_bsLeap takes nothing returns nothing
    local integer i = 1
    set gg_trg_bsLeap1 = CreateTrigger()

        // register for all but players 1 and 7
    loop
        call TriggerRegisterPlayerUnitEvent(gg_trg_bsLeap1, Player(i), EVENT_PLAYER_UNIT_ATTACKED, null)
  
        exitwhen i == 11
  
        if (i == 5) then
            set i = 7
        else
            set i = i + 1
        endif
    endloop
    
    call TriggerAddAction(gg_trg_bsLeap1, function bsLeapActions)
    call TriggerAddCondition(gg_trg_bsLeap1, Condition(function bsLeapConditions))
endfunction

#2
My walk animation in the above trigger never did work... How would I go about fixing that? hehe...


Also....
#3

Okay, so this is probably a pretty noob-esque question, but here it goes.
Im relatively new to Jass, and upon looking around in various forums to get a feel for the code, I've seen various uses of

Code:
scope blah initializer Init

// insert code/functionality here

endscope

I know that this is functionality from the JNGP, but I don't really seem to know how it works. I know that it makes it so that private funcs can't be seen outside, but waht else does it do, because it seems to not let me use function outside of the scope as well?

- Thanks for your time :wink:
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Not bad for a Jass beginner......

In JASS you can always test if a function was even called, just insert a BJDebugMsg(<any string here>) after the local declarations in bsLeapActions function. But I don't see any reason for it to not work, since the InitTrig_ function looks fine.

The code seems flawless (except a few leaks, but it doesn't matter), I really don't see the problem just now, I'll look at it again later.

If the walk animation doesn't work, maybe the unit doesn't have a walk animation (which is really rare and only for imported models and such). You can try to mess with SetUnitAnimationByIndex, you can download a .mdx to .mdl converter, convert your model and look in the notepad under "sequences", the first animation starts with 0, then 1, 2, 3..... and find the "walk" animation index (that's the parameter needed for SetUnitAnimationByIndex).

And you can wrap your code in a scope because then you can have short function names (and make them private) which would save you some time and you wouldn't have to worry about having multiple functions with same names (I name my actions function "Actions" and my conditions function "Conditions", for example). And scope lets you use vJass features, like global blocks, structs etc.

Sorry I haven't been much of a help, I didn't know I won't find the problem in such a simple code.
 
Level 4
Joined
Jun 8, 2007
Messages
89
Ok, yeah, that was a really stupid mistake.. hehe. I also noticed that I never registered my condition before, but it still doesn't work with the changes, and I'm still not sure why...

Thanks for the help.

JASS:
function Trig_bsLeap_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A003'
endfunction

function Trig_bsLeap_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit temp
    
    local location loc = GetSpellTargetLoc()
    
    local group enemies = CreateGroup()
    local integer abiLevel = GetUnitAbilityLevel(u, 'A003')
    local integer dmg = R2I(20 + abiLevel * 40)
    local real coeff = 1

    local real x
    local real y
    local real angle
    local real distance
    local real time
    
    //if (IsLocPathable(loc) == false) then
    //    set loc = GetNearestPathableLoc(loc)
        //call DisplayTextToPlayer( GetOwningPlayer(u), "|cffff5000Target Location is not pathable!|r" )
    //endif
        
        // set vars
    set distance = DistanceBetweenPoints(GetUnitLoc(u), loc)
    set time = distance / GetUnitMoveSpeed(GetTriggerUnit())
        
        // initiate jump
    call DCJS_Jump(u, loc, distance/3, time)
    
        //animate walking
    call SetUnitFacingToFaceLocTimed( u, loc, 0.50 )
    call SetUnitAnimation( u, "walk" )
    call SetUnitTimeScalePercent( u, 25.00 )
    
        // wait until jump finishes
    call PolledWait(time)
        // end the animation
    call SetUnitAnimation(u, "stand")
    call SetUnitTimeScalePercent( u, 100.00 )
    
        // find affected enemies
    set loc = GetUnitLoc(u)
    call GroupEnumUnitsInRangeOfLoc(enemies, loc, 350.0, null)
    
    set x = GetUnitX(u)
    set y = GetUnitY(u)
    
        // loop the group, doing knockback
    loop
        set temp = FirstOfGroup(enemies)
        exitwhen temp == null
    
        if IsUnitEnemy(temp, GetOwningPlayer(u)) then
                //damage units
        call damageUnit(u, temp, dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_PHYSICAL, coeff, false)
            
                // knockback units
            set angle = 57.29582 * Atan2(GetUnitY(temp) - y, GetUnitX(temp) - x)
            call KnockbackTarget(temp, angle, 600, 60, true)
        endif
    
        call GroupRemoveUnit(enemies, temp)
    endloop
    
        // delete data
    call RemoveLocation(loc)
    call DestroyGroup(enemies)
        // clear leaks
    set enemies = null
    set u = null
    set temp = null
    set loc = null
endfunction

//===========================================================================
function InitTrig_bsLeap takes nothing returns nothing
    local integer i = 1
    
    set gg_trg_bsLeap = CreateTrigger(  )
    call TriggerAddAction( gg_trg_bsLeap, function Trig_bsLeap_Actions )
    
        // register for all but players 1 and 7
    loop
        call TriggerRegisterPlayerUnitEvent(gg_trg_bsLeap1, Player(i), EVENT_PLAYER_UNIT_SPELL_CAST, null)
  
        exitwhen i == 11
  
        if (i == 5) then
            set i = 7
        else
            set i = i + 1
        endif
    endloop
    
    call TriggerAddCondition(gg_trg_bsLeap1, Condition(function Trig_bsLeap_Conditions))
endfunction

*EDIT*

While test using BJDebugMsg(), I have found that the trigger never even gets to the condition, meaning something is wrong with the Event, but I'm still not sure what...
 
Last edited:
Level 4
Joined
Jun 8, 2007
Messages
89
*EDIT* Problem Below Fixed (the one that I put into dark red at the bottom of the post), I simply set it to EVENT_PLAYER_UNIT_SPELL_CAST and now it works, although i had it at that before... Anyway, am I correct to assume that EVENT_PLAYER_UNIT_SPELL_FINISH doesn't allow GetSpellTargetLoc()?

Another question (I might as well not spam with another thread, heh).
Is there any reason I would want to use a PolledWait(time) over a TriggerSleepAction(time)? To me it seems that the latter does the same with a lot less code/calls...

Plus, you were talking about leaks. Could you point me in the correct direction of where they are exactly? Or am I leak free now, I tried me best. heh. Oh, and do you have to set parameters to null as well?

JASS:
function Trig_bsLeap_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A003'
endfunction

function Trig_bsLeap_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit enemy
    
    local location locTarget = GetSpellTargetLoc()
    local location locCaster = GetUnitLoc(caster)
    
    local group enemies = CreateGroup()
    local integer abiLevel = GetUnitAbilityLevel(caster, 'A003')
    local integer dmg = R2I(20 + abiLevel * 40)
    local real coeff = 1

    local real x
    local real y
    local real angle
    local real distance
    local real time
    
    //if (IsLocPathable(loc) == false) then
    //    set loc = GetNearestPathableLoc(loc)
        //call DisplayTextToPlayer( GetOwningPlayer(u), "|cffff5000Target Location is not pathable!|r" )
    //endif
        
        // set vars
    set distance = DistanceBetweenPoints(locCaster, locTarget)
    set time = distance / GetUnitMoveSpeed(GetTriggerUnit())
        
        // initiate jump
    call DCJS_Jump(caster, locTarget, distance/3, time)
    
        //animate walking
    //call SetUnitFacingToFaceLocTimed( u, loc, 0.50 )

    call SetUnitFacingTimed(caster, AngleBetweenPoints(locCaster, locTarget), .5)
    
    call SetUnitAnimationByIndex( caster, 2 )
    call SetUnitTimeScale( caster, .25 )
    
        // wait until jump finishes
    //call PolledWait(time - 0.25)
    call TriggerSleepAction(time - 0.25)
    
        // end the animation
    call SetUnitAnimation(caster, "stand")
    call SetUnitTimeScale( caster, 1.00 )
    
        // find affected enemies
    call GroupEnumUnitsInRangeOfLoc(enemies, locTarget, 300.0, null)
    
    set x = GetUnitX(caster)
    set y = GetUnitY(caster)
    
        // loop the group, doing knockback
    loop
        set enemy = FirstOfGroup(enemies)
        exitwhen enemy == null
    
        if IsUnitEnemy(enemy, GetOwningPlayer(caster)) then
                //damage units
        call damageUnit(caster, enemy, dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_PHYSICAL, coeff, true)
            
                // knockback units
            set angle = 57.29582 * Atan2(GetUnitY(enemy) - y, GetUnitX(enemy) - x)
            call KnockbackTarget(enemy, angle, 850, 175, true)
        endif
    
        call GroupRemoveUnit(enemies, enemy)
    endloop
    
        // delete data
    call RemoveLocation(locTarget)
    call RemoveLocation(locCaster)
    call DestroyGroup(enemies)
        // clear leaks
    set enemies = null
    set caster = null
    set enemy = null
    set locTarget = null
    set locCaster = null
endfunction

//===========================================================================
function InitTrig_bsLeap takes nothing returns nothing
    local integer i = 0
    
    set gg_trg_bsLeap = CreateTrigger(  )
    call TriggerAddAction( gg_trg_bsLeap, function Trig_bsLeap_Actions )
    
        // register for all but players 1 and 7
    loop
        call TriggerRegisterPlayerUnitEvent(gg_trg_bsLeap, Player(i), EVENT_PLAYER_UNIT_SPELL_CAST, null)

        exitwhen i == 11
  
        if (i == 5) then
            set i = 7
        else
            set i = i + 1
        endif
    endloop
    
    call TriggerAddCondition(gg_trg_bsLeap, Condition(function Trig_bsLeap_Conditions))
endfunction

-Thanks again guys.


Okay, changing the event to EVENT_PLAYER_UNIT_SPELL_FINISH, and fixing my trigger type vars which were gg_trg_bsLeap1 instead of gg_trg_bsLeap, it now at least kind of works again.
Now he just kind of jumps in the same direction the same distance every time I use the ability.
It shouldn't have anything to do with the jump function call, because that is someone else's system imported into my map, and I haven't so much as laid a finger on it.

Any ideas?

*EDIT*
So I removed the line just before the loop and just before I find the unit group that was:
set loc = GetUnitLoc(u)

and I changed the polledWait(time) to PolledWait(time - .3).

Now, the jump always goes the to the center of the map, or at least, that's what it looks like...
I'm so confused...
 
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
Isn't it better to use EVENT_PLAYER_UNIT_SPELL_EFFECT?

Another question (I might as well not spam with another thread, heh).
Is there any reason I would want to use a PolledWait(time) over a TriggerSleepAction(time)? To me it seems that the latter does the same with a lot less code/calls...

Well, I suggest you don't use neither of them. You should start using timers + handlevars (check this post, I practically linked everything that is necessary). TriggerSleepAction and PolledWait are inaccurate and have a minimum (~0.27), timers are accurate and don't have a minimum (minimum is 0, as Vex said).

EDIT: Whoops, forgot to point out the leaks..... crap, you fixed them all, nice job :)
 
Status
Not open for further replies.
Top