• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Mui Spell

Status
Not open for further replies.
Level 1
Joined
Sep 19, 2016
Messages
4
Hello there! I'm new here and I'm trying to create a simple MUI spell that I'll use it in some future spells. Before jumps to the question, I'm not sure if this is already or not answered and sorry if I'm creating new thread for no reason. Also, I searched in the web and I'm still in doubt.
So, here is my question: when I use the spell until the second instance, it's ok. But, when I try the third, the loop trigger (see below) tend to don't off and some leaks appears (some special effects aren't destroyed).

  • Can you give me a hand? A tip or link to solve this problem?
  • What do you think about these codes?

If don't mind, please, download my map here http://www.hiveworkshop.com/attachments/spell-pack-by-suomalainen-varis-w3x.248960/ test it and tell me what's going wrong.

The spell code is below:

Loop:

  • Rejuvenation Loop
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Spell_Loop) from 1 to Spell_Index_Max, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Spell_Last_Current[Spell_Loop] Less than or equal to 0.00
            • Then - Actions
              • Special Effect - Destroy Spell_SE[Spell_Loop]
              • Set Spell_Index_Max = (Spell_Index_Max - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Spell_Index_Max Less than or equal to 0
                • Then - Actions
                  • Game - Display to (All players) the text: (((Final) Loop = + ((String(Spell_Loop)) + and Index = )) + (String(Spell_Index)))
                  • Game - Display to (All players) the text: Trigger (Rejuvenati...
                  • Set Spell_Index = 0
                  • Set Spell_Index_Max = 0
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions
              • Set Spell_Last_Current[Spell_Loop] = (Spell_Last_Current[Spell_Loop] - 0.05)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Spell_Heal_Every_Current[Spell_Loop] Greater than or equal to Spell_Heal_Every_Base[Spell_Loop]
                • Then - Actions
                  • -------- --------
                  • Set Spell_Player = (Player group((Owner of Spell_Caster[Spell_Loop])))
                  • Floating Text - Create floating text that reads ((Index = + ((String(Spell_Index)) + , Loop = )) + ((String(Spell_Loop)) + (, Max = + (String(Spell_Index_Max))))) above Spell_Target[Spell_Loop] with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
                  • Floating Text - Hide (Last created floating text) for (All players)
                  • Floating Text - Show (Last created floating text) for Spell_Player
                  • Floating Text - Change (Last created floating text): Disable permanence
                  • Floating Text - Change the lifespan of (Last created floating text) to 1.50 seconds
                  • Floating Text - Change the fading age of (Last created floating text) to 2.00 seconds
                  • Floating Text - Set the velocity of (Last created floating text) to 100.00 towards 90.00 degrees
                  • -------- Destroy/Remove any leak(s): --------
                  • Custom script: call DestroyForce(udg_Spell_Player)
                  • Custom script: set udg_Spell_Player = null
                  • -------- --------
                  • Unit - Set life of Spell_Target[Spell_Loop] to ((Life of Spell_Target[Spell_Loop]) + ((Life of Spell_Target[Spell_Loop]) x Spell_Heal_Amount_Current[Spell_Loop]))
                  • Set Spell_Heal_Every_Current[Spell_Loop] = 0.00
                • Else - Actions
                  • Set Spell_Heal_Every_Current[Spell_Loop] = (Spell_Heal_Every_Current[Spell_Loop] + 0.05)


Cast:


  • Rejuvenation Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Spell_Ability
    • Actions
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Spell_Index Less than or equal to 0
        • Then - Actions
          • Set Spell_Index = 1
          • Set Spell_Index_Max = 1
        • Else - Actions
          • Set Spell_Index = (Spell_Index + 1)
          • Set Spell_Index_Max = (Spell_Index_Max + 1)
      • -------- --------
      • Set Spell_Caster[Spell_Index] = (Triggering unit)
      • Set Spell_Target[Spell_Index] = (Target unit of ability being cast)
      • Set Spell_Level = (Level of Spell_Ability for Spell_Caster[Spell_Index])
      • Set Spell_Heal_Amount_Current[Spell_Index] = Spell_Heal_Amount_Base[Spell_Level]
      • Set Spell_Last_Current[Spell_Index] = Spell_Last_Base[Spell_Index]
      • -------- --------
      • Special Effect - Create a special effect attached to the chest of Spell_Target[Spell_Index] using Abilities\Spells\NightElf\Rejuvenation\RejuvenationTarget.mdl
      • Set Spell_SE[Spell_Index] = (Last created special effect)
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Spell_Index Equal to 1
        • Then - Actions
          • Game - Display to (All players) the text: Trigger (Rejuvenati...
          • Trigger - Turn on Rejuvenation Loop <gen>
        • Else - Actions
          • Game - Display to (All players) the text: Trigger (Rejuvenati...
      • -------- --------


Can you give me a hand, tip or link? Also, what do you think about this code?
Above all, thank you for your time, attention and help.
 
Level 39
Joined
Feb 27, 2007
Messages
5,019
Imo, @pOke, he's not doing anything wrong with his indexing. The only weird thing is how he decides when to deallocate an instance (decrementing heal amount every iteration until its <= 0.00). The problem is this line:
  • Set Spell_Last_Current[Spell_Index] = Spell_Last_Base[Spell_Index]
  • -------- Should be --------
  • Set Spell_Last_Current[Spell_Index] = Spell_Last_Base[Spell_Level]
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Same for "Spell_Heal_Every_Current[Spell_Loop] Greater than or equal to Spell_Heal_Every_Base[Spell_Loop]".

Also, your deindexing is incomplete.
Check the linked thread about dynamic indexing and you will see that you have to swap the one that expired with the last one that is used.
That is why it didnt destroy the effects (nor anything else).

Also, it should be practically impossible to have "Spell_Index Less than 0".
As you only reduce it by one for every instance.

And with proper instance deindexing, you also dont need both Spell_Index and Spell_Index_Max as these become exactly the same.
 
Level 1
Joined
Sep 19, 2016
Messages
4
Thank you so much guys. So, I read the link that poke recommended. I followed the same method with indexing. But there's a problem yet: when I cast the spell for per example, three times, when the first instance ends, the rest ends too. What's going on? Well above is my new code:

Cast:

  • Spell Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Spell_Ability
    • Actions
      • -------- --------
      • Set Spell_Index = (Spell_Index + 1)
      • Set Spell_Index_Counter[Spell_Index] = 0
      • Set Spell_Caster[Spell_Index] = (Triggering unit)
      • Set Spell_Target[Spell_Index] = (Target unit of ability being cast)
      • Set Spell_Level = (Level of Spell_Ability for Spell_Caster[Spell_Index])
      • Set Spell_Last_Current[Spell_Index] = Spell_Last_Base[Spell_Level]
      • -------- --------
      • Special Effect - Create a special effect attached to the origin of Spell_Target[Spell_Index] using Spell_Effect_Name[1]
      • Special Effect - Destroy (Last created special effect)
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Spell_Index Equal to 1
        • Then - Actions
          • Game - Display to (All players) the text: Trigger on
          • Trigger - Turn on Spell Loop <gen>
        • Else - Actions
          • Game - Display to (All players) the text: Trigger already on
      • -------- --------

Loop:

  • Spell Loop
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Spell_Index_Loop) from 1 to Spell_Index, do (Actions)
        • Loop - Actions
          • Set Spell_Level = (Level of Spell_Ability for Spell_Caster[Spell_Index_Loop])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • Spell_Last_Current[Spell_Index_Loop] Less than or equal to 0.00
                  • (Spell_Target[Spell_Index_Loop] is Magic Immune) Equal to True
                  • (Spell_Target[Spell_Index_Loop] is dead) Equal to True
            • Then - Actions
              • -------- --------
              • Set Spell_Caster[Spell_Index_Loop] = Spell_Caster[Spell_Index]
              • Set Spell_Target[Spell_Index_Loop] = Spell_Target[Spell_Index]
              • Set Spell_Index_Counter[Spell_Index_Loop] = Spell_Index_Counter[Spell_Index]
              • Set Spell_Index = (Spell_Index - 1)
              • Set Spell_Index_Loop = (Spell_Index_Loop - 1)
              • -------- --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Spell_Index Equal to 0
                • Then - Actions
                  • Game - Display to (All players) the text: Trigger off
                  • Trigger - Turn off (This trigger)
                • Else - Actions
              • -------- --------
            • Else - Actions
              • -------- --------
              • Set Spell_Last_Current[Spell_Index_Loop] = (Spell_Last_Current[Spell_Index_Loop] - 0.05)
              • -------- --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Spell_Heal_Every_Current[Spell_Index_Loop] Greater than or equal to Spell_Heal_Every_Base[Spell_Level]
                • Then - Actions
                  • -------- --------
                  • Floating Text - Create floating text that reads (String((Integer(Spell_Last_Current[Spell_Index_Loop])))) above Spell_Target[Spell_Index_Loop] with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
                  • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
                  • Floating Text - Change the lifespan of (Last created floating text) to 1.50 seconds
                  • Floating Text - Change the fading age of (Last created floating text) to 1.25 seconds
                  • -------- --------
                  • Special Effect - Create a special effect attached to the chest of Spell_Target[Spell_Index_Loop] using Abilities\Spells\Undead\AbsorbMana\AbsorbManaBirthMissile.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Set Spell_Heal_Final = ((Life of Spell_Target[Spell_Index_Loop]) + ((Life of Spell_Target[Spell_Index_Loop]) x Spell_Heal_Amount_Base[Spell_Level]))
                  • Unit - Set life of Spell_Target[Spell_Index_Loop] to Spell_Heal_Final
                  • Set Spell_Heal_Every_Current[Spell_Index_Loop] = 0.00
                • Else - Actions
                  • Set Spell_Heal_Every_Current[Spell_Index_Loop] = (Spell_Heal_Every_Current[Spell_Index_Loop] + 0.05)
 
Level 39
Joined
Feb 27, 2007
Messages
5,019
I don't see anything that would cause that-- is there anything else that may be turning off the trigger? Try printing variables before/during loops and ifs to see if you can figure out what's going on. Spell_Index must be == 0 if nothing else can disable the trigger, so why isn't it being incremented properly?
 
Level 1
Joined
Sep 19, 2016
Messages
4
Sorry guys for delay. But, I solved the problem: I used as an example, the DynamicIndex from Hanky. Worked out.
Below, the new codes:

Loop:

  • Spell Loop 2
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • For each (Integer Spell2_IndexLoop) from 1 to Spell2_IndexSize, do (Actions)
        • Loop - Actions
          • Set Spell2_IndexTemp = Spell2_Index[Spell2_IndexLoop]
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • Spell2_DurationCurrent[Spell2_IndexTemp] Less than or equal to 0.00
                  • (Spell2_Target[Spell2_IndexTemp] is Magic Immune) Equal to True
                  • (Spell2_Target[Spell2_IndexTemp] is dead) Equal to True
            • Then - Actions
              • -------- --------
              • Special Effect - Destroy Spell2_SpecialEffect[Spell2_IndexTemp]
              • -------- --------
              • Set Spell2_Caster[Spell2_IndexTemp] = No unit
              • Set Spell2_Target[Spell2_IndexTemp] = No unit
              • -------- --------
              • Set Spell2_Index[Spell2_IndexLoop] = Spell2_Index[Spell2_IndexSize]
              • Set Spell2_Index[Spell2_IndexSize] = Spell2_IndexTemp
              • Set Spell2_IndexSize = (Spell2_IndexSize - 1)
              • Set Spell2_IndexLoop = (Spell2_IndexLoop - 1)
              • -------- --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Spell2_IndexSize Equal to 0
                • Then - Actions
                  • Game - Display to (All players) the text: Spell Loop 2 trigge...
                  • Trigger - Turn off (This trigger)
                • Else - Actions
              • -------- --------
            • Else - Actions
              • Set Spell2_Level = (Level of Spell2_Ability for Spell2_Caster[Spell2_IndexTemp])
              • Set Spell2_DurationCurrent[Spell2_IndexTemp] = (Spell2_DurationCurrent[Spell2_IndexTemp] - 0.05)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Spell2_RegenEveryCurrent[Spell2_IndexTemp] Greater than or equal to Spell2_RegenEveryBase[Spell2_Level]
                • Then - Actions
                  • -------- --------
                  • Set Spell2_RegenFinal = ((Mana of Spell2_Target[Spell2_IndexTemp]) + ((Mana of Spell2_Target[Spell2_IndexTemp]) x Spell2_RegenAmountBase[Spell2_Level]))
                  • Unit - Set mana of Spell2_Target[Spell2_IndexTemp] to Spell2_RegenFinal
                  • -------- --------
                  • Floating Text - Create floating text that reads (+ + (((String((Integer(((Mana of Spell2_Target[Spell2_IndexTemp]) x Spell2_RegenAmountBase[Spell2_Level]))))) + , ) + ((String((Integer(Spell2_DurationCurrent[Spell2_IndexTemp])))) + s))) above Spell2_Target[Spell2_IndexTemp] with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
                  • Floating Text - Change (Last created floating text): Disable permanence
                  • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
                  • Floating Text - Change the lifespan of (Last created floating text) to 1.50 seconds
                  • Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds
                  • -------- --------
                  • Set Spell2_RegenFinal = 0.00
                  • Set Spell2_RegenEveryCurrent[Spell2_IndexTemp] = 0.00
                  • -------- --------
                • Else - Actions
                  • Set Spell2_RegenEveryCurrent[Spell2_IndexTemp] = (Spell2_RegenEveryCurrent[Spell2_IndexTemp] + 0.05)

Cast:

  • Spell Cast 2
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Spell2_Ability
    • Actions
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Spell2_IndexSize Equal to 0
        • Then - Actions
          • Trigger - Turn on Spell Loop 2 <gen>
          • Game - Display to (All players) the text: Spell Loop 2 trigge...
        • Else - Actions
          • Game - Display to (All players) the text: Spell Loop 2 trigge...
      • -------- --------
      • Set Spell2_IndexSize = (Spell2_IndexSize + 1)
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Spell2_IndexSize Greater than Spell2_IndexMaxSize
        • Then - Actions
          • Set Spell2_Index[Spell2_IndexSize] = Spell2_IndexSize
          • Set Spell2_IndexMaxSize = Spell2_IndexSize
        • Else - Actions
      • -------- --------
      • Set Spell2_IndexTemp = Spell2_Index[Spell2_IndexSize]
      • -------- --------
      • Set Spell2_Caster[Spell2_IndexTemp] = (Triggering unit)
      • Set Spell2_Target[Spell2_IndexTemp] = (Target unit of ability being cast)
      • Set Spell2_Level = (Level of Spell2_Ability for Spell2_Caster[Spell2_IndexTemp])
      • -------- --------
      • Set Spell2_DurationCurrent[Spell2_IndexTemp] = Spell2_DurationBase[Spell2_Level]
      • -------- --------
      • Special Effect - Create a special effect attached to the origin of Spell2_Target[Spell2_IndexTemp] using Spell2_SpecialEffectModel[1]
      • Set Spell2_SpecialEffect[Spell2_IndexTemp] = (Last created special effect)
      • -------- --------


Thank you all of guys for the help and comments.
 
Status
Not open for further replies.
Top