• 🏆 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] Problems

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
Can someone tell me what's wrong with my script? Here's the script :

JASS:
scope Lightning initializer Init

globals
    
    constant integer DUMMY_ID = 'h000'
    constant integer SPELL_ID = 'A000'
    constant string EFFECT = "Abilities\\Weapons\\ChimaeraLightningMissile\\ChimaeraLightningMissile.mdl"
     
     timer T = CreateTimer()
     integer Total = 0
     integer array Ar
     
endglobals

private struct Data
    
    unit d
    group damaged
    real cos
    real sin
    real fx
    real fy
    
static method create takes unit u, real angle returns Data
    local Data dat = Data.allocate()
    set dat.d = CreateUnitAtLoc( GetOwningPlayer(u), DUMMY_ID, GetUnitLoc(u), angle )
    set dat.cos = Cos(angle)
    set dat.sin = Sin(angle)
    set dat.fx = GetUnitX(dat.d) + 800 * dat.cos
    set dat.fy = GetUnitY(dat.d) + 800 * dat.sin
    
    call TimerStart(T, 0.035, true, function Data.Execute )
    
    if Total == 4000 then
      set Total = 0
    endif
    
    set Total = Total + 1
    set Ar[Total - 1] = dat
    
    return dat
endmethod

static method Execute takes nothing returns nothing
    local Data dat
    local integer i = 0
    local real x
    local real y
    
    loop
      exitwhen i >= Total
      set dat = Ar[i]
      
      if dat.fx != x and dat.fy != y then
        set x = GetUnitX(dat.d) + 8 * dat.cos
        set y = GetUnitY(dat.d) + 8 * dat.sin
        
        call DestroyEffect( AddSpecialEffect( EFFECT, x, y) )
        
        call SetUnitX(dat.d, x)
        call SetUnitY(dat.d, y)
      endif
      
      set i = i + 1
    endloop
endmethod

endstruct

private function Wave takes unit u, real angle returns nothing
    call Data.create(u,angle)
endfunction

//==================================================================

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

private function Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local real ang = GetUnitFacing(caster)
    call Wave(caster,ang)
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 Conditions ) )
    call TriggerAddAction(t, function Actions )
endfunction

endscope

I made the spell part just for testing. When i cast the spell, the dummy unit is created, but doesn't move.

I tried removing the
JASS:
if dat.fx != x and dat.fy != y then
part but then the effect would move, while the dummy wouldnt.

Can someone help me pls?

I attached the map.
 

Attachments

  • Waves.w3x
    16.2 KB · Views: 39
That indexing system is all retarded. Please fix it.

You try to compare the x to target x before you assign any value to x, likewise with y.

The only leak is this:
JASS:
private function Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local real ang = GetUnitFacing(caster)
    call Wave(caster,ang)
endfunction
You need to null that local unit variable.
 
Level 8
Joined
Feb 15, 2009
Messages
463
Can someone tell me what's wrong with my script? Here's the script :

JASS:
scope Lightning initializer Init

globals
    
    constant integer DUMMY_ID = 'h000'
    constant integer SPELL_ID = 'A000'
    constant string EFFECT = "Abilities\\Weapons\\ChimaeraLightningMissile\\ChimaeraLightningMissile.mdl"
     
     timer T = CreateTimer()
     integer Total = 0
     integer array Ar
     
endglobals

private function Execute takes nothing returns nothing
    local Data dat
    local integer i = 0
    local real x
    local real y
    
    loop
      exitwhen i >= Total
      set dat = Ar[i]
      // this is never anything coz x and y are not declared(so its a thing which could be)
      
      if dat.fx != x and dat.fy != y then
        set x = GetUnitX(dat.d) + 8 * dat.cos
        set y = GetUnitY(dat.d) + 8 * dat.sin
        
        call DestroyEffect( AddSpecialEffect( EFFECT, x, y) )
        //some mistakes here but not enough time sry =(
        call SetUnitX(dat.d, x)
        call SetUnitY(dat.d, y)
      endif
      
      set i = i + 1
    endloop
endmethod

private struct Data
    
    unit d
    group damaged
    real cos
    real sin
    real fx
    real fy
    


static method create takes unit u, real angle returns Data
    local Data dat = Data.allocate()
    set dat.d = CreateUnit( GetOwningPlayer(u), DUMMY_ID, GetUnitX(u), GetUnitY(u), angle )
    set dat.cos = Cos(angle)
    set dat.sin = Sin(angle)
    set dat.fx = GetUnitX(dat.d) + 800 * dat.cos
    set dat.fy = GetUnitY(dat.d) + 800 * dat.sin
    
    call TimerStart(T, 0.035, true, function Execute )
    
    if Total >= 4000 then
      call dat.destroy()
      set Total = 0
    endif
    
    set Total = Total + 1
    set Ar[Total - 1] = dat
    
    return dat
endmethod



method onDestroy takes nothing returns nothing
     call RemoveUnit( this.d) // or .d
     call DestroyGroup( this.damaged) // or .damaged
     set .d = null
     set .damaged = null
endmethod

endstruct

//==================================================================

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

private function Actions takes nothing returns nothing
    call Data.create(GetTriggerUnit(),GetUnitFacing(GetTriggerUnit()))
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 Conditions ) )
    call TriggerAddAction(t, function Actions )
endfunction

endscope

I made the spell part just for testing. When i cast the spell, the dummy unit is created, but doesn't move.

I tried removing the
JASS:
if dat.fx != x and dat.fy != y then
part but then the effect would move, while the dummy wouldnt.

Can someone help me pls?

I attached the map.

I dont get to much time for this but i just fixed your loc leak , and the unnecessary declaration in Actions,removed the wave sheet etc...
 
Status
Not open for further replies.
Top