• 🏆 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!

[JASS] Animation prob

Status
Not open for further replies.
Level 11
Joined
Apr 6, 2008
Messages
760
i have some problems with this spell iv tried anything but nothing seems to work... when u cast the spell i summon 4 shades that follow ur hero around, and when the hero attack the shades attack to, but the event for detecting when the hero moves dont work if like a unit get close to the hero...

JASS:
scope Spell

globals
    private constant integer Abil_id = 'A000'
    private constant integer NumberOfIllus = 4
    private constant integer Dum_id = 'h000'
endglobals

private struct Data
unit c
unit array illu [NumberOfIllus]

trigger trig

integer order

timer t
endstruct

private function atkf takes nothing returns boolean
    local Data dat = GetTriggerStructA(GetTriggeringTrigger())
    local boolean ok = GetAttacker() == dat.c
    return ok
endfunction

private function UnitFilter takes nothing returns boolean
    local Data dat = GetTriggerStructA(GetTriggeringTrigger())
    local unit f = GetFilterUnit()
    local boolean ok = GetWidgetLife(f) > .405 and not IsUnitType(f,UNIT_TYPE_STRUCTURE) and IsUnitEnemy(f,GetOwningPlayer(dat.c))
    set f = null
    return ok
endfunction

private function Atk takes nothing returns nothing
    local Data dat = GetTriggerStructA(GetTriggeringTrigger())
    local integer a = 0
    local group g = CreateGroup()
    local unit d
    
        loop
            exitwhen a == NumberOfIllus
            set a = a + 1
            call SetUnitAnimation(dat.illu[a],"Attack")
            call GroupEnumUnitsInRange(g,GetUnitX(dat.illu[a]),GetUnitY(dat.illu[a]),100,Filter(function UnitFilter))
            loop
                set d = FirstOfGroup(g)
                exitwhen d == null
                call GroupRemoveUnit(g,d)
                call UnitDamageTarget(dat.c,d,150,false,false,null,null,null)
                call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl",GetUnitX(d),GetUnitY(d)))
            endloop
        endloop
    call DestroyGroup(g)
    set g = null
endfunction
        
private function Exe takes nothing returns nothing
    local Data dat = GetTriggerStructA(GetTriggeringTrigger())
    local integer a = 0
    
    set dat.order  = GetIssuedOrderId()
    
    call BJDebugMsg(I2S(dat.order))
    if dat.order == 851971 or dat.order == 851990 then
        loop
            exitwhen a == NumberOfIllus
            set a = a + 1
            call SetUnitAnimationByIndex(dat.illu[a],2)
        endloop
    endif
    if dat.order == 851972 or dat.order == 851993 then
        loop
            exitwhen a == NumberOfIllus
            set a = a + 1
            call SetUnitAnimation(dat.illu[a],"stand - 1")
        endloop
    endif
    
endfunction

private function Move takes nothing returns nothing
    local Data dat = GetTimerStructA(GetExpiredTimer())
    local real x = GetUnitX(dat.c)
    local real y = GetUnitY(dat.c)
    local integer a = 0
    local real Dist = 300.
    local real f = GetUnitFacing(dat.c)
    local real angle = 45.
    
    
    loop
        exitwhen a == NumberOfIllus
        set a = a + 1
        call SetUnitX(dat.illu[a],x+Dist*Cos(angle*3.14159/180))
        call SetUnitY(dat.illu[a],y+Dist*Sin(angle*3.14159/180))
        call SetUnitFacing(dat.illu[a],f)
        set angle = angle + 90
    endloop
    
endfunction
    

private function Actions takes nothing returns nothing
    local Data dat = Data.create()
    local trigger t = CreateTrigger()
    local integer a = 0
    local real x
    local real y
    local real Dist = 300.
    local real f = GetUnitFacing(dat.c)
    local real angle = 45.
        
    set dat.c = GetTriggerUnit()
    set x = GetUnitX(dat.c)
    set y = GetUnitY(dat.c)
    set dat.trig = CreateTrigger()
    
    loop
        exitwhen a == NumberOfIllus
        set a = a + 1
        set dat.illu[a] = CreateUnit(GetOwningPlayer(dat.c),Dum_id,x+Dist*Cos(angle*3.14159/180),y+Dist*Sin(angle*3.14159/180),f)
        call SetUnitVertexColor(dat.illu[a],0,0,0,95)
        call PauseUnit(dat.illu[a],true)
        set angle = angle + 90
    endloop
    
    call SetTriggerStructA(dat.trig,dat)
    call SetTriggerStructA(t,dat)
    call TriggerRegisterUnitEvent(dat.trig,dat.c, EVENT_UNIT_ISSUED_POINT_ORDER)
    call TriggerRegisterUnitEvent(dat.trig,dat.c, EVENT_UNIT_ISSUED_TARGET_ORDER)
    call TriggerRegisterUnitEvent(dat.trig,dat.c, EVENT_UNIT_ISSUED_ORDER)
    call TriggerAddAction(dat.trig,function Exe)
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddAction(t,function Atk)
    call TriggerAddCondition(t,Filter(function atkf))
    set dat.t = NewTimer()
    call SetTimerStructA(dat.t,dat)
    call TimerStart(dat.t,.035,true,function Move)
