HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[vJASS] Problem: Animation breakdown

09-25-2008, 05:02 PM#1
Zandose
I'm trying to breakdown a animation to see how it looks in slow motion, but this doesn't seem to work. Sometimes it works but most of the time it doesn't.

Collapse JASS:
scope Animation

globals
    //START_DELAY and STOP should be equal to the total time of the animation ("attack")
    private constant real ANIMATION_LENGTH          = 1.0 //How long to wait before starting to freeze untis
    private constant integer NUMBER_OF_UNITS        = 40 //The timer is STOP divided by NUM_OF_UNITS
    private constant real DISTANCE_BETWEEN_UNITS    = 80.0 //Make sure the unit is still within "attack" range
    private constant real MAP_BOUNDS_SAFTY_MARGIN   = 100 //Avoid making units out of bounds (crash)
    private constant string COMMAND                 = "attack"
    private constant integer UID_UNIT               = 'H001'
    //======================================================================================
    private integer Counter = 0
    private unit array Units
    private timer Tim = CreateTimer()
endglobals

private function Pause takes nothing returns nothing
    set Counter = Counter + 1
    //For some reason you need to use both to get the unit to pause while doing a animation
    call PauseUnit(Units[Counter], true) //Pauses unit
    call SetUnitTimeScale(Units[Counter], 0) //Sets the units animation speed to zero
    if Counter == NUMBER_OF_UNITS then
        return
    endif
    call TimerStart(Tim, ANIMATION_LENGTH/NUMBER_OF_UNITS, false, function Pause)
endfunction

private function Actions takes nothing returns nothing
    local rect r = GetWorldBounds()
    local real minX = GetRectMinX(r)
    local real maxX = GetRectMaxX(r)
    local real minY = GetRectMinY(r)
    local real maxY = GetRectMaxY(r)
    local real x = minX + MAP_BOUNDS_SAFTY_MARGIN
    local real y = minY + MAP_BOUNDS_SAFTY_MARGIN
    local integer i = 0 //Counter
    //Creates all the units
    loop
        set i = i + 1
        set x = x + DISTANCE_BETWEEN_UNITS
        if x >= maxX - MAP_BOUNDS_SAFTY_MARGIN then
            set x = minX + MAP_BOUNDS_SAFTY_MARGIN
            set y = y + DISTANCE_BETWEEN_UNITS
        endif
        set Units[i] = CreateUnit(Player(0), UID_UNIT, x, y, 0)
        exitwhen i == NUMBER_OF_UNITS
    endloop
    
    call TriggerSleepAction(1) //I don't know
    //Makes all the units attack the next unit in the line
    set i = 0
    loop
        set i = i + 1
        exitwhen i == NUMBER_OF_UNITS
        call SetUnitAnimation(Units[i], COMMAND)
    endloop
    
    call TimerStart(Tim, ANIMATION_LENGTH/NUMBER_OF_UNITS, false, function Pause)
    
    //Cleanup
    call RemoveRect(r)
    set r = null
endfunction

public function InitTrig takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerEvent(t, GetLocalPlayer(), EVENT_PLAYER_END_CINEMATIC)
    call TriggerAddAction(t, function Actions)
    call BJDebugMsg("Press the 'ESC' key to start.")
endfunction

endscope
09-25-2008, 05:09 PM#2
Anitarf
Why don't you just play their attack animation instead of ordering them to attack?
09-25-2008, 05:39 PM#3
Zandose
Didn't think of it. At the time I was thinking "in order to to get the attack animation I need to attack something."