1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  4. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  5. Units have been turned into heroes in our latest Icon Contest! Vote for the best icon set at the Icon Contest #18 Poll!
    Dismiss Notice
  6. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  7. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] Trigger do not run

Discussion in 'Triggers & Scripts' started by Saishy, Jan 30, 2009.

  1. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    This trigger don't run when my unit cast the spell.
    (Nothing happen, even the debug msg are not shown)

    Code (vJASS):
    scope Hirenkyaku initializer In_Hirenkyaku

    globals
        private constant real move = 100.00
    endglobals

    private struct HIR
        unit caster
        location target
        real tx
        real ty
        real x
        real y
        real angle
        integer times
    endstruct

    //===========================================================================

    private function Hirenkyaku_Move takes nothing returns nothing
        local HIR h = GetTimerData(GetExpiredTimer())

        if h.times > 0 then
            call BJDebugMsg("3-4")
            set h.x = h.x + move * Cos(h.angle * bj_DEGTORAD)
            set h.y = h.y + move * Sin(h.angle * bj_DEGTORAD)
            call SetUnitX(h.caster, h.x)
            call SetUnitY(h.caster, h.y)
            set h.times = h.times - 1
        else
            call BJDebugMsg("3-5")
            call SetUnitPosition(h.caster, h.tx, h.ty)
            call UnitRemoveAbility(h.caster, 'A03Y')
            call UnitRemoveAbility(h.caster, 'A03Z')
           
            call ReleaseTimer(GetExpiredTimer())
            call h.destroy()
        endif
       
    endfunction

    //===========================================================================

    private function Hirenkyaku_Actions takes nothing returns boolean

        local HIR h
        local timer t
        local real dx
        local real dy
       
        if (GetSpellAbilityId() == 'A03W') then
            set h.target = GetSpellTargetLoc()
            set h.caster = GetTriggerUnit()
            set h.tx = GetLocationX(h.target)
            set h.ty = GetLocationY(h.target)
                call BJDebugMsg("1")
            if IsTerrainPathable(h.tx, h.ty, PATHING_TYPE_WALKABILITY) then
                set h.x = GetUnitX(h.caster)
                set h.y = GetUnitY(h.caster)
                set h.angle = bj_RADTODEG * Atan2(h.ty - h.y, h.tx - h.x)
                set t = NewTimer()
                call SetTimerData(t,h)
                set dx = h.tx - h.x
                set dy = h.ty - h.y
                call UnitAddAbility(h.caster, 'A03Y')
                call UnitAddAbility(h.caster, 'A03Z')
                set h.times = R2I(SquareRoot(dx * dx + dy * dy) / 100)
                call TimerStart(t, 0.05, true, function Hirenkyaku_Move)
                    call BJDebugMsg("2")
            else
                call IssueImmediateOrder(h.caster, "stop")
                call h.destroy()
                    call BJDebugMsg("3")
            endif
        endif
       
        return false
    endfunction

    //===========================================================================
    private function In_Hirenkyaku takes nothing returns nothing
        local trigger t_Hirenkyaku = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ( t_Hirenkyaku, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( t_Hirenkyaku, Condition(function Hirenkyaku_Actions) )
        set t_Hirenkyaku = null
    endfunction

    endscope
     
  2. Ciebron

    Ciebron

    Joined:
    Apr 6, 2008
    Messages:
    760
    Resources:
    2
    Spells:
    2
    Resources:
    2
    u dont create HIR

    Code (vJASS):
    private function Hirenkyaku_Actions takes nothing returns boolean

        local HIR h
        local timer t
        local real dx
        local real dy

        if (GetSpellAbilityId() == 'A03W') then
            set h = HIR.create()
            set h.target = GetSpellTargetLoc()
            set h.caster = GetTriggerUnit()
            set h.tx = GetLocationX(h.target)
            set h.ty = GetLocationY(h.target)
                call BJDebugMsg("1")
            if IsTerrainPathable(h.tx, h.ty, PATHING_TYPE_WALKABILITY) then
                set h.x = GetUnitX(h.caster)
                set h.y = GetUnitY(h.caster)
                set h.angle = bj_RADTODEG * Atan2(h.ty - h.y, h.tx - h.x)
                set t = NewTimer()
                call SetTimerData(t,h)
                set dx = h.tx - h.x
                set dy = h.ty - h.y
                call UnitAddAbility(h.caster, 'A03Y')
                call UnitAddAbility(h.caster, 'A03Z')
                set h.times = R2I(SquareRoot(dx * dx + dy * dy) / 100)
                call TimerStart(t, 0.05, true, function Hirenkyaku_Move)
                    call BJDebugMsg("2")
            else
                call IssueImmediateOrder(h.caster, "stop")
                call h.destroy()
                    call BJDebugMsg("3")
            endif
        endif

        return false
    endfunction


    should be like that
     
  3. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    Thanks! It worked!

    But IsTerrainPathable is always returning false... why?
    Edit: Got it, return false when is pathable... lol
    Edit2: Can't rep you for some reason...

    -----------------------------------------------------------

    It is possible to order a paused unit to play an animation?
    I'm trying to order him to walk but he don't!
     
    Last edited: Jan 30, 2009
  4. raft_pl

    raft_pl

    Joined:
    May 27, 2006
    Messages:
    496
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Paused units cant do any orders, since they are paused. Thats the idea of this function, to prevent unit from doing anything...
    But you can play a paused units specific animation by triggers, if thats your point.
     
  5. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    I'm trying to play walk animation by triggers, but he does nothing. See trigger above!
     
  6. raft_pl

    raft_pl

    Joined:
    May 27, 2006
    Messages:
    496
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Maybe you've got another version of your code, cause i cant see anything similar to call SetUnitAnimation in that piece...
     
  7. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    Sry, I keep changing the code xD

    Code (vJASS):
    scope Hirenkyaku initializer In_Hirenkyaku

    globals
        private constant real move = 50.00
    endglobals

    private struct HIR
        unit caster
        location target
        real tx
        real ty
        real x
        real y
        real angle
        integer times
    endstruct

    //===========================================================================

    private function Hirenkyaku_Move takes nothing returns nothing
        local HIR h = GetTimerData(GetExpiredTimer())

        if h.times > 0 then
            set h.x = h.x + move * Cos(h.angle * bj_DEGTORAD)
            set h.y = h.y + move * Sin(h.angle * bj_DEGTORAD)
            call SetUnitX(h.caster, h.x)
            call SetUnitY(h.caster, h.y)
            set h.times = h.times - 1
        else
            call SetUnitPosition(h.caster, h.tx, h.ty)
            call UnitRemoveAbility(h.caster, 'A03Y')
            call UnitRemoveAbility(h.caster, 'Avul')
            call SetUnitVertexColorBJ(h.caster, 100, 100, 100, 0)
            call SetUnitAnimation(h.caster, "stand")
            call PauseUnit(h.caster, false)
           
            call ReleaseTimer(GetExpiredTimer())
            call h.destroy()
        endif
       
    endfunction

    //===========================================================================

    private function Hirenkyaku_Actions takes nothing returns boolean

        local HIR h
        local timer t
        local real dx
        local real dy
       
        if (GetSpellAbilityId() == 'A03W') then
            set h = HIR.create()
            set h.target = GetSpellTargetLoc()
            set h.caster = GetTriggerUnit()
            set h.tx = GetLocationX(h.target)
            set h.ty = GetLocationY(h.target)
           
            if not(IsTerrainPathable(h.tx, h.ty, PATHING_TYPE_WALKABILITY)) then
                set h.x = GetUnitX(h.caster)
                set h.y = GetUnitY(h.caster)
                set h.angle = bj_RADTODEG * Atan2(h.ty - h.y, h.tx - h.x)
                set t = NewTimer()
                call SetTimerData(t,h)
                set dx = h.tx - h.x
                set dy = h.ty - h.y
                call UnitAddAbility(h.caster, 'A03Y')
                call UnitAddAbility(h.caster, 'Avul')
                call SetUnitVertexColorBJ(h.caster, 100, 100, 100, 30)
                call PauseUnit(h.caster, true)
                call SetUnitAnimation(h.caster, "walk")
                set h.times = R2I(SquareRoot(dx * dx + dy * dy) / move)
                call TimerStart(t, 0.05, true, function Hirenkyaku_Move)
            else
                call IssueImmediateOrder(h.caster, "stop")
                call SetUnitState(h.caster, UNIT_STATE_MANA, GetUnitState(h.caster, UNIT_STATE_MANA) + 15 + (15 * GetUnitAbilityLevel(h.caster, 'A03W')))
                call h.destroy()
            endif
        endif
       
        return false
    endfunction

    //===========================================================================
    private function In_Hirenkyaku takes nothing returns nothing
        local trigger t_Hirenkyaku = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ( t_Hirenkyaku, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( t_Hirenkyaku, Condition(function Hirenkyaku_Actions) )
        set t_Hirenkyaku = null
    endfunction

    endscope
     
  8. raft_pl

    raft_pl

    Joined:
    May 27, 2006
    Messages:
    496
    Resources:
    1
    Maps:
    1
    Resources:
    1
    The only reason i can find is that the animation is being played before moving the unit... Guess its interrupting the animation somehow, even though SetUnitX/Y shouldn't interrupt anything.
     
  9. Ciebron

    Ciebron

    Joined:
    Apr 6, 2008
    Messages:
    760
    Resources:
    2
    Spells:
    2
    Resources:
    2
    try,
    SetUnitAnimationByIndex()
    . u have to try too find the correct animation with this.


    also u could save cos and sin in to the struct and u dont need to calc that all the time

    Code (vJASS):
    private struct HIR
    unit caster
    unit target

    real cos
    real sin

    integer times

    static real tempx
    static real tempy
    static real tempa

    static integer array Ar                   //*************
    static integer Total = 0                 // This is a indexer, dont need to use this but its more effecient then any Attachment system
    static timer Time = CreateTimer()   //****************

        static method create takes unit u,unit t returns HIR
            local HIR h = HIR.allocate()
     
            set h.caster = u
            set h.target = t
            set tempx = GetUnitX(h.target)-GetUnitX(h.caster)
            set tempy = GetUnitY(h.target)-GetUnitY(h.caster)
            set tempa = Atan2(tempy,tempx)
            set h.cos = Cos(tempa)
            set h.sin = Sin(tempa)

            if h.Total == 0 then
                 call TimerStart(h.Time,0.035,true,function HIR.Loop)
            endif

            set h.Ar[h.Total] = h
            set h.Total = h.Total + 1

           set u = null
           set t = null

            return h
        endmethod

        static method Loop takes nothing returns nothing
            local HIR h
            local integer i = 0


            loop
                exitwhen i >= h.Total
                set h = h.Ar[i]
         
                if h.times > 0 then
                    call SetUnitX(h.caster,GetUnitX(h.caster)+Move*h.cos)
                    call SetUnitY(h.caster,GetUnitY(h.caster)+Move*h.sin)
                else
                    set h.Total = h.Total - 1
                    set h.Ar[i] = h.Ar[h.Total]
                    set i = i - 1
                    call h.destroy()
                endif

                set i = i + 1
            endloop

            if h.Total == 0 then
                call PauseTimer(h.Time)
            endif
        endmethod

        method onDestroy takes nothing returns nothing
            set .caster = null
            set .target = null
        endmethod
    endstruct


    did all this in opera :p
     
    Last edited: Jan 31, 2009
  10. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    Lol thanks, but what the hell is that? I didn't even know jass could look like that >.<

    Serious, what that do? What I do with that? xD
     
  11. Ciebron

    Ciebron

    Joined:
    Apr 6, 2008
    Messages:
    760
    Resources:
    2
    Spells:
    2
    Resources:
    2
    Static methods or class methods do not use an instance, they are actually like functions but since they are declared inside the struct they can use private members

    Methods are just like functions, the difference is that they are associated with the class, also [normal] methods are associated with an instance (in this case 'this')

    Source : JassHelper 0.9.D.0
     
  12. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    didn't understand yet, why some variables are static?
    also, what is the difference between my code and yours, and how do I use yours?

    Edit: Why can you do that: set h = h.Ar ?
     
    Last edited: Jan 31, 2009
  13. NiddHogg-kun

    NiddHogg-kun

    Joined:
    Sep 24, 2007
    Messages:
    268
    Resources:
    2
    Icons:
    2
    Resources:
    2
    to make unit play WALK animations you have to change movement speed of unit to 0
     
  14. Ciebron

    Ciebron

    Joined:
    Apr 6, 2008
    Messages:
    760
    Resources:
    2
    Spells:
    2
    Resources:
    2
    static variables are like globals but they can only be used with that struct

    Code (vJASS):
    local HIR h


    that will allow us to use those static variables

    Code (vJASS):
    h.Total = h.Total + 1


    but the biggest diffrence between our codes are that i save Cos and Sin (wich makes it more efficent), i use a indexer and i dont use locals
     
  15. RolePlaynGamer

    RolePlaynGamer

    Joined:
    Apr 5, 2008
    Messages:
    473
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Lies.
    Set UnitAnimationByIndex is the only way to play an units walk animation, beware, that it'll leap through the animation until you play another one or make the unit do something.
    It takes an integer, which is the index of the animation. Just try with 0, and if it's not the correct one, then try 1, then 2 etc.
     
  16. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    Thanks everyone! The spell is working perfectly now!

    One little video to show a strange thing happening while using death animation, it looks like a slip xD

    http://www.youtube.com/watch?v=tRZZqlmeCeI
    *I uploaded the movie right now, so might take a time to load*

    Code (vJASS):
    scope Hirenkyaku initializer In_Hirenkyaku

    globals
        private constant real move = 60.00
    endglobals

    private struct HIR
        unit caster
        location target
        real tx
        real ty
        real x
        real y
        real angle
        real cos
        real sin
        integer times
    endstruct

    //===========================================================================

    private function Hirenkyaku_Move takes nothing returns nothing
        local HIR h = GetTimerData(GetExpiredTimer())

        if h.times > 0 then
            set h.x = h.x + h.cos
            set h.y = h.y + h.sin
            call SetUnitX(h.caster, h.x)
            call SetUnitY(h.caster, h.y)
            set h.times = h.times - 1
        else
            call SetUnitPosition(h.caster, h.tx, h.ty)
            call UnitRemoveAbility(h.caster, 'A03Y')
            call UnitRemoveAbility(h.caster, 'Avul')
            call SetUnitVertexColorBJ(h.caster, 100, 100, 100, 0)
            call SetUnitAnimation(h.caster, "stand")
            call SetUnitTimeScale(h.caster, 1)
            call PauseUnit(h.caster, false)
           
            call ReleaseTimer(GetExpiredTimer())
            call h.destroy()
        endif
       
    endfunction

    //===========================================================================

    private function Hirenkyaku_Actions takes nothing returns boolean

        local HIR h
        local timer t
        local real dx
        local real dy
       
        if (GetSpellAbilityId() == 'A03W') then
            set h = HIR.create()
            set h.target = GetSpellTargetLoc()
            set h.caster = GetTriggerUnit()
            set h.tx = GetLocationX(h.target)
            set h.ty = GetLocationY(h.target)
           
            if not(IsTerrainPathable(h.tx, h.ty, PATHING_TYPE_WALKABILITY)) then
                set h.x = GetUnitX(h.caster)
                set h.y = GetUnitY(h.caster)
                set h.angle = bj_RADTODEG * Atan2(h.ty - h.y, h.tx - h.x)
                set t = NewTimer()
                call SetTimerData(t,h)
                set dx = h.tx - h.x
                set dy = h.ty - h.y
                set h.cos = move * Cos(h.angle * bj_DEGTORAD)
                set h.sin = move * Sin(h.angle * bj_DEGTORAD)
                call UnitAddAbility(h.caster, 'A03Y')
                call UnitAddAbility(h.caster, 'Avul')
                call SetUnitVertexColorBJ(h.caster, 100, 100, 100, 30)
                call PauseUnit(h.caster, true)
                call SetUnitAnimationByIndex(h.caster, 5)
                call SetUnitTimeScale(h.caster, 2)
                set h.times = R2I(SquareRoot(dx * dx + dy * dy) / move)
                call TimerStart(t, 0.05, true, function Hirenkyaku_Move)
            else
                call IssueImmediateOrder(h.caster, "stop")
                call SetUnitState(h.caster, UNIT_STATE_MANA, GetUnitState(h.caster, UNIT_STATE_MANA) + 15 + (15 * GetUnitAbilityLevel(h.caster, 'A03W')))
                call h.destroy()
            endif
        endif
       
        return false
    endfunction

    //===========================================================================
    private function In_Hirenkyaku takes nothing returns nothing
        local trigger t_Hirenkyaku = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ( t_Hirenkyaku, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( t_Hirenkyaku, Condition(function Hirenkyaku_Actions) )
        set t_Hirenkyaku = null
    endfunction

    endscope


    Obs: If you didn't take any rep by me, its because I'm getting annoyed by some "You must spread some Reputation around before giving it to SOMEONE again."
     
    Last edited: Jan 31, 2009