• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Trigger do not run

Status
Not open for further replies.
Level 12
Joined
Mar 23, 2008
Messages
942
This trigger don't run when my unit cast the spell.
(Nothing happen, even the debug msg are not shown)

JASS:
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
 
Level 11
Joined
Apr 6, 2008
Messages
760
u dont create HIR

JASS:
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
 
Level 12
Joined
Mar 23, 2008
Messages
942
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:
Level 12
Joined
Mar 23, 2008
Messages
942
Maybe you've got another version of your code, cause i cant see anything similar to call SetUnitAnimation in that piece...

Sry, I keep changing the code xD

JASS:
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
 
Level 11
Joined
Apr 6, 2008
Messages
760
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

JASS:
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:
Level 12
Joined
Mar 23, 2008
Messages
942
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

did all this in opera :p

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
 
Level 11
Joined
Apr 6, 2008
Messages
760
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
 
Level 12
Joined
Mar 23, 2008
Messages
942
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:
Level 11
Joined
Apr 6, 2008
Messages
760
static variables are like globals but they can only be used with that struct

JASS:
local HIR h

that will allow us to use those static variables

JASS:
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
 
Level 9
Joined
Apr 5, 2008
Messages
529
to make unit play WALK animations you have to change movement speed of unit to 0

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.
 
Level 12
Joined
Mar 23, 2008
Messages
942
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

*I uploaded the movie right now, so might take a time to load*

JASS:
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:
Status
Not open for further replies.
Top