• 🏆 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!

[Spell] bear trap ability

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,534
Use an existing trap like goblin landmines and modify it so that when the trap goes off (dies) you create a Dummy unit and order it to cast Ensnare on a random (or closest) nearby enemy unit. Also, remove the damage from it's explosion.

Related posts: Explosive Trap Ability
Some info regarding dummy spell casting (see my comments): Dummy Casting Problem
How to get the closest unit: [General] - Nearest Unit
 
Last edited:
Level 7
Joined
Sep 19, 2020
Messages
190
Use an existing trap like goblin landmines and modify it so that when the trap goes off (dies)
I don't want this, I make trigger but is now work good
  • Bear Trap Loop
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • For each (Integer BearTrap_LoopIndex) from 1 to BearTrap_Index, do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in (Units within 50.00 of (Position of BearTrap_Trap[BearTrap_LoopIndex]) matching (((Matching unit) belongs to an enemy of (Owner of BearTrap_Caster)) Equal to True)) and do (Actions)
            • Loop - Actions
              • Game - Display to (All players) the text: 1
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • BearTrap_Traped[BearTrap_LoopIndex] Equal to False
                • Then - Actions
                  • Set BearTrap_Traped[BearTrap_LoopIndex] = True
                  • Set BearTrap_Target[BearTrap_LoopIndex] = (Random unit from (Units within 50.00 of (Position of BearTrap_Trap[BearTrap_LoopIndex]) matching (((Matching unit) belongs to an enemy of (Owner of BearTrap_Caster)) Equal to True)))
                  • Unit - Remove BearTrap_Dummy[BearTrap_LoopIndex] from the game
                  • Unit - Create 1 Dummy for (Owner of BearTrap_Caster) at (Position of BearTrap_Trap[BearTrap_LoopIndex]) facing Default building facing degrees
                  • Set BearTrap_Dummy[BearTrap_LoopIndex] = (Last created unit)
                  • Unit - Add a 2.00 second Generic expiration timer to BearTrap_Dummy[BearTrap_LoopIndex]
                  • Unit - Add Trap to BearTrap_Dummy[BearTrap_LoopIndex]
                  • Unit - Order BearTrap_Dummy[BearTrap_LoopIndex] to Orc Raider - Ensnare BearTrap_Target[BearTrap_LoopIndex]
                  • Animation - Play BearTrap_Trap[BearTrap_LoopIndex]'s spell animation
                  • Unit - Remove Ghost from BearTrap_Trap[BearTrap_LoopIndex]
                • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (BearTrap_Trap[BearTrap_LoopIndex] is dead) Equal to True
            • Then - Actions
              • Unit - Remove Bear Trap (Air) buff from BearTrap_Target[BearTrap_LoopIndex]
              • Unit - Remove Bear Trap (Ground) buff from BearTrap_Target[BearTrap_LoopIndex]
              • Set BearTrap_Dummy[BearTrap_LoopIndex] = BearTrap_Dummy[BearTrap_Index]
              • Set BearTrap_Target[BearTrap_LoopIndex] = BearTrap_Target[BearTrap_Index]
              • Set BearTrap_Trap[BearTrap_LoopIndex] = BearTrap_Trap[BearTrap_Index]
              • Set BearTrap_Traped[BearTrap_LoopIndex] = BearTrap_Traped[BearTrap_Index]
              • Set BearTrap_Traped[BearTrap_LoopIndex] = BearTrap_Traped[BearTrap_Index]
              • Set BearTrap_Index = (BearTrap_Index - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • BearTrap_Index Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions
it's work for one, when i drop 2 trap it is not work. pls help me to fix it
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,534
1) You're doing this twice for no reason:
  • Set BearTrap_Traped[BearTrap_LoopIndex] = BearTrap_Traped[BearTrap_Index]

2) You don't need to keep track of the Dummy or "de-index" it when the Trap dies. If anything just use a non-array variable for the Dummy like:
  • Unit - Create 1 Dummy for (Owner of BearTrap_Caster) at (Position of BearTrap_Trap[BearTrap_LoopIndex]) facing Default building facing degrees
  • Set BearTrap_Dummy = (Last created unit)

