• 🏆 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] Spell doesn't reset MoveSpeed properly.

Status
Not open for further replies.
Level 13
Joined
Jul 26, 2008
Messages
1,009
It's odd, because the other spell resets it just fine that I have and runs similarly.

The spell is an activatable based on immolation.

The spell sets your Movespeed to 1 at the end of it's timer for some reason, but the amount to subtract is only 250.

JASS:
scope Hunt initializer init

globals
    private constant integer SPELLID    = 'hunt'
    private constant string TurnOn      = "immolation"
    private constant string TurnOff     = "unimmolation"
    private constant real tick          = 0.1
    private HandleTable info
endglobals

private struct Data

    unit c
    boolean deactivate = false
    integer co
    real bonus
    timer tim
    real mspd
    real d
    real i
    
    static method onLoop takes nothing returns nothing
        local Data D = Data(GetTimerData(GetExpiredTimer()))
        local integer lvl = GetUnitAbilityLevel(D.c, SPELLID)
        local real aspd = 2+1*lvl
        local real mspd = 5*lvl
        local real cap = 15+10*lvl
        if not(IsUnitType(D.c,UNIT_TYPE_DEAD)) and not(D.deactivate) and GetUnitState(D.c, UNIT_STATE_MANA) >= 25 then
            //Start timer
            if D.d == 1 + D.i and D.i <= 3+3*lvl then
                set D.i = D.i + 1
                set D.co = D.co - 21
                if D.bonus < cap then
                    call UnitModifyAttackSpeed(D.c, aspd)
                    if  GetUnitMoveSpeed(D.c) < 500 then
                        call SetUnitMoveSpeed(D.c, GetUnitMoveSpeed(D.c) + mspd)
                        debug call BJDebugMsg(R2S(D.mspd))
                        set D.mspd = D.mspd + mspd
                    endif
                    set D.bonus = D.bonus + aspd
                endif
                call SetUnitVertexColor(D.c, 255, D.co, D.co, 255)
                call SetUnitState(D.c, UNIT_STATE_MANA, GetUnitState(D.c, UNIT_STATE_MANA) - D.i*(0.6*lvl))
            elseif D.i > 3+3*lvl then
                if D.bonus < cap then
                    call UnitModifyAttackSpeed(D.c, aspd)
                    set D.bonus = D.bonus + aspd
                endif
                call SetUnitState(D.c, UNIT_STATE_MANA, GetUnitState(D.c, UNIT_STATE_MANA) - D.i*(lvl*0.05))
            endif
            set D.d = D.d + tick
        else
            //Cleanup
            call BJDebugMsg(R2S(D.mspd)+" is the end result")
            call SetUnitMoveSpeed(D.c, GetUnitMoveSpeed(D.c)-D.mspd)
            call UnitModifyAttackSpeed(D.c, -D.bonus)
            call SetUnitVertexColor(D.c, 255,255,255,255)
            call IssueImmediateOrder(D.c, TurnOff)
            call IssueSecondLastOrder(D.c)
            call info.flush(D.c)
            set D.c = null
            call ReleaseTimer(D.tim)
            call D.destroy()
        endif
    endmethod
    
    static method create takes unit caster, real movespeed returns Data
    local Data D =  Data.allocate()
        set D.c = caster
        set D.co = 255
        set D.d = 0
        set D.i = 0
        set D.bonus = 0
        set D.mspd = 0
        //Timer
        set D.tim = NewTimer()
        call SetTimerData(D.tim,D)
        call TimerStart(D.tim, tick, true, function Data.onLoop)
        set info[D.c] = D
        return D
    endmethod
endstruct
 
private function Deactivate takes nothing returns boolean
    local Data D
    if GetIssuedOrderId() == OrderId(TurnOff) and info.exists(GetTriggerUnit()) then
        set D = info[GetTriggerUnit()]
        set D.deactivate = true
    endif
    return false
endfunction

private function Activation takes nothing returns boolean
    if GetIssuedOrderId() == OrderId(TurnOn) and GetUnitAbilityLevel(GetTriggerUnit(), SPELLID) > 0 then
        call Data.create(GetTriggerUnit(), GetUnitMoveSpeed(GetTriggerUnit()))
    endif
    return false
endfunction

 //===========================================================================
private function init takes nothing returns nothing 
 local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ISSUED_ORDER )  
    call TriggerAddCondition(t, function Activation )
    set t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ISSUED_ORDER ) 
    call TriggerAddCondition( t, function Deactivate )
    set info = HandleTable.create()
    call XE_PreloadAbility(SPELLID)
endfunction

endscope
 
Level 13
Joined
May 11, 2008
Messages
1,198
Use a library instead of a scope if it has library requirements, so that when you post it on the forums we don't have to guess at what you are using.

I spy TimerUtils, Table, xepreload, something that looks like LastOrder and something else I don't recognise (for UnitModifyAttackSpeed).

uhm...no...it's simpler just to say what he's using.

why would it be timerutils with somthing called tick? maybe it's TT
 
Level 13
Joined
Jul 26, 2008
Messages
1,009
Actually what I should do is mention them in post and comment the code. Honestly my setup for that code was so confusing even I forgot what I was trying to do there. I just got lazy cause I wanted to return to other aspects of my map.

I went with setting the unit's movespeed back to it's default. While it does limit what I can do with movespeed, it does solve the problem.
 
Status
Not open for further replies.
Top