Need Example of Slide Spell with Structs

--Thanatos--

New Member
Reaction score
33
I just read Vex' Tutorial about Struct, and I think I need some example...

And Slide spell just do perfect :D.
 

substance

New Member
Reaction score
34
Actually I think em3jir (i always mess up his name) posted a slide script using struct not too long ago.

Then again, maybe it used tables... :confused:

go search!
 

Tom Jones

N/A
Reaction score
437
Here's a simple example:
JASS:
scope SlideTest
globals
    private integer array structs
    private integer       index         = 0
    private timer         t             = CreateTimer()
    private real          SlideDistance = 300.
    private real          SlideSpeed    = 300.
endglobals

private struct data
    unit v
    real dist
endstruct

private function Timer_Actions takes nothing returns nothing
    local integer i = 1
    local data s
    local real x
    local real y

    loop
        exitwhen i > index
        set s = data(structs<i>)
        set x = GetUnitX(s.v)+(SlideSpeed*0.05)*Cos((360-GetUnitFacing(s.v))*(3.14/180))
        set y = GetUnitY(s.v)+(SlideSpeed*0.05)*Sin((360-GetUnitFacing(s.v))*(3.14/180))
        call SetUnitPosition(s.v,x,y) 
        set s.dist = s.dist+(SlideDistance*0.05)
        if s.dist &gt; SlideDistance then
            call s.destroy()
            set structs<i> = data(structs[index])
            set index = index-1
            if index == 0 then
                call PauseTimer(t)
            endif
            set i = i-1
        endif
        set i = i+1
    endloop
endfunction

private function Actions takes nothing returns nothing
    local data s = data.create()  

    set s.v = GetSpellTargetUnit()
    if index == 0 then
        call TimerStart(t,0.05,true,function Timer_Actions)
    endif
    set index = index+1
    set structs[index] = data(s)
endfunction

//===========================================================================
function InitTrig_Test takes nothing returns nothing
    local integer i = 0
    local integer a = GetPlayers()

    set gg_trg_Test = CreateTrigger()
    loop
        exitwhen i &gt; a
        call TriggerRegisterPlayerUnitEvent(gg_trg_Test,Player(i),EVENT_PLAYER_UNIT_SPELL_EFFECT,null
        set i = i+1
    endloop
    call TriggerAddAction( gg_trg_Test, function Actions)
endfunction
endscope</i></i>
Though it would be just as easy to simply use globals.
 

emjlr3

Change can be a good thing
Reaction score
395
where tom jones' uses a timer recycle method, this does not, but allows for customization of the slide for each unit, maybe ill update mine at some point to recycle too

JASS:
//Slides a unit over a period of time, from an initial speed to a final speed
//if no effect is wanted just use &quot;none.mdl&quot;
private struct SlideUnit
    unit u
    real init
    real dec
    real time
    real cos
    real sin
    string sfx
endstruct  
function SlideUnitTimed_Child takes nothing returns nothing  
    local timer t = GetExpiredTimer()   
    local SlideUnit dat = GetData(t)    
    local real x = GetUnitX(dat.u)+dat.init*dat.cos
    local real y = GetUnitY(dat.u)+dat.init*dat.sin     
      
    if GetWidgetLife(dat.u)&gt;.405 and dat.init&gt;0 and dat.time&gt;.01 then
        call SetUnitPosition(dat.u,SafeX(x),SafeY(y))
        call DestroyEffect(AddSpecialEffect(dat.sfx,x,y)) 
        set dat.init = dat.init - dat.dec
        set dat.time = dat.time - TimeOut
    else
        call dat.destroy()
        call EndTimer(t)        
    endif  
    
    set t = null   
endfunction  
function SlideUnitTimed takes unit toslide, real duration, real initSpeed, real finalSpeed, real angle, string sfx returns nothing
    local timer t = GetTimer()
    local SlideUnit dat = SlideUnit.create()           
       
    set dat.u = toslide    
    set dat.init = initSpeed
    set dat.dec = (initSpeed-finalSpeed)/((duration/TimeOut)-1)
    set dat.cos = Cos(angle*bj_DEGTORAD)
    set dat.sin = Sin(angle*bj_DEGTORAD)      
    set dat.time = duration
    set dat.sfx = sfx  
    
    call SetData(t,dat)      
    call TimerStart(t, TimeOut, true, function SlideUnitTimed_Child)
    
    set t = null        
endfunction
 

Tom Jones

N/A
Reaction score
437
Scopes are basically the same as libraries, except that scopes will not be moved to the beginning of the script, and scopes can be nested.
*Edit*
GetTimer() and EndTimer() is CS_Cache functions?
 

substance

New Member
Reaction score
34
Isnt it easier to use some sort of global timer recyclying as apposed to one per ability?

JASS:

globals
 private timer array TIMERS
 private integer TIMERS_N = 0
endglobals

function NewTimer takes nothing returns timer
 if (TIMERS_N==0) then
     return CreateTimer()
 endif
 set TIMERS_N = TIMERS_N - 1
 return TIMERS[TIMERS_N]
endfunction
function ReleaseTimer takes timer t returns nothing
 call PauseTimer(t)
 set TIMERS[TIMERS_N] = t
 set TIMERS_N = TIMERS_N + 1
endfunction
 

emjlr3

Change can be a good thing
Reaction score
395
JASS:
library TimerSafety needs Tables

//==========================================================================================
globals
    private timer array cs_Timers
    private integer cs_N_Timers = 0
endglobals

//==========================================================================================
function GetTimer takes nothing returns timer
    if (cs_N_Timers==0) then
        return CreateTimer()
    endif
    set cs_N_Timers=cs_N_Timers-1
    return cs_Timers[cs_N_Timers]
endfunction

//==========================================================================================
function EndTimer takes timer t returns nothing
    call PauseTimer(t)
    call FlushStoredMission(cscache,I2S(CS_H2I(t)))
    if (cs_N_Timers==8191) then
        //gg, your map is toast anyways, destroying a timer is the least of your worries
        call DestroyTimer(t)
    else
        set cs_Timers[cs_N_Timers]=t
        set cs_N_Timers=cs_N_Timers+1
    endif    
endfunction

endlibrary



//===========================================================================
function InitTrig_Timer_Safety takes nothing returns nothing
endfunction


timer recycles

however i just rewrote my slide to use 1 timer :)


