- Joined
- Dec 19, 2008
- Messages
- 276
JASS:
library TE
//Ranger21 Timed Effect For Projectiles
//Automatically check when unit die.
private struct TE
effect e
real count = 0
real max
unit u
endstruct
globals
private timer Tim21 = CreateTimer()
private TE array queue
private integer total = 0
endglobals
private function TE_Timer takes nothing returns nothing
local integer i = 0
local TE data
loop
exitwhen i >= total
set data = queue[i]
if data.u==null or GetWidgetLife(data.u)<0.45 then
call DestroyEffect(data.e)
call RemoveUnit(data.u)
call data.destroy()
set total = total - 1
set queue[i] = queue[total]
set i = i - 1
endif
set i = i + 1
endloop
if total == 0 then
call PauseTimer(Tim21)
endif
endfunction
// mN - string for effect path, tW - unit for which one will be attached effect, attach - attach point.
//call AddSpecEffectTim("Laz0r.mdl",u,"origin") xD
function AddSpecEffectTim takes string mN, unit tW, string attach returns effect
local TE data = TE.create()
set data.e=AddSpecialEffectTarget(mN,tW,attach)
set data.u=tW
if total == 0 then
call TimerStart(Tim21, 0.1, true, function TE_Timer)
endif
set queue[total] = data
set total = total + 1
return data.e
endfunction
endlibrary
JASS:
library TA
//Ranger21 TimedAbility
//Allow add ability to unit for integer time.
private struct TA
unit u
integer count = 0
integer id
integer max
integer level
endstruct
globals
private timer Tim = CreateTimer()
private TA array queue
private integer total = 0
endglobals
private function TA_Timer takes nothing returns nothing
local integer i = 0
local TA data
loop
exitwhen i >= total
set data = queue[i]
set data.count =data.count+1
if data.count>=data.max then
if data.level<=0 then
call UnitRemoveAbility(data.u,data.id)
else
call SetUnitAbilityLevel(data.u,data.id,data.level)
endif
call data.destroy()
set total = total - 1
set queue[i] = queue[total]
set i = i - 1
endif
set i = i + 1
endloop
if total == 0 then
call PauseTimer(Tim)
endif
endfunction
function TimedAbility takes integer id,unit u,integer time,integer level returns nothing
local TA data = TA.create()
set data.level=GetUnitAbilityLevel(u,id)
if data.level<=0 then
call UnitAddAbility(u,id)
call SetUnitAbilityLevel(u,id,level)
endif
if data.level>0 then
call SetUnitAbilityLevel(u,id,level)
endif
set data.id = id
set data.u=u
set data.count = 0
set data.max = time
if total == 0 then
call TimerStart(Tim, 1, true, function TA_Timer)
endif
set queue[total] = data
set total = total + 1
endfunction
endlibrary
Well, it's very easy done and can be good for people who want learn structs from some easy ways, also gui users (which have jgnp) can find that usefull.
