1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Find your way through the deepest dungeon in the 18th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A brave new world lies beyond the seven seas. Join the 34th Modeling Contest today!
    Dismiss Notice
  4. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Spell Effect Indexer v1.5

Submitted by Almia
This bundle is marked as approved. It works and satisfies the submission rules.
  • Introduction
    • Are you tired of rewriting a spell indexer all over again?
    • Do you want a much easier spell indexer?
    • Then here it is, the Spell Indexer!
    • This helps users who uses a dynamic indexing and linked list for their spells.
  • Features
    • Spell Effect Event with corresponding Event variables for better retrieving
    • Easy registering spells
    • Auto registers looping timer event for every trigger with looping
  • Requires:
  • Code
    Code (vJASS):

    //************************************************************************************
    //*
    //*
    //*                      SPELL EFFECT INDEXER
    //*
    //*                             BY : ALMIA
    //*
    //*
    //************************************************************************************
    //*
    //*    Indexes every instance created by a casted spell/ ability
    //*
    //************************************************************************************
    //*
    //*    Requires:
    //*
    //*    Linked List Table = http://www.hiveworkshop.com/forums/spells-569/linked-list-table-v1-2-a-230076/
    //*
    //************************************************************************************
    //*
    //*    Code API
    //*
    //*    constant function SpellDefaultTimeout takes nothing returns real
    //*        - System default timeout for looping spells
    //*
    //*    function TriggerRegisterSpellEffect takes integer spell, trigger onEffect, trigger onLoop  returns nothing
    //*
    //*        - Registers the spell to the system
    //*        - Also, it registers the triggers being evaluated and looped
    //*        - Creates linked lists for every spell registered
    //*
    //*    function RegisterSpellEffect takes integer spell, code onEffect ,code onLoop returns nothing
    //*        - Same goes to TriggerRegisterSpellEffect, though uses code
    //*
    //*    function OnSpellEffect takes nothing returns boolean
    //*
    //*        - System trigger condition
    //*        - Evaluates the triggers for every spell casted
    //*        - Creates new indexed instance for multi instancability
    //*
    //*    function RecycleSpellIndex takes integer spell, integer index returns nothing
    //*
    //*        - Recycles the spell's current index
    //*        - Used when the spell's effect ends in the loop
    //*
    //*    function GetSpellNewIndex takes integer spell returns integer
    //*
    //*        - Wrapper for SpellEffectEventIndex
    //*        - Created in case the SpellEffectEventIndex is overwritten
    //*
    //*    function SpellGetFirst takes integer a returns integer
    //*
    //*        - Gets the starting index of the spell's linked list
    //*
    //*    function SpellGetNext takes integer a, integer index returns integer
    //*
    //*        - Gets the next index of the given index from a spell's linked list
    //*
    //*
    //************************************************************************************
    //*
    //*    ITERATION MODULE
    //*
    //*    All variables in between "$" will be replaced by your own variables
    //*    Must be CnPed
    //*
    //*    Variables required:
    //*
    //*    $SPELL$ = your Spell
    //*    $INDEX$ = Your Index variable
    //*
    //*    =====================================================================
    //*
    //*    set $INDEX$ = SpellGetFirst($SPELL$)
    //*
    //*    loop
    //*    
    //*        exitwhen 0 == $INDEX$
    //*
    //*        ( YOUR CODE HERE )
    //*
    //*        ( IF YOUR SPELL'S EFFECT HAS ENDED )
    //*        ( MAKE SURE TO USE "call RecycleSpellIndex($SPELL$, $INDEX$)
    //*
    //*        set $INDEX$ = SpellGetNext($SPELL$, $INDEX$)
    //*
    //*    endloop
    //*
    //*    =====================================================================
    //*
    //************************************************************************************
    //*
    //*    NOTES:
    //*
    //*    - Registers spells only in map initialization triggers.
    //*    - Do not register any events in your trigger which will have the spell's effect
    //*    - Do not register any events in your spell effect loop trigger
    //*    - Iteration module must be followed when iterating instances
    //*    - You can uses either GetSpellNewIndex or SpellEffectEventIndex to get
    //*      the spell being casted
    //*    - Use SpellEffectEventAbility to retrieve the casted spell
    //*
    //************************************************************************************
    //*
    //*    Variables :
    //*
    //*    SpellEffectEventIndex   = Integer
    //*    SEI_Table = Hashtable
    //*
    //************************************************************************************
    constant function SpellDefaultTimeout takes nothing returns real
        return 0.031250000
    endfunction

    //************************************************************************************

    function OnSpellEffect takes nothing returns boolean

        // Locals
        local integer spell = GetSpellAbilityId()
        local integer count
        local trigger t
       
        if HaveSavedBoolean(udg_SEI_Table, spell, 0) then

            set t = LoadTriggerHandle(udg_SEI_Table, spell, 1)
            //Evaluating trigger with event-related variables

            set udg_SpellEffectEventIndex = GetNewIndexFromLinkedList(LoadInteger(udg_SEI_Table, spell, 0))

            //In case EventIndex is overwritten, save variable
            call SaveInteger(udg_SEI_Table, spell, 4, udg_SpellEffectEventIndex)
       
            //Start evaluating
            if TriggerEvaluate(t) then
                call TriggerExecute(t)
            endif

            set t = null
       
            //Count instances
            set count = LoadInteger(udg_SEI_Table, spell, 3) + 1
            call SaveInteger(udg_SEI_Table, spell, 3, count)

            //If instances counted is equal to 1
            //then turn on the looping trigger

            if 1 == count then
                call EnableTrigger(LoadTriggerHandle(udg_SEI_Table, spell, 2))
            endif
        endif
        return false
    endfunction

    //************************************************************************************

    function InitSpellIndexer takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( t, Filter(function OnSpellEffect))
        set udg_SEI_Table = InitHashtable()
        set t = null
    endfunction

    //************************************************************************************

    function TriggerRegisterSpellEffect takes integer spell, trigger onEffect, trigger onLoop  returns nothing
        if null == udg_SEI_Table then
            call InitSpellIndexer()
        endif
        call SaveBoolean(udg_SEI_Table, spell, 0, true)

        // Creating new linked list for the registered ability
        call SaveInteger(udg_SEI_Table, spell, 0, CreateLinkedList())

        // Saving trigger related to spell
        call SaveTriggerHandle(udg_SEI_Table, spell, 1, onEffect)
        call SaveTriggerHandle(udg_SEI_Table, spell, 2, onLoop)

        // registering looping event
        call TriggerRegisterTimerEvent(onLoop, SpellDefaultTimeout(), true)
    endfunction

    //************************************************************************************

    function RegisterSpellEffect takes integer spell, code onEffect ,code onLoop returns nothing
        local trigger t = CreateTrigger()
        local trigger t2 = CreateTrigger()
        call TriggerAddCondition(t, Condition(onEffect))
        call TriggerAddCondition(t, Condition(onLoop))
        call TriggerRegisterSpellEffect(spell, t, t2)
        set t = null
        set t2 = null
    endfunction

    //************************************************************************************

    function RecycleSpellIndex takes integer spell, integer index returns nothing
       
        // Recycling Instance
        local integer count = LoadInteger(udg_SEI_Table, spell, 3) - 1
        call RecycleIndexFromLinkedList(LoadInteger(udg_SEI_Table, spell, 0), index)
        call SaveInteger(udg_SEI_Table, spell, 3, count)

        // If number of instance counted is equal to 0
        // Disable trigger
        if 0 == count then
            call DisableTrigger(LoadTriggerHandle(udg_SEI_Table, spell, 2))
        endif
    endfunction

    //************************************************************************************
    //*
    //*                       EXTRA FUNCTIONS or UTILS
    //*
    //************************************************************************************

    // SPELL EFFECT EVENT RELATED
    function GetSpellNewIndex takes integer spell returns integer
        return LoadInteger(udg_SEI_Table, spell, 4)
    endfunction

    // ITERATION RELATED
    function SpellGetFirst takes integer a returns integer
        return GetFirstIndexFromLinkedList(LoadInteger(udg_SEI_Table, a, 0))
    endfunction

    function SpellGetNext takes integer a, integer index returns integer
        return GetNextIndexFromLinkedList(LoadInteger(udg_SEI_Table, a, 0), index)
    endfunction

    //************************************************************************************
     
  • Demo
      • TC Start
        • Events
          • Map initialization
        • Conditions
        • Actions
          • Custom script: call RegisterSpellEffect('AHtc', gg_trg_TC_Cast , gg_trg_TC_Loop)
      • TC Cast
        • Events
        • Conditions
        • Actions
          • Set TC_Index = SpellEffectEventIndex
          • Set TC_U[TC_Index] = (Triggering unit)
          • Set TC_Time[TC_Index] = 0.00
          • Set TC_Duration[TC_Index] = 10.00
      • TC Loop
        • Events
        • Conditions
        • Actions
          • Custom script: set udg_TC_Index = SpellGetFirst('AHtc')
          • Custom script: loop
          • Custom script: exitwhen 0 == udg_TC_Index
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TC_Time[TC_Index] Less than TC_Duration[TC_Index]
            • Then - Actions
              • Custom script: set udg_TC_Time[udg_TC_Index] = udg_TC_Time[udg_TC_Index] + SpellDefaultTimeout()
              • Set TC_Loc = (Position of TC_U[TC_Index])
              • Special Effect - Create a special effect at TC_Loc using Abilities\Spells\Orc\MirrorImage\MirrorImageCaster.mdl
              • Special Effect - Destroy (Last created special effect)
              • Custom script: call RemoveLocation(udg_TC_Loc)
            • Else - Actions
              • Custom script: call RecycleSpellIndex('AHtc', udg_TC_Index)
              • Set TC_U[TC_Index] = No unit
              • Set TC_Duration[TC_Index] = 0.00
              • Set TC_Time[TC_Index] = 0.00
          • Custom script: set udg_TC_Index = SpellGetNext('AHtc',udg_TC_Index)
          • Custom script: endloop
  • Installing
    • Install Linked List Table
    • Copy the Spell Effect Indexer trigger.
    • Create variables listed in the code
  • Changelogs
    • Updated system due to Linked List Table's update.
    • Updated due to Linked List Table's update
    • Code simplified
    • - New Update -
    • Now supports codes
    • Updated to get rid of Wacraft III Header compiler's bug
