1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  5. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  6. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Do you have good ideas for new contests? If so, please open new threads in the Contest Submission sub-forum to discuss them.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Simple Temporary Ability System

Submitted by iam20842
This bundle is marked as pending. It has not been reviewed by a staff member yet.
Simple Temporary Ability System.
Version: 0.0.3


Now it make sense!


When a unit cast a certain spell, the system will add another spell that correspond to the spell casted.

This spell added will be in the hero spell a certain time, called expiration time.

Is usefull if you want create spell chain, combo, or next spell behaviour

How it works?

1. Create your spells, in this case will use one base, and two more. the flow will be:
1.1 when base you will get combo
1.2 when cast combo you will get wombo
1.3 If you set the icon for all the spell at same values, you will overwrite the spell.
1.4 If you set different pos(x,y) you will get multiple icon, take care about the expiration time, because if the NEXT spell have more time than the BASE you can keep spamming the NEXT spell.

2. In STAS LIBRARY save the globals variable of your spell id, need to the expiration time of the spell. this mean, the amount of time that temporary spell will remain in unit available spells.

3. Use the CreateTemporaryAbility to create the temporary chain between the spell.

4. Use the CastTemporaryAbility to use the system.

5. Enjoy!


Advantages

* Is MUI
* Use timers
* Easy configuration
* Now with Create and Cast function!

Version 0.0.3

Code (vJASS):

globals
    hashtable STASSkills = InitHashtable()
    hashtable STASIndexer = InitHashtable()

    integer ONE_SPELL          = 'A000'
    integer ONE_TO_TWO_SPELL   = 'A001'
    integer TWO_TO_THREE_SPELL = 'A002'

    real ONE_TO_TWO_SPELL_ET = 3.00
    real TWO_TO_ONE_SPELL_ET = 1.00

endglobals

library STAS
    function CreateTemporaryAbility takes integer bs, integer ns, real nset returns nothing
        call SaveInteger(STASSkills, bs, StringHash("NEXT"), ns)
        call SaveReal(STASSkills, bs, StringHash("EXPTIME"), nset)
    endfunction

    function STASTemporaryTimeHandler takes nothing returns nothing
        // USE: On timer expiration, remove the next spell

        // Get the expired timer
        local timer t = GetExpiredTimer()

        // Get the caster unit through timer ID
        local unit caster = LoadUnitHandle(STASIndexer, GetHandleId(t), StringHash("CASTER"))

        // Get the next_spell spell ID
        local integer NEXT = LoadInteger(STASIndexer, GetHandleId(t), StringHash("NEXT"))

        // Remove the spell
        call UnitRemoveAbility(caster, NEXT)

        // For avoid bugs of timer, pause it
        call PauseTimer(t)

        // Destroy the timer
        call DestroyTimer(t)

        // Remove leak
        set t = null
        set caster = null
    endfunction

    function CastTemporaryAbility takes unit cu, integer cs returns nothing
        local real et
        local timer t
        local integer ns = LoadInteger(STASSkills, cs, StringHash("NEXT"))

        if (ns != 0) then

            // Initialize the timer
            set t = CreateTimer()

            // Save expiration time
            set et = LoadReal(STASSkills, cs, StringHash("EXPTIME"))
   
            // Save to hashtable the unit that cast the spell
            call SaveUnitHandle(STASIndexer, GetHandleId(t), StringHash("CASTER"), cu)

            // Save the next_spell spell ID
            call SaveInteger(STASIndexer, GetHandleId(t), StringHash("NEXT"), ns)

            // Add new spell to caster
            call UnitAddAbility(cu, ns)

            // Start the timer
            call TimerStart(t, et, false, function STASTemporaryTimeHandler)
        else
             return
        endif
 
        // Avoid leaks
        set cu = null
        set t = null
    endfunction

endlibrary
 


Code (vJASS):

function sca takes nothing returns nothing

    call CreateTemporaryAbility(ONE_SPELL, ONE_TO_TWO_SPELL, ONE_TO_TWO_SPELL_ET)
    call CreateTemporaryAbility(ONE_TO_TWO_SPELL, TWO_TO_THREE_SPELL, TWO_TO_ONE_SPELL_ET)

endfunction

//===========================================================================
function InitTrig_STAS_Creation takes nothing returns nothing
    local trigger tg = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( tg, 0.00 )
    call TriggerAddAction( tg, function sca )
endfunction

 

Code (vJASS):

