• 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.

Unit Animation is bad after spell

Status
Not open for further replies.
Level 14
Joined
Jul 26, 2008
Messages
1,009
I have a spell called petrify. When the unit is hit by it the unit's aspd, movespeed and animation will be slowed, and finally stopped.

The problem is the spell causes the animation of the unit to skip around and get all wonky until the problem is fixed.

I have a command in the game that sets the unit's animation speed to whatever you want, and typing that corrects the problem. It's the same method I use to change any animation.

Q: What is causing the animation of units to go crazy after this spell?

JASS:
scope Petrify initializer InitTrig_Petrify

globals
    private constant integer SPELLID        = 'Petr'
    private constant real tick              = 0.2
endglobals

private struct Data

    unit c
    unit t
    real dur
    real ms
    real as

    static method Timer takes nothing returns nothing
     local timer tim = GetExpiredTimer()
     local Data D = Data(GetTimerData(tim))
     local integer lvl = GetUnitAbilityLevel(D.c, SPELLID)
     local integer aspd = R2I(tick*(10+10*lvl))
     local integer mspd = R2I(tick*(60+20*lvl))
        if D.dur >= 4 then
            call SetUnitTimeScale(D.t, 100.0)
            call PauseUnit(D.t, false)
            call AddUnitBonus(D.t, BONUS_ATTACK_SPEED, R2I(D.as))
            call AddUnitBonus(D.t, BONUS_MOVEMENT_SPEED, R2I(D.ms))
            call SetUnitVertexColor(D.t, 255,255,255,255)
            call UnitRemoveType(D.t, UNIT_TYPE_MECHANICAL)
            call ReleaseTimer(tim)
            call D.destroy()
        elseif GetUnitMoveSpeed(D.t) > 25 then
            set D.ms = D.ms + mspd
            set D.as = D.as + aspd
            call AddUnitBonus(D.t, BONUS_ATTACK_SPEED, -aspd)
            call AddUnitBonus(D.t, BONUS_MOVEMENT_SPEED, -mspd)
            call SetUnitVertexColor(D.t, 197,197,197,255)
        else
            call SetUnitVertexColor(D.t, 123,123,123,255)
            call SetUnitTimeScale(D.t, 1.0)
            call PauseUnit(D.t, true)
            call UnitAddType(D.t, UNIT_TYPE_MECHANICAL)
        endif
        set D.dur = D.dur + tick
    endmethod
    
    static method create takes unit c, unit t returns Data
     local Data D = Data.allocate()
     local timer tim = NewTimer()
        set D.dur = 0
        set D.c = c
        set D.t = t
        set D.ms = 0
        set D.as = 0
        call SetTimerData(tim,D)
        call TimerStart(tim, tick, true, function Data.Timer)
     return D
    endmethod
    
endstruct

private function Conditions takes nothing returns boolean
    if GetSpellAbilityId() == SPELLID then
        call Data.create(GetTriggerUnit(),GetSpellTargetUnit())
    endif
 return true
endfunction

//===========================================================================
public function InitTrig_Petrify takes nothing returns nothing
 local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, function Conditions )
 set t = null
endfunction

endscope

TimerUtils and BonusMod are used in this.

JASS:
function AnimEnumUnitSelected takes nothing returns boolean
    call SetUnitTimeScale(GetFilterUnit(), udg_TEMP_Real * 0.01)
 return false
endfunction


    //Set Animation Speed
    if SubString(ChatString,0,4) == "anim" then

        if (SubString(ChatString,4,5) == " ") then
            set text = SubString(ChatString,5,StringLength(ChatString))
        else
            set text = SubString(ChatString,4,StringLength(ChatString))
        endif

        set udg_TEMP_Real = S2R(text)

        call GroupEnumUnitsSelected( grp, pl, function AnimEnumUnitSelected )
 
Status
Not open for further replies.
Top