**the only thing i don't understand is the part where you take your last struct and move it to your current, for ex.

JASS:
globals
    private timer SlideUnitTimer = CreateTimer()
    private integer SlideTotal
    private SlideUnit array SlideStructArray
endglobals   
private struct SlideUnit
    poop
endstruct  
function poo takes nothing returns nothing
    local integer i = 1
    loop
        exitwhen i &gt; SlideTotal
        set dat = SlideStructArray<i>
        if blarg then
            do stuff
        else
            call dat.destroy()
            set SlideStructArray<i> = SlideStructArray[SlideTotal]
            set SlideTotal = SlideTotal - 1
            if SlideTotal==0 then
                call PauseTimer(SlideUnitTimer)
            endif
        endif
        set i = i + 1
    endloop
endfunction
function blurg takes nothing returns nothing
    local SlideUnit dat = SlideUnit.create()
    if SlideTotal==0 then     
        call TimerStart(SlideUnitTimer, .033, true, function poo)
    endif
    set SlideTotal = SlideTotal + 1
    set SlideStructArray[SlideTotal] = dat
endfunction</i></i>


seems to me that for instance u got 10 total, and your on number 5

the unit is done sliding, so u destroy that data, then set data5 = data10 and set your total to -1

but since data5 just ran, i = 6 next loop, thus data5 will not run again on that go around, and since you lowered your total by 1, data10 will not run either since your total is now 9, so what was data10, but now is data5, will never run on that go around, not until the timer expires again...what gives?
 

Tom Jones

N/A
Reaction score
437
JASS:
 //gg, your map is toast anyways, destroying a timer is the least of your worries
:D
Aside from the very funny comment, that's actually pretty smart.
*Edit*
seems sto me that for instance u got 10 total, and your on number 5

the unit is done sliding, so u destroy that data, then set data5 = data10 and set your total to -1

but since data5 just ran, i = 6 next go around, thus 5 will not run again, an dsince you lowered your total by 1, 10 will not run, so what was 10, but now is 5 will never run on that timer run...what gives?
If your referring to my coding your corret, it would cause problems. That's why, let's take your example, if the slide is over and the variables are swapped, I run 5 again. Notice the set i = i-1 at the end of the if statement.
 

emjlr3

Change can be a good thing
Reaction score
395
ooooo, alright, cant believe I missed that
 

Arkan

Nobody rides for free
Reaction score
92
Yes it is MUI, you have a global array of your struct and one global timer, in the timer action you cycle through this array to perform actions for all units/players currently using the struct.
 

--Thanatos--

New Member
Reaction score
33
Ok, I need an example like this:
With Handle Vars:

I actually understand how to make them, but do we must use a global?
 

emjlr3

Change can be a good thing
Reaction score
395
globals are great, do not frown upon them, but up until now they were difficult to make, but now since we can delcare them dynamically, I use them all the time, where I used to use GC and other things
 

grim001

New Member
Reaction score
10
It's my system for attaching things using globals...

JASS:

library DataSystem

function DS_H2I takes handle h returns integer
    return h
    return 0
endfunction

//! textmacro DS_Declare takes NAME, TYPE
globals
 public $TYPE$ array $NAME$1
 public $TYPE$ array $NAME$2
 public $TYPE$ array $NAME$3
endglobals

function Set$NAME$ takes handle h, $TYPE$ v returns nothing
 local integer i=DS_H2I(h)-0x100000
    if (i&lt;8191) then
        set $NAME$1<i>=v
    elseif (i&lt;16382) then
        set $NAME$2[i-8191]=v
    elseif (i&lt;24573) then
        set $NAME$3[i-16382]=v
    else
        call BJDebugMsg(&quot;Data System Error: Set$NAME$ handle index too high&quot;)
    endif
endfunction

function Get$NAME$ takes handle h returns $TYPE$
 local integer i=DS_H2I(h)-0x100000
    if (i&lt;8191) then
        return $NAME$1<i>
    elseif (i&lt;16382) then
        return $NAME$2[i-8191]
    elseif (i&gt;=24573) then
        call BJDebugMsg(&quot;Data System Error: Get$NAME$ handle index too high&quot;)
    endif
 return $NAME$3[i-16382]
endfunction
//! endtextmacro

//! runtextmacro DS_Declare(&quot;Data&quot;,&quot;integer&quot;)
endlibrary
</i></i>
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top