function STASActions takes nothing returns nothing
    // Get the caster unit
    local unit c = GetSpellAbilityUnit()

    // Get the casted spell
    local integer cs = GetSpellAbilityId()

    // Call the temporary system
    call CastTemporaryAbility(c, cs)

    set c = null
endfunction

function InitTrig_STAS_Cast takes nothing returns nothing
    local trigger tg = CreateTrigger()
    local integer i = 0

    call TriggerAddAction(tg, function STASActions)

    loop
        call TriggerRegisterPlayerUnitEvent(tg, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set i = i + 1
    exitwhen i == bj_MAX_PLAYERS
    endloop
endfunction
 


More Credits:
* Hate, code correction
Contents

Simple Temporal Ability System 0.0.1 (Map)

Simple Temporal Ability System 0.0.2 (Map)

Simple Temporal Ability System 0.0.3 (Map)

  1. JC Helas

    JC Helas

    Joined:
    Oct 19, 2014
    Messages:
    127
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Im still confuse of how the system works, but i have to say this

    CAST


    why not try to index everything just to prevent create and destroy timer

    CONFIGURE


    You had the uniqueness idead but much better to infunction those ability id like
    Code (vJASS):

    constant function BASE_SPELL takes nothing returns integer
        return 'A000'
    endfunction
     

    Also those saved by handles
     
  2. iam20842

    iam20842

    Joined:
    Jan 13, 2019
    Messages:
    272
    Resources:
    0
    Resources:
    0
    Thanks for the comment, i will update the trigger and the post :)
     
  3. iam20842

    iam20842

    Joined:
    Jan 13, 2019
    Messages:
    272
    Resources:
    0
    Resources:
    0
    Pending:

    * Change Magic Number to CONSTANTS
    * Change individual trigger to a library
    * Another improvements
     
  4. iam20842

    iam20842

    Joined:
    Jan 13, 2019
    Messages:
    272
    Resources:
    0
    Resources:
    0
    Changes:

    1. Magic number not longer exist
    2. Terms changed (no more wombo, combo, lombo) instead NEXT_SPELL
     
  5. _Guhun_

    _Guhun_

    Joined:
    Jun 12, 2010
    Messages:
    371
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    I think you should rename this system to Simple TEMPORARY Ability System. Calling it temporal and using an hourglass as your image gives an impression that the system is related to abilities that manipulate time (such as going back in time or pausing units).
     
  6. iam20842

    iam20842

    Joined:
    Jan 13, 2019
    Messages:
    272
    Resources:
    0
    Resources:
    0
    Now it make sense!, see the restructuration of the library :D
     
  7. JC Helas

    JC Helas

    Joined:
    Oct 19, 2014
    Messages:
    127
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Wow, i just felt yesterday of talking this, impressive you learn too fast, but i have to test this and i'll feedback right after testing,
     
  8. iam20842

    iam20842

    Joined:
    Jan 13, 2019
    Messages:
    272
    Resources:
    0
    Resources:
    0
    hahaha yeah, i learn too fast, is one of my strengths. Thanks :D. i got another post of simple system!
     
  9. JC Helas

    JC Helas

    Joined:
    Oct 19, 2014
    Messages:
    127
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Done testing your system,, i have even test in multiple unit,, and it work so, but one that keeps bugging my mind, or even experts will tell you this,, why not try to avoid creating and destroying timers, instead use one and ingroup those casters as well
     
  10. iam20842

    iam20842

    Joined:
    Jan 13, 2019
    Messages:
    272
    Resources:
    0
    Resources:
    0
    i see this on internet: one timer with time 1 and every expiration set a integer to integer - 1 , and this integer is assigned to a hashtable that have the unit id?
     
  11. iam20842

    iam20842

    Joined:
    Jan 13, 2019
    Messages:
    272
    Resources:
    0
    Resources:
    0
    The first implementation of my system was using this Making countdown timers MUI
     
  12. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,788
    Resources:
    1
    Spells:
    1
    Resources:
    1
    In general, yes. However when using a single timer your margin of error for any given duration is +-(timerperiod) so timing for a duration of 9s could actually take as long as 9.999... or as short as 8.000..1. I would use a shorter timer period like 0.2, so then instead of storing 9 as the integer to count down you store 9*1/(timerperiod) = 9*5 = 45
     
  13. iam20842

    iam20842

    Joined:
    Jan 13, 2019
    Messages:
    272
    Resources:
    0
    Resources:
    0
    Thanks for that suggestion, can you check my others system too please?. in my profile page you can get the link :D