endfunction

private function conds takes nothing returns boolean
    return GetSpellAbilityId()==Abil_id
endfunction

public function InitTrig takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddAction(t,function Actions)
    call TriggerAddCondition(t,Filter(function conds))
endfunction

endscope
 

Attachments

  • Template.w3x
    37.6 KB · Views: 46
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
Arg, call SetUnitAnimation(dat.illu[a],"Walk") is wrong, you have to uncapitalize "Walk" (so replace it with "walk").

For the second one, it really depends on what 851971 and 851993 are. I don't know myself, you should have some idea what are those orders.

if order == OrderId(<input orderstring>) or order == OrderId(<input orderstring>) then
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
You have to download Magos Wc3 Model Editor, load a model, save it as a .mdl (instead of .mdx) file, then open it in notepad and you'll see animation strings under Sequences. They almost always go in the 0, 1, 2, 3 etc. order.

For example, this is what a part of Peasant.mdl looks like:

}
Sequences 22 {
Anim "Stand" {
Interval { 133, 1633 },
MinimumExtent { -28.5623, -29.8084, -0.0504422 },
MaximumExtent { 20.6361, 26.5544, 92.6605 },
BoundsRadius 52.6531,
}
Anim "Stand -2" {
Interval { 1800, 4467 },
Rarity 3,
MinimumExtent { -25.878, -29.8389, 0.152655 },
MaximumExtent { 28.2653, 28.5517, 92.7458 },
BoundsRadius 51.4812,
}
Anim "Stand - 3" {
Interval { 4633, 9800 },
Rarity 4,
MinimumExtent { -29.9116, -31.7053, -5.43188 },
MaximumExtent { 36.1178, 38.608, 92.7594 },
BoundsRadius 51.9626,
}
Anim "Stand - 4" {
Interval { 14133, 18133 },
Rarity 4,
MinimumExtent { -26.0243, -36.6485, -0.456286 },
MaximumExtent { 26.0185, 31.4237, 97.5041 },
BoundsRadius 54.1783,
}
Anim "Stand Gold" {
Interval { 18300, 19867 },
MinimumExtent { -30.7913, -29.2415, 0.201665 },
MaximumExtent { 19.058, 21.2577, 98.3751 },
BoundsRadius 55.6318,
}

So if you want to make unit play the "Stand" animation, you use 0:

call SetUnitAnimationByIndex(u, 0)


But the unit-type has to be Peasant, of course.
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
He said: Make a test map. Put the model you want to test on the map.
Make a trigger that fires when you type some command ("-animate 1").
The triggers actions will make the unit play the animation with name - the substring you entered.
;)
 
Level 12
Joined
Apr 27, 2008
Messages
1,228
No you are not.
Most probably you just didn't read the post carefully nor think about it.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
I generally try say as much as necessary, no less, nor more.

So yes, sometimes you have to think about it, but that helps you actually learn from the point and do some thinking yourself, rather than mechanically copy and pasting other peoples' solutions and thus likely not learning anything in the process.

