• 💀 Happy Halloween! 💀 It's time to vote for the best terrain! Check out the entries to Hive's HD Terrain Contest #2 - Vampire Folklore.❗️Poll closes on November 14, 2023. 🔗Click here to cast your vote!
  • 🏆 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!
  • 🏆 HD Level Design Contest #1 is OPEN! Contestants must create a maze with at least one entry point, and at least one exit point. The map should be made in HD mode, and should not be openable in SD. Only custom models from Hive's HD model and texture sections are allowed. The only exceptions are DNC models and omnilights. This is mainly a visual and design oriented contest, not technical. The UI and video walkthrough rules are there to give everyone an equal shot at victory by standardizing how viewers see the terrain. 🔗Click here to enter!

[Trigger] Spell Problem

Status
Not open for further replies.
Level 16
Joined
Apr 4, 2011
Messages
995
I am working on a spell, called Ten Thousand Butterflies, which creates butterflies when it is cast. Anytime a unit collides with a butterfly, it creates another butterfly, and the unit is healed. My problem is, the newly created unit isn't being added to the unit group properly, so it doesn't fly around and create even MORE copies.

Here are triggers:

  • TTB Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to 10,000 Butterflies
    • Actions
      • Set TTB_Caster = (Triggering unit)
      • Set TTB_Level = (Level of 10,000 Butterflies for TTB_Caster)
      • Set TTB_Timer = (8.00 + (2.00 x (Real(TTB_Level))))
      • Set TTB_Points[1] = (Position of TTB_Caster)
      • Set TTB_Loops = (TTB_Loops + 1)
      • For each (Integer TTB_Integer1) from 1 to 4, do (Actions)
        • Loop - Actions
          • Set TTB_Points[2] = (TTB_Points[1] offset by (Random real number between 100.00 and 250.00) towards TTB_Angle degrees)
          • Unit - Create 1 Butterfly for (Triggering player) at TTB_Points[2] facing Default building facing degrees
          • Set TTB_Butterfly = (Last created unit)
          • Unit - Add a TTB_Timer second Generic expiration timer to TTB_Butterfly
          • Unit - Make TTB_Butterfly Explode on death
          • Unit Group - Add TTB_Butterfly to TTB_ButterflyGroup
          • Special Effect - Create a special effect attached to the chest of TTB_Butterfly using Abilities\Spells\NightElf\FaerieDragonInvis\FaerieDragon_Invis.mdl
          • Hashtable - Save Handle Of(Last created special effect) as 1 of (Key (Last created unit)) in (Last created hashtable)
          • Hashtable - Save TTB_Timer as 2 of (Key (Last created unit)) in TTB_Hash
          • Custom script: call RemoveLocation(udg_TTB_Points[2])
      • Custom script: call RemoveLocation(udg_TTB_Points[1])
  • TTB Loop
    • Events
      • Time - Every 0.20 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in TTB_ButterflyGroup and do (Actions)
        • Loop - Actions
          • Set TTB_Butterfly = (Picked unit)
          • Set TTB_Timer = (Load 2 of (Key (Picked unit)) from TTB_Hash)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TTB_Timer Greater than 0.00
            • Then - Actions
              • Set TTB_Points[1] = (Position of TTB_Butterfly)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Units within 120.00 of TTB_Points[1] matching (((Matching unit) belongs to an ally of (Owner of TTB_Butterfly)) Equal to True)) is empty) Equal to False
                • Then - Actions
                  • Custom script: set bj_wantDestroyGroup = true
                  • Unit Group - Pick every unit in (Units within 120.00 of TTB_Points[1] matching (((Matching unit) belongs to an ally of (Owner of TTB_Butterfly)) Equal to True)) and do (Actions)
                    • Loop - Actions
                      • Unit - Set life of (Picked unit) to ((Life of (Picked unit)) + 5.00)
                  • Unit - Create 1 Butterfly for (Owner of TTB_Butterfly) at TTB_Points[1] facing Default building facing degrees
                  • Unit - Add a TTB_Timer second Generic expiration timer to (Last created unit)
                  • Unit - Make (Last created unit) Explode on death
                  • Unit Group - Add (Last created unit) to TTB_ButterflyGroup
                • Else - Actions
              • Set TTB_Points[2] = (TTB_Points[1] offset by 500.00 towards (Random angle) degrees)
              • Unit - Order TTB_Butterfly to Move To TTB_Points[2]
              • Hashtable - Save (TTB_Timer - 0.20) as 2 of (Key (Picked unit)) in TTB_Hash
            • Else - Actions
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in TTB_Hash
              • Unit Group - Remove TTB_Butterfly from TTB_ButterflyGroup
Hopefully this isn't a stupid mistake o_O Btw the second trigger isn't leak cleared fully, so don't even mention it.
 
Level 13
Joined
Mar 16, 2008
Messages
941
Just a hint: in the first trigger is a "last created hashtable" ;)
How are they even flying around? There is no triggered movement so I bet they got wander? Another thing: This would cause problems if working because you create a unit every 0.2 seconds when another healable unit is near. If this happens, after 0.2 seconds the unit will be still there and healed for two units, creating two new. Then with four, eight, sixteen, and so on.

Your problem is that you don't store TTB_TIMER for the new units what causes them to be insta-removed with the next loop.
 
Status
Not open for further replies.
Top