• 🏆 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] Slide Spell

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
As usual, i have a problem :grin:

JASS:
scope Slide initializer Init

globals

    constant integer SPELL_ID = 'A000'
    constant integer DUMMY_ID = 'h000'
    
    constant real SPEED = 600
    constant real INTERVAL = 0.035
    
    timer Tim
    
endglobals

struct Slide

    unit u
    real x
    real y
    real dx
    real dy
    
    static Slide array Index
    static integer Total
    
    static method Loop takes nothing returns nothing
        local Slide dat
        local integer i = 0
        loop
            exitwhen i >= dat.Total
            set dat = dat.Index[i]
            set dat.x = dat.x + dat.dx
            set dat.y = dat.y + dat.dy
            
            call SetUnitPosition(dat.u, dat.x, dat.y)
            
            set dat.Total = dat.Total - 1
            set dat.Index[i] = dat.Index[dat.Total]
        endloop
        
        if dat.Total == 0 then
            call PauseTimer(Tim)
        endif
    endmethod
    
    static method Start takes unit caster, real targetX, real targetY returns nothing
        local Slide dat = Slide.allocate()
        local real distanceX
        local real distanceY
        local real distance
        local real angle
        set dat.x = GetUnitX(caster)
        set dat.y = GetUnitY(caster)
        set distanceX = targetX - dat.x
        set distanceY = targetY - dat.y
        set distance = SquareRoot(distanceX * distanceX + distanceY * distanceY)
        set dat.dx = distanceX/distance*SPEED*INTERVAL
        set dat.dy = distanceY/distance*SPEED*INTERVAL
        set angle = bj_DEGTORAD * Atan2(distanceY, distanceX)
        set dat.u = CreateUnit(GetOwningPlayer(caster), DUMMY_ID, dat.x, dat.y, angle)
        
        if dat.Total == 0 then
            call TimerStart(Tim, INTERVAL, true, function Slide.Loop)
        endif
        set dat.Index[dat.Total] = dat
        set dat.Total = dat.Total + 1
    endmethod
    
endstruct
    
private function Cond takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

private function Act takes nothing returns nothing
    local location l = GetSpellTargetLoc()
    call Slide.Start( GetTriggerUnit(), GetLocationX(l), GetLocationY(l) )
    call RemoveLocation(l)
    set l = null
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition(t, Condition( function Cond ) )
    call TriggerAddAction(t, function Act )

    set Tim = CreateTimer()
endfunction

endscope

VERY IMPORTANT READ:I know i DON'T destroy the struct. I'll put that in later. Don't say "You don't destroy the struct" and stuff like that!

So as usual, the dummy won't move. I set its speed to 1, but it still doesn't work.
 
Status
Not open for further replies.
Top