@Ciebron: Bumping is allowed, of course. However, what did you edit about the first post (I don't remember the old one)?
 
Level 11
Joined
Apr 6, 2008
Messages
760
It was that I had problems with playing walk animation, but I overcame that problem.

But now I have problems with playing a spell animation, sometimes when I attack with my hero after it has walked. The "shades" dont player spell animation

anyone got a solotion for that?

JASS:
scope Spell

globals
    private constant integer Abil_id = 'A000'
    private constant integer NumberOfIllus = 4
    private constant integer Dum_id = 'h000'
endglobals

private struct Data
unit c
unit array illu [NumberOfIllus]

trigger trig

real x
real y

integer s

timer t
timer ti
    static method End takes nothing returns nothing //not so happy with this shit...
        local Data dat = GetTimerStructB(GetExpiredTimer())
        call dat.destroy()
    endmethod    
        
    method onDestroy takes nothing returns nothing
        local integer a = 0
        call ClearTriggerStructA(.trig)
        call ReleaseTimer(.t)
        call ReleaseTimer(.ti)
        call ClearTimerStructA(.t)
        call ClearTimerStructB(.ti)
        call DestroyTrigger(.trig)
        loop
            exitwhen a == NumberOfIllus
            set a = a + 1
            call RemoveUnit(.illu[a])
        endloop
    endmethod
endstruct

private function atkf takes nothing returns boolean
    local Data dat = GetTriggerStructA(GetTriggeringTrigger())
    local boolean ok = GetAttacker() == dat.c
    return ok
endfunction

private function UnitFilter takes nothing returns boolean
    local Data dat = GetTriggerStructA(GetTriggeringTrigger())
    local unit f = GetFilterUnit()
    local boolean ok = GetWidgetLife(f) > .405 and not IsUnitType(f,UNIT_TYPE_STRUCTURE) and IsUnitEnemy(f,GetOwningPlayer(dat.c))
    set f = null
    return ok
endfunction

private function Atk takes nothing returns nothing
    local Data dat = GetTriggerStructA(GetTriggeringTrigger())
    local integer a = 0
    local group g = CreateGroup()
    local unit d
    
    set dat.s = 0 //doing this did do the bugg didnt allway be there
        loop
            exitwhen a == NumberOfIllus
            set a = a + 1
            call SetUnitAnimationByIndex(dat.illu[a],6) //this is the problem
            call GroupEnumUnitsInRange(g,GetUnitX(dat.illu[a]),GetUnitY(dat.illu[a]),200,Filter(function UnitFilter))
            loop
                set d = FirstOfGroup(g)
                exitwhen d == null
                call GroupRemoveUnit(g,d)
                call UnitDamageTarget(dat.c,d,100,false,false,null,null,null)
                call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl",GetUnitX(d),GetUnitY(d)))
            endloop
        endloop
    call DestroyGroup(g)
    set g = null
endfunction

private function Move takes nothing returns nothing
    local Data dat = GetTimerStructA(GetExpiredTimer())
    local real x = GetUnitX(dat.c)
    local real y = GetUnitY(dat.c)
    local integer a = 0
    local real Dist = 300.
    local real f = GetUnitFacing(dat.c)
    local real angle = 45.
    
    
    if x != dat.x or y != dat.y then
        set dat.x = x
        set dat.y = y
        loop
            exitwhen a == NumberOfIllus
            set a = a + 1
            call SetUnitFacing(dat.illu[a],f)
            if dat.s == 0 then //if this isnt here it looks like the unit has hiccup
                call SetUnitAnimationByIndex(dat.illu[a],2)
            endif
            call SetUnitX(dat.illu[a],x+Dist*Cos(angle*3.14159/180))
            call SetUnitY(dat.illu[a],y+Dist*Sin(angle*3.14159/180))
            set angle = angle + 90
        endloop
        set dat.s = 1
    else
        loop
            exitwhen a == NumberOfIllus
            set a = a + 1
            call SetUnitFacing(dat.illu[a],f)
            if dat.s == 1 then //if this isnt here it looks like the unit has hiccup
                call SetUnitAnimation(dat.illu[a],"stand - 1")
            endif
        endloop
        set dat.s = 0
    endif
    
endfunction
    

private function Actions takes nothing returns nothing
    local Data dat = Data.create()
    local integer a = 0
    local real x
    local real y
    local real Dist = 300.
    local real f = GetUnitFacing(dat.c)
    local real angle = 45.
    local integer lvl = GetUnitAbilityLevel(GetTriggerUnit(),Abil_id)
    local real dura = 10+(lvl*5)
    
    set dat.c = GetTriggerUnit()
    set x = GetUnitX(dat.c)
    set y = GetUnitY(dat.c)
    set dat.x = x
    set dat.y = y
    set dat.trig = CreateTrigger()
    
    loop
        exitwhen a == NumberOfIllus
        set a = a + 1
        set dat.illu[a] = CreateUnit(GetOwningPlayer(dat.c),Dum_id,x+Dist*Cos(angle*3.14159/180),y+Dist*Sin(angle*3.14159/180),f)
        call SetUnitVertexColor(dat.illu[a],0,0,0,75)
        call PauseUnit(dat.illu[a],true)
        set angle = angle + 90
    endloop
    
    call SetTriggerStructA(dat.trig,dat)
    call TriggerRegisterAnyUnitEventBJ(dat.trig, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddAction(dat.trig,function Atk)
    call TriggerAddCondition(dat.trig,Filter(function atkf))
    set dat.t = NewTimer()
    call SetTimerStructA(dat.t,dat)
    call TimerStart(dat.t,.035,true,function Move)
    set dat.ti = NewTimer()
    call SetTimerStructB(dat.ti,dat)
    call TimerStart(dat.ti,dura,false,function Data.End)
endfunction

private function conds takes nothing returns boolean
    return GetSpellAbilityId()==Abil_id
endfunction

public function InitTrig takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t,function Actions)
    call TriggerAddCondition(t,Filter(function conds))
endfunction

endscope
 
Last edited:
Status
Not open for further replies.
Top