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

[vJASS] Can't find a problem with the spell

Status
Not open for further replies.
Level 12
Joined
Sep 24, 2007
Messages
283
Update: forgot one library action
JASS:
library Dash initializer InitDash uses IsTerrainWalkable
globals
private constant real               speed = 12
private constant integer            distance = 400
private constant integer            dpl = 120
private constant integer            ID = 'A001'
private constant integer            BID = 'B000'


timer T = CreateTimer()
real x
real y
real x2
real y2


endglobals

struct Movement

unit u
real angle
real dis
real sp

static Movement array Index
static integer Total



static method Move takes nothing returns nothing
local Movement dat

local integer i = 0
    loop
        exitwhen i >= dat.Total
        set dat = dat.Index[i]
        
        set x = GetUnitX(dat.u)
        set y = GetUnitY(dat.u)
        
        set x2 = x + (Cos(dat.angle * bj_DEGTORAD)*(dat.sp+40))
        set y2 = y + (Sin(dat.angle * bj_DEGTORAD)*(dat.sp+40))
        
        
        if IsTerrainWalkable(x2,y2) then
            call SetUnitX(dat.u, x + (Cos(dat.angle * bj_DEGTORAD)*dat.sp))
            call SetUnitY(dat.u, y + (Sin(dat.angle * bj_DEGTORAD)*dat.sp))
        else
            set dat.dis = -150
        endif
    
        
        set dat.dis = dat.dis - dat.sp
        set dat.sp = dat.sp + 1
        
        if dat.dis <= 0 then
        call SetUnitPathing(dat.u, true)
        call PauseUnit(dat.u, false)
        call UnitRemoveAbility(dat.u,BID)
        
        call dat.destroy()
        set dat.Total = dat.Total - 1
        set dat.Index[i] = dat.Index[dat.Total]
        set i = i - 1
        
        endif
        
    set i = i  + 1
    if dat.Total == 0 then
      call PauseTimer(T)
    endif
    endloop
    
    
endmethod


static method Start takes nothing returns nothing
    local Movement dat = Movement.allocate()
    if dat.Total == 0 then
    call TimerStart(T,0.02,true,function Movement.Move)
    endif
    
    set dat.u = GetTriggerUnit()
    set dat.angle = GetUnitFacing(dat.u)
    set dat.sp = speed
    set dat.dis = distance+(120*GetUnitAbilityLevel(dat.u,ID))
    call SetUnitPathing(dat.u, false)
    call PauseUnit(dat.u, true)
    set dat.Index[dat.Total] = dat
    set dat.Total = dat.Total + 1
endmethod

endstruct




private function Check takes nothing returns boolean
    return GetSpellAbilityId() == ID
endfunction 



private function InitDash takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
    call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i =i+1
        exitwhen i == bj_MAX_PLAYER_SLOTS
    endloop
    
    call TriggerAddAction(t, function Movement.Start)
    call TriggerAddCondition(t, Filter( function Check))
    
endfunction



endlibrary



i dont know why but when i cast spell nothing happens o_O



after some changes my JassHelper stoped to work and it can't be saved. I call it WTF!?
here's the code
JASS:
[code=jass]ibrary Dash initializer InitDash uses IsTerrainWalkable
globals
private constant real               speed = 12
private constant integer            distance = 400
private constant integer            dpl = 120
private constant integer            ID = 'A001'
private constant integer            BID = 'B000'
private constant string             SFX = "Abilities\\Spells\\Other\\StrongDrink\\BrewmasterMissile.mdl"


timer T = CreateTimer()
real x
real y
real x2
real y2
rect r


endglobals

struct Movement

unit u
real angle
real dis
real sp

static Movement array Index
static integer Total = 0



static method Move takes nothing returns nothing
local Movement dat

local integer i = 0
    loop
        exitwhen i >= dat.Total
        set dat = dat.Index[i]
        
        set x = GetUnitX(dat.u)
        set y = GetUnitY(dat.u)
        
        set x2 = x + (Cos(dat.angle * bj_DEGTORAD)*(dat.sp+40))
        set y2 = y + (Sin(dat.angle * bj_DEGTORAD)*(dat.sp+40))
        
        
        if IsTerrainWalkable(x2,y2) then
            call SetUnitX(dat.u, x + (Cos(dat.angle * bj_DEGTORAD)*dat.sp))
            call SetUnitY(dat.u, y + (Sin(dat.angle * bj_DEGTORAD)*dat.sp))
            call IssueImmediateOrder(dat.u, "stop")
            call DestroyEffect(AddSpecialEffect(SFX,x,y))
            
            
            set r = Rect( x2 - 200*0.5, y2 - 200*0.5, x2 + 200*0.5, y2 + 200*0.5 )
            call EnumDestructablesInRect(r, null, function Movement.KillDestruct)
            
            
        else
            set dat.dis = -150
        endif
    
        
        set dat.dis = dat.dis - dat.sp
        set dat.sp = dat.sp + 1
        
        if dat.dis <= 0 then
        call SetUnitPathing(dat.u, true)
        call UnitRemoveAbility(dat.u,BID)
        
        call dat.destroy()
        set dat.Total = dat.Total - 1
        set dat.Index[i] = dat.Index[dat.Total]
        set i = i - 1
        
        endif
        
    set i = i  + 1
    if dat.Total == 0 then
      call PauseTimer(T)
    endif
    endloop
    
    