Contents

SpellEffect Indexer v1.5 (Map)

Reviews
Moderator
23:02, 2nd Jan 2013 Magtheridon96: Approved, but change the function names used for iteration. They're too short and general. Add more words to them. Something like SpellInstanceListGetFirst and SpellInstanceListGetNext.
  1. 23:02, 2nd Jan 2013
    Magtheridon96: Approved, but change the function names used for iteration. They're too short and general. Add more words to them. Something like SpellInstanceListGetFirst and SpellInstanceListGetNext.
     
  2. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    ~Reserved.
     
  3. Ofel

    Ofel

    Joined:
    Mar 29, 2012
    Messages:
    431
    Resources:
    10
    Spells:
    10
    Resources:
    10
    It's not one trigger, it's 4 triggers but created after the first trigger executed :D (Kidding)
     
  4. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    I just expressed only one trigger because i only use one in making it :D
     
  5. Ofel

    Ofel

    Joined:
    Mar 29, 2012
    Messages:
    431
    Resources:
    10
    Spells:
    10
    Resources:
    10
    Nice idea...

    I'll use this on my map... (if approved)

    Can you give me an idea for making a system, because all my system is rejected :(
     
    Last edited: Dec 21, 2012
  6. Lord_Demon_X

    Lord_Demon_X

    Joined:
    Nov 13, 2012
    Messages:
    22
    Resources:
    4
    Spells:
    4
    Resources:
    4
    Very nice system, very hepful for me because I'm a bit bored to do an index system for each spell that I make.

    But got a problem, tried the system with a spell which has a bad indexing system and the loop just bugged

    1) The dummy always move from a 360° angle (his going to the right, not doing a circle)

    2) When the spell is casted likes any MUI spell others instances stop from moving, continue from doing specials effects and don't disappears.

    So I dunno why this happen because I done these:

     
    Last edited: Dec 21, 2012
  7. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Did you indexed the dummy?It must work just like a Dynamic Indexing
     
  8. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    hmmm, maybe add another function that takes the rawcode as parameter for those who would like to do things in just one line?
     
  9. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    I disagree.Some user-made functions in JASS doesnt work in other triggers but the trigger itself.That's why i use arguems in the function that can only be used by its own trigger.
     
  10. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    It's just a rawcode parameter/argument, I don't see any normal way that it would not work...

    btw, I just wanna ask why set to 0.0, then 1.0 then 0.0... can't you remove the first 0.0 or the last 0.0?
     
  11. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    its just an emergency backup if a user puts a wrong variable or also if i miss some event variables so i need that backup(learned from Bribe)

    Also,im tired to change my description so just get rid of the arguems
     
  12. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Updated.
    Added a demo
     
  13. BUP

    BUP

    Joined:
    Sep 9, 2012
    Messages:
    149
    Resources:
    8
    Spells:
    8
    Resources:
    8
    Finally a demo.
    When I was trying my spell with this,it didn't work and there wasn't even a DEMO for the testers.
     
  14. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Hehe,sorry for the late update

    Btw,updating demo tomorrow.Please use the SpellIndexerEventLoopIndex in the array(i put the wrong index)
     
    Last edited by a moderator: Mar 30, 2013
  15. BUP

    BUP

    Joined:
    Sep 9, 2012
    Messages:
    149
    Resources:
    8
    Spells:
    8
    Resources:
    8
    That's ok.I'm not making spells today,tomorrow and the day after tomorrow
    and
    My Timer

    • BUP TIMER
      • Events
        • Time - Every 1 day
      • Conditions
        • ((BUP) is alive) Equal to True
      • Actions
        • Set TDAT = TDAT + 1
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • TDAT is greater than TDAT
          • Then - Actions
            • Unit - Make BUP to make more spells
          • Else - Actions
            • Unit - Make BUP to rest
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • TDAT Equal to 30
          • Then - Actions
            • Trigger - Run BUP Revive(ignoring conditions)
          • Else - Actions


    BUP Revive

    • BUP Revive
      • Events
      • Conditions
      • Actions
        • Unit - Make BUP to make more spells

     
  16. shadowvzs

    shadowvzs

    Joined:
    Nov 13, 2006
    Messages:
    1,803
    Resources:
    2
    Spells:
    2
    Resources:
    2
    i dont got the system sense (my bad), it is used for what?
    it is used for make easier trigger spells from regular wc3 spell and make easier the spell damage type setting if somebody use damage indexer?
     
  17. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    It helps dynamic indexing coders.
     
  18. shadowvzs

    shadowvzs

    Joined:
    Nov 13, 2006
    Messages:
    1,803
    Resources:
    2
    Spells:
    2
    Resources:
    2
    but could you explain why somebody want give index to the abilities?
     
  19. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    to make the spell MUI