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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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