endmethod


static method Start takes nothing returns nothing
    local Movement dat = Movement.allocate()
    
    if dat.Total == 0 then
    call TimerStart(T,0.02,true,function Movement.Move)
    endif
    
    set dat.u = GetTriggerUnit()
    set dat.angle = GetUnitFacing(dat.u)
    set dat.sp = speed
    set dat.dis = distance+(120*GetUnitAbilityLevel(dat.u,ID))
    call SetUnitPathing(dat.u, false)
    set dat.Index[dat.Total] = dat
    set dat.Total = dat.Total + 1
endmethod


static method KillDestruct takes nothing returns nothing
    call KillDestructable( GetEnumDestructable() )
endmethod

endstruct

private function Check takes nothing returns boolean
    return GetSpellAbilityId() == ID
endfunction 



private function InitDash takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
            exitwhen i == bj_MAX_PLAYER_SLOTS
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i =i+1
    endloop
    
    call TriggerAddAction(t, function Movement.Start)
    call TriggerAddCondition(t, Filter( function Check))
    
endfunction



endlibrary
[/code]
 

Attachments

  • spell2.w3x
    20.5 KB · Views: 38
Last edited:
Level 12
Joined
Sep 24, 2007
Messages
283
ok after a bit changing i got this
JASS:
library Dash initializer InitDash uses IsTerrainWalkable
globals
private constant real               speed = 12
private constant integer            distance = 400
private constant integer            dpl = 120
private constant integer            ID = 'A001'
private constant integer            BID = 'B000'


timer T = CreateTimer()
real x
real y
real x2
real y2


endglobals

struct Movement

unit u
real angle
real dis
real sp

static Movement array Index
static integer Total = 0



static method Move takes nothing returns nothing
local Movement dat

local integer i = 0
    loop
        exitwhen i >= dat.Total
        set dat = dat.Index[i]
        
        set x = GetUnitX(dat.u)
        set y = GetUnitY(dat.u)
        
        set x2 = x + (Cos(dat.angle * bj_DEGTORAD)*(dat.sp+40))
        set y2 = y + (Sin(dat.angle * bj_DEGTORAD)*(dat.sp+40))
        
        
        if IsTerrainWalkable(x2,y2) then
            call SetUnitX(dat.u, x + (Cos(dat.angle * bj_DEGTORAD)*dat.sp))
            call SetUnitY(dat.u, y + (Sin(dat.angle * bj_DEGTORAD)*dat.sp))
        else
            set dat.dis = -150
        endif
    
        
        set dat.dis = dat.dis - dat.sp
        set dat.sp = dat.sp + 1
        
        if dat.dis <= 0 then
        call SetUnitPathing(dat.u, true)
        call PauseUnit(dat.u, false)
        call UnitRemoveAbility(dat.u,BID)
        
        call dat.destroy()
        set dat.Total = dat.Total - 1
        set dat.Index[i] = dat.Index[dat.Total]
        set i = i - 1
        
        endif
        
    set i = i  + 1
    if dat.Total == 0 then
      call PauseTimer(T)
    endif
    endloop
    
    
endmethod


static method Start takes nothing returns nothing
    local Movement dat = Movement.allocate()
    
    if dat.Total == 0 then
    call TimerStart(T,0.02,true,function Movement.Move)
    endif
    
    set dat.u = GetTriggerUnit()
    set dat.angle = GetUnitFacing(dat.u)
    set dat.sp = speed
    set dat.dis = distance+(120*GetUnitAbilityLevel(dat.u,ID))
    call SetUnitPathing(dat.u, false)
    call PauseUnit(dat.u, true)
    set dat.Index[dat.Total] = dat
    set dat.Total = dat.Total + 1
endmethod

endstruct




private function Check takes nothing returns boolean
    return GetSpellAbilityId() == ID
endfunction 



private function InitDash takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
            exitwhen i == bj_MAX_PLAYER_SLOTS
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i =i+1
    endloop
    
    call TriggerAddAction(t, function Movement.Start)
    call TriggerAddCondition(t, Filter( function Check))
    
endfunction


endlibrary


it works now. I will test MUI now.



EDIT: It works nice. THX to all.

Any comments on coding?
 
It is pretty good coding, except you should make the globals "x" and "y" and "x2" and "y2" and "T" all private. (commonly used names)

Also, make:
JASS:
    set dat.angle = GetUnitFacing(dat.u)
Become:
JASS:
    set dat.angle = GetUnitFacing(dat.u)*bj_DEGTORAD

This will save you a couple hundred or more multiplications in the timer callback.

Also, you can inline x2 and y2 into IsTerrainWalkable since that is the only case where you use it.

Otherwise, nice job. =)
 
Status
Not open for further replies.
Top