3) For debugging you should display the BearTrap_LoopIndex instead:
  • Game - Display to (All players) the text: Integer(BearTrap_LoopIndex)

4) You're leaking Points/Unit Groups throughout the trigger.

5) You may not be Indexing it properly in your other trigger. You should post that one too.

6) Your Matching condition doesn't take a lot of important things into consideration:
  • Set BearTrap_Target[BearTrap_LoopIndex] = (Random unit from (Units within 50.00 of (Position of BearTrap_Trap[BearTrap_LoopIndex]) matching (((Matching unit) belongs to an enemy of (Owner of BearTrap_Caster)) Equal to True)))
Dead units, Structures, Invulnerable, etc... These should all be filtered out as possible targets.

Also, how does the spell work exactly? Can the Bear Trap be attacked and killed? Is the idea that the enemy can break out of the trap early if they destroy it?
 
Last edited:
Level 7
Joined
Sep 19, 2020
Messages
190
Also, how does the spell work exactly? Can the Bear Trap be attacked and killed? Is the idea that the enemy can break out of the trap early if they destroy it?
bear trap is hide, when enemy is around, he's trapped and trap is show and have 10 HP, trap duration is 0 and enemy is need to destroy trap to be free
5) You may not be Indexing it properly in your other trigger. You should post that one too.
  • Bear Trap Fnish
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
      • (Ability being cast) Equal to Bear Trap
    • Actions
      • Set BearTrap_Index = (BearTrap_Index + 1)
      • Unit - Create 1 Bear Trap for (Owner of BearTrap_Caster) at BearTrap_Point facing Default building facing degrees
      • Set BearTrap_Trap[BearTrap_Index] = (Last created unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • BearTrap_Index Equal to 1
        • Then - Actions
          • Trigger - Turn on Bear Trap Loop <gen>
        • Else - Actions
I only have one bear trap caster, and can cast 10 time
  • BearTrap Cast
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Bear Trap
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • BearTrap_Index Equal to 10
        • Then - Actions
          • Unit - Order (Triggering unit) to Stop
        • Else - Actions
  • Bear Trap Start
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Bear Trap
    • Actions
      • Set BearTrap_Caster = (Triggering unit)
      • Set BearTrap_Point = (Target point of ability being cast)
call destroy location i add soon

pls send me trigger if u can
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,534
Not sure. Could have something to do with the Finishes Casting Event, that can fail sometimes and cause issues. Make sure you do what I said in my previous post with the 6 fixes.

Anyway, here's what I came up with using my own design. It ended up being a bit more complicated than what I originally planned for but it also has a neat feature of allowing multiple traps to stack on a single enemy. Only issue I ran into was that Removing the Ensnare Air/Ground buffs wouldn't work for some reason... but Removing ALL buffs did work, weird.

This uses Bribe's Unit Indexer.
Map requires latest patch 1.32+

I am creating the Bear Trap through the Serpent Ward ability so this is how I detect it:
  • Bear Trap create
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Bear Trap
    • Actions
      • Set VariableSet TrapLimit = (TrapLimit + 1)
      • -------- A slight delay before the trap "arms" (OPTIONAL) --------
      • Wait 2.00 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is alive) Equal to True
        • Then - Actions
          • Unit Group - Add (Triggering unit) to TrapGroup
          • Trigger - Turn on Bear Trap timer <gen>
        • Else - Actions
  • Bear Trap cancel
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Bear Trap
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TrapLimit Equal to 10
        • Then - Actions
          • Unit - Order (Triggering unit) to Stop.
        • Else - Actions
  • Bear Trap timer
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in TrapGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet Trap = (Picked unit)
          • Set VariableSet TrapPoint = (Position of Trap)
          • Set VariableSet TrapEnemyGroup = (Units within 50.00 of TrapPoint.)
          • -------- --------
          • -------- Remove unwanted units from TrapEnemyGroup --------
          • Unit Group - Pick every unit in TrapEnemyGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is alive) Equal to True
                  • ((Picked unit) belongs to an enemy of (Owner of Trap).) Equal to True
                  • ((Picked unit) is invulnerable) Equal to False
                  • ((Picked unit) is A structure) Equal to False
                • Then - Actions
                  • -------- It's a valid target - do nothing --------
                • Else - Actions
                  • Unit Group - Remove (Picked unit) from TrapEnemyGroup.
          • -------- --------
          • -------- Try to get a random nearby enemy target --------
          • Set VariableSet TrapTarget = No unit
          • Set VariableSet TrapTarget = (Random unit from TrapEnemyGroup)
          • -------- --------
          • -------- If a target was found then cast Ensnare --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TrapTarget Not equal to No unit
            • Then - Actions
              • Unit - Remove Ghost from Trap
              • Animation - Play Trap's attack animation
              • Set VariableSet TrapTargetSaved[(Custom value of Trap)] = TrapTarget
              • Set VariableSet TrapTargetCV = (Custom value of TrapTarget)
              • Set VariableSet TrapTargetCount[TrapTargetCV] = (TrapTargetCount[TrapTargetCV] + 1)
              • Trigger - Run Bear Trap fix animation <gen> (ignoring conditions)
              • Unit Group - Remove Trap from TrapGroup.
              • -------- --------
              • Unit - Create 1 Dummy for (Owner of Trap) at TrapPoint facing Default building facing degrees
              • Set VariableSet TrapDummy = (Last created unit)
              • Unit - Add a 1.00 second Generic expiration timer to TrapDummy
              • Unit - Add Ensnare (Bear Trap) to TrapDummy
              • Unit - Order TrapDummy to Orc Raider - Ensnare TrapTarget
            • Else - Actions
          • -------- --------
          • Custom script: call DestroyGroup (udg_TrapEnemyGroup)
          • Custom script: call RemoveLocation (udg_TrapPoint)
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in TrapGroup) Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
This was used to make the Bear Trap remain in it's "clamped" animation instead of disappearing:
  • Bear Trap fix animation
    • Events
    • Conditions
    • Actions
      • Custom script: local unit u = udg_Trap
      • Wait 0.50 seconds
      • -------- Freeze the traps animation --------
      • Custom script: if (IsUnitAliveBJ(u)) then
      • Custom script: call SetUnitTimeScalePercent( u, 0.00 )
      • Custom script: endif
  • Bear Trap trap dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Bear Trap
    • Actions
      • Set VariableSet Trap = (Triggering unit)
      • Set VariableSet TrapLimit = (TrapLimit - 1)
      • Set VariableSet TrapCV = (Custom value of Trap)
      • Animation - Change Trap's animation speed to 100.00% of its original speed
      • Unit Group - Remove Trap from TrapGroup.
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TrapTargetSaved[TrapCV] Not equal to No unit
        • Then - Actions
          • Set VariableSet TrapTarget = TrapTargetSaved[TrapCV]
          • Set VariableSet TrapTargetCV = (Custom value of TrapTarget)
          • -------- --------
          • -------- Reduce the number of Bear Traps the target is affected by (but never below 0) --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TrapTargetCount[TrapTargetCV] Greater than 0
            • Then - Actions
              • Set VariableSet TrapTargetCount[TrapTargetCV] = (TrapTargetCount[TrapTargetCV] - 1)
            • Else - Actions
          • -------- --------
          • -------- If the target isn't affected by any other Bear Traps then set it free --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TrapTargetCount[TrapTargetCV] Equal to 0
            • Then - Actions
              • Unit - Remove All buffs from TrapTarget
            • Else - Actions
          • -------- --------
          • Set VariableSet TrapTargetSaved[TrapCV] = No unit
        • Else - Actions
  • Bear Trap enemy dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • TrapTargetCount[(Custom value of (Triggering unit))] Greater than 0
    • Actions
      • Set VariableSet TrapTargetCount[(Custom value of (Triggering unit))] = 0
 

Attachments

  • Bear Trap.w3m
    33.5 KB · Views: 23
Last edited:
Status
Not open for further replies.
Top