--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 .
And Slide spell just do perfect .
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 > 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 > 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>
//Slides a unit over a period of time, from an initial speed to a final speed
//if no effect is wanted just use "none.mdl"
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)>.405 and dat.init>0 and dat.time>.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
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
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
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 > 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>
JASS://gg, your map is toast anyways, destroying a timer is the least of your worries
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.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?
Isnt it easier to use some sort of global timer recyclying as apposed to one per ability?
I actually understand how to make them, but do we must use a global?
call SetData (t,dat)
local SlideUnit dat = GetData (t)
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<8191) then
set $NAME$1<i>=v
elseif (i<16382) then
set $NAME$2[i-8191]=v
elseif (i<24573) then
set $NAME$3[i-16382]=v
else
call BJDebugMsg("Data System Error: Set$NAME$ handle index too high")
endif
endfunction
function Get$NAME$ takes handle h returns $TYPE$
local integer i=DS_H2I(h)-0x100000
if (i<8191) then
return $NAME$1<i>
elseif (i<16382) then
return $NAME$2[i-8191]
elseif (i>=24573) then
call BJDebugMsg("Data System Error: Get$NAME$ handle index too high")
endif
return $NAME$3[i-16382]
endfunction
//! endtextmacro
//! runtextmacro DS_Declare("Data","integer")
endlibrary
</i></i>
It uses I2H?