• 🏆 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!

Easy Struct Systems(Timed Ability, Timed Effect Attach)

Status
Not open for further replies.
Level 7
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.:grin: Heh, goodluck guys.
 
Level 7
Joined
Dec 19, 2008
Messages
276
It is compatible with both 1.23 and 1.24

And i finded one system of timed effects... it will not work...

Well i use that in my map for compability :p and you can not use this ofc, it is for people who want understand basic struct's. (coz they even better then some systems)
 
Status
Not open for further replies.
Top