• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Timed Ability v1.3

  • Timed Ability by Almia
  • Requires:
  • Code
    JASS:
    //************************************************************************************
    //*
    //*
    //*                               TIMED ABILITY
    //*
    //*                                 BY: ALMIA
    //*
    //*
    //************************************************************************************
    //*
    //*    Adds timed abilities to a unit
    //*
    //************************************************************************************
    //*
    //*    Requires:
    //*
    //*    Linked List Table - http://www.hiveworkshop.com/forums/spells-569/linked-list-table-v1-3-a-230076/
    //*
    //************************************************************************************
    //*
    //*    CODE API
    //*
    //*    constant function TimedAbilityDefaultTimeout takes nothing returns real
    //*
    //*        - System default timeout
    //*
    //*    function GetUnitTimedAbilityIndex takes integer spell, unit owner returns integer
    //*
    //*        - Gets the id of the given spell and unit in the system
    //*        - "spell" must be in ASCII(Ex: 'AHtc')
    //*
    //*    function TimedAbilityPeriodic takes nothing returns nothing
    //*
    //*        - Periodic function of system
    //*
    //*    function AddTimedAbility takes unit owner, integer spell, real duration returns nothing
    //*
    //*        - Registers the unit to the system
    //*        - "spell" must be in ASCII(Ex: 'AHtc')
    //*
    //************************************************************************************
    //*
    //*    Variables
    //*
    //*    TA_List = Integer
    //*    TA_Timer = Timer
    //*    TA_Duration = Real Array
    //*    TA_Ability = Integer Array
    //*    TA_Unit = Unit Array
    //*    TA_Count = Integer
    //*
    //************************************************************************************
    constant function TimedAbilityDefaultTimeout takes nothing returns real
        return 0.031250000
    endfunction
    
    //************************************************************************************
    
    function GetUnitTimedAbilityIndex takes integer spell, unit owner returns integer
        return LoadInteger(udg_TA_Hash, GetHandleId(owner), spell)
    endfunction
    
    //************************************************************************************
    
    function TimedAbilityPeriodic takes nothing returns nothing
        local integer id = GetFirstIndexFromLinkedList(udg_TA_List)
        loop
            exitwhen 0 == id
            // Check if duration is not yet 0
            if 0 < udg_TA_Duration[id] then
                set udg_TA_Duration[id] = udg_TA_Duration[id] - TimedAbilityDefaultTimeout()
            else
                //Removing Ability and Recycling Index
                call UnitRemoveAbility(udg_TA_Unit[id], udg_TA_Ability[id])
                call RecycleIndexFromLinkedList(udg_TA_List, id)
                set udg_TA_Ability[id] = 0
                set udg_TA_Unit[id] = null
                set udg_TA_Count = udg_TA_Count - 1
                if 0 == udg_TA_Count then 
                    call PauseTimer(udg_TA_Timer)
                endif
            endif
            set id = GetNextIndexFromLinkedList(udg_TA_List, id)
         endloop
    endfunction
    
    //************************************************************************************
    
    function AddTimedAbility takes unit owner, integer spell, real duration returns nothing
        local integer index = GetUnitTimedAbilityId(spell, owner)
        if 0 == index then
            // Assigning new id to the unregistered unit
            set index = GetNewIndexFromLinkedList(udg_TA_List)
            set udg_TA_Count = udg_TA_Count + 1
            if 1 == udg_TA_Count then
                call TimerStart(udg_TA_Timer, TimedAbilityDefaultTimeout(), true, function TimedAbilityPeriodic)
            endif
            call UnitAddAbility(owner, spell)
            call SaveInteger(udg_TA_Hash, GetHandleId(owner), spell, index)
        endif
        set udg_TA_Ability[index] = spell
        set udg_TA_Duration[index] = duration
        set udg_TA_Unit[index] = owner
    endfunction
    
    //************************************************************************************
    
    function InitTrig_Timed_Ability takes nothing returns nothing
        set udg_TA_List = CreateLinkedList()
        set udg_TA_Hash = InitHashtable()
    endfunction
  • Demo
    • Example
      • Events
        • Unit - A unit Starts the effect of an ability
      • Conditions
      • Actions
        • Custom script: call AddTimedAbility(GetTriggerUnit() , 'Apiv', 5)
  • Changelogs
    - Updated due to the Linked List Table new update
Contents

Timed Ability v1.3 (Map)

Reviews
04:32, 30th Mar 2013 Magtheridon96: Approved. This is useful.

Moderator

M

Moderator

04:32, 30th Mar 2013
Magtheridon96: Approved. This is useful.
 
Level 2
Joined
Jul 26, 2012
Messages
7
i'm new to editor, and i found this system is what i need for my maps (personal use only) , sorry but its work with custom abilities? like if i change the "Apiv" to "A001:Apiv" because the abilities i need to add is custom one. sorry for my bad english , not my native language. thank you
 
Top