• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Trigger Question - "unit comes within range"

Status
Not open for further replies.
Trigger:

  • Camera Traps
    • Events
      • Unit - A unit comes within 300.00 of Lazer Wall Trap 0005 <gen>
      • Unit - A unit comes within 300.00 of Lazer Wall Trap 0304 <gen>
      • Unit - A unit comes within 300.00 of Lazer Wall Trap 0355 <gen>
      • Unit - A unit comes within 300.00 of Lazer Wall Trap 0348 <gen>
      • Unit - A unit comes within 300.00 of Lazer Wall Trap 0385 <gen>
      • Unit - A unit comes within 300.00 of Lazer Wall Trap 0380 <gen>
      • Unit - A unit comes within 300.00 of Lazer Wall Trap 0381 <gen>
    • Conditions
      • (Player number of (Owner of (Triggering unit))) Less than or equal to 5
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Set p = (Position of (Triggering unit))
      • Special Effect - Create a special effect at p using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
      • Special Effect - Destroy (Last created special effect)
      • Unit - Create 1 (Random level (Hero level of (Triggering unit)) creep unit-type) for Neutral Hostile at p facing (Random angle) degrees
      • Unit - Order (Last created unit) to Attack (Triggering unit)
      • Custom script: call RemoveLocation(udg_p)

Problam: I do not want to summon the new units for "netural hostile" but to the owner of the trap.
"Triggering unit" = the one activating the trap.
" ???? " = the trap which the unit came closer to.
 
use many if conditions. if distance between position of triggering unit and position of trap x less than or equal to 300.

this would be 7 if conditions.

Those are the first 7 in the game which will have 100+, also, its impossible to tell if trigger unit is inside range of 2 traps, resulting in double spawn on the same trap, common is there NO WAY to tell which unit is it using the normal ways?
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,219
well you didnt say there was going to be more traps. another solution in that case is to use a unit group. like pick all units in range of location of triggering unit matching unit is of type trap.
then the trap is picked unit.

sorry if im unclear its hard to write trigger stuff on the phone.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Add all the traps to a Unit Group, then loop.

If distance between TrigUnit and PickedUnit is less than or equal to 300... that Picked Unit will be the trap that triggered the stuff.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
There is no "Triggered Twice". After checking the distance between the target and ALL The traps in the group, just the closer one will trigger. If both have the exact same distance, just one of them will trigger.

Unless you have them exactly one over the other at the exact same x/y spot, you won't have double trigger. If the unit triggers when getting closer to 2 traps, it will trigger that one. If 0.03 seconds later it comes at 300 distance from another one, it's impossible for the unit to be again at shortest distance from another trap.
 
There is no "Triggered Twice". After checking the distance between the target and ALL The traps in the group, just the closer one will trigger. If both have the exact same distance, just one of them will trigger.

Unless you have them exactly one over the other at the exact same x/y spot, you won't have double trigger. If the unit triggers when getting closer to 2 traps, it will trigger that one. If 0.03 seconds later it comes at 300 distance from another one, it's impossible for the unit to be again at shortest distance from another trap.

:goblin_boom: :ogre_rage: :goblin_boom:
This unit blinked into the ranged of between 2 traps, then them both need to be triggered, one is more close then the other and it will be triggered twise due to you suggestion.
^ proven that there is no way.
 
You can pick all mines in range but let only the closest one explode.

However making more traps explode when you're in range of all of them makes more sense.

First of all I want to thank you for answering my question and I want to thank the other readers that tried to help.

But, since my lazer wall does not explode after he depleated:
I decided to give each wall a speical effect that shows that it is active and once activated it cannot be activated for 20 seconds (duration of summoned unit).
1) :goblin_boom::ogre_rage::goblin_boom::goblin_boom:
2) :goblin_boom::ogre_rage:X:goblin_boom:
3) X:ogre_rage:X:goblin_boom:
4) X:ogre_rage:XX
5) wait 20 seconds
6) :goblin_boom::ogre_rage::goblin_boom::goblin_boom: (ogre needs to re enter to active)
 
LOL, I love your usage of the smilies

Without smiles and with triggers it will look like this
  • Camera Traps
    • Events
      • Unit - A unit comes within 300.00 of Camra 0005 <gen>
      • Unit - A unit comes within 300.00 of Camra 0304 <gen>
      • Unit - A unit comes within 300.00 of Camra 0355 <gen>
      • Unit - A unit comes within 300.00 of Camra 0348 <gen>
      • Unit - A unit comes within 300.00 of Camra 0385 <gen>
      • Unit - A unit comes within 300.00 of Camra 0380 <gen>
      • Unit - A unit comes within 300.00 of Camra 0381 <gen>
      • Unit - A unit comes within 300.00 of Camra 0010 <gen>
      • Unit - A unit comes within 300.00 of Camra 0152 <gen>
    • Conditions
      • (Player number of (Owner of (Triggering unit))) Less than or equal to 5
    • Actions
      • Set p = (Position of (Triggering unit))
      • Set ug = (Units within 350.00 of p matching (((Unit-type of (Matching unit)) Equal to Camra) and ((Level of Camera (Neutral Hostile) for (Matching unit)) Equal to 1)))
      • Unit Group - Pick every unit in ug and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Triggering unit) belongs to an enemy of (Owner of (Picked unit))) Equal to True
            • Then - Actions
              • Set unit = (Picked unit)
              • Set p2 = (Position of (Picked unit))
              • Special Effect - Create a special effect at p2 using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
              • Special Effect - Destroy (Last created special effect)
              • Special Effect - Create a special effect at p using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
              • Special Effect - Destroy (Last created special effect)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Triggering unit) is A Hero) Equal to True
                • Then - Actions
                  • Set int = (Hero level of (Triggering unit))
                • Else - Actions
                  • Set int = (Level of (Triggering unit))
              • Unit - Create 1 (Random level int creep unit-type) for (Owner of (Picked unit)) at p facing (Random angle) degrees
              • Unit - Add classification of Summoned to (Last created unit)
              • Unit - Add a 20.00 second Generic expiration timer to (Last created unit)
              • Unit - Order (Last created unit) to Attack (Triggering unit)
              • Unit - Set level of Camera (Neutral Hostile) for (Picked unit) to 2
              • Unit Group - Add (Picked unit) to Cameras
              • Set int = 20
              • Hashtable - Save int as 1 of (Key (Picked unit)) in Hash_Cameras
              • Animation - Change (Picked unit)'s vertex coloring to (0.00%, 0.00%, 0.00%) with 0.00% transparency
              • Set Effect = (Load 2 of (Key (Picked unit)) in Hash_Cameras)
              • Special Effect - Destroy Effect
              • Special Effect - Create a special effect at p2 using Abilities\Spells\Orc\LightningShield\LightningShieldTarget.mdl
              • Set Effect = (Last created special effect)
              • Hashtable - Save Handle OfEffect as 2 of (Key (Picked unit)) in Hash_Cameras
              • Custom script: call RemoveLocation(udg_p2)
              • Trigger - Turn on Camera Traps Cooldown <gen>
            • Else - Actions
      • Custom script: call DestroyGroup(udg_ug)
      • Custom script: call RemoveLocation(udg_p)
  • Camera Traps Cooldown
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Cameras and do (Actions)
        • Loop - Actions
          • Set p = (Position of (Picked unit))
          • Set int = (Load 1 of (Key (Picked unit)) from Hash_Cameras)
          • Floating Text - Create floating text that reads ((String(int)) + seconds to reactive) at p 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 5.00 seconds
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the fading age of (Last created floating text) to 4.00 seconds
          • Custom script: call RemoveLocation(udg_p)
          • Set int = (int - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • int Greater than 0
            • Then - Actions
              • Hashtable - Save int as 1 of (Key (Picked unit)) in Hash_Cameras
            • Else - Actions
              • Set int2 = (Load 2 of (Key (Picked unit)) from Hash_Cameras)
              • Unit Group - Remove (Picked unit) from Cameras
              • Animation - Change (Picked unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 0.00% transparency
              • Unit - Set level of Camera (Neutral Hostile) for (Picked unit) to 1
              • Set Effect = (Load 2 of (Key (Picked unit)) in Hash_Cameras)
              • Special Effect - Destroy Effect
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Cameras is empty) Equal to True
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
Notes:
1) You must check units in 350 area or otherwize the unit will get into 300 area before that the trigger will react as if it is iniside that range, 350 was the only way it worked for me.
2) You must give the self effecting aura "camera (netural hostile)" with 2 levels to make sure that level 1 is active and level 2 in inactive, to allow faster check on the unit group, make sure that the buffs of that skills say "camera active" in case a player summoned it.
^
A unit cast a spell
spell is "camera summon"
add spawned unit to the first trigger

^^
Allows spell to actually go ahead and summon the traps.
 
u should put anything u use twice or more into a variable and use that instead. this will increase efficiency and speed of triggers.
ex: u use triggering unit a lot. store it and use the variable.

doesn't saving a loading a variable cost more power of the computer engeen and take more time than simly use whatever is stored inside the original function "triggered unit" ?

Explain:

GOOD -
Func: X+1 = Y
use X = 2
Func(2)=3

BAD -
FunC: X+1=Y
set TriggeredUnit = Save as W
set X = LOAD W
Func(X)= Func(load X=W)= Func (loaded Triggered unit) = 3

Edit: for those who wonder how such a trap would look like, I attached my game which uses it. Just dont say I don't LOVE you.
 

Attachments

  • Freedom Force v0.23.w3x
    513.3 KB · Views: 64
Level 20
Joined
Jul 14, 2011
Messages
3,213
This unit blinked into the ranged of between 2 traps, then them both need to be triggered, one is more close then the other and it will be triggered twise due to you suggestion.
^ proven that there is no way.

Set LastTriggeredTower[PlayerNumber] = Picked Unit

and add condition
Picked Unit is NOT equal to LastTriggeredTower[PlayerNumber]

So, if the unit enters 2 towers range, the first one will trigger and be set as the Last Triggered Tower. When the seconds tower triggers, the check will skip the first one, since it's the LastTriggeredTower that player approached to.
 
Set LastTriggeredTower[PlayerNumber] = Picked Unit

and add condition
Picked Unit is NOT equal to LastTriggeredTower[PlayerNumber]

So, if the unit enters 2 towers range, the first one will trigger and be set as the Last Triggered Tower. When the seconds tower triggers, the check will skip the first one, since it's the LastTriggeredTower that player approached to.

Allthough your idea is creative and I think that I understood it, instead, I used unit group which allows all nearby traps to go with the same trigger, same interuction, so that the line is randomed, but the line is faster. (30 traps trigger mine just once, but with random order)

Also, allow me to say to those who learn from me, that I forgot to clear all child of hashtable once the trap reactivated, if you want further explain, feel free to ask.
 
Status
Not open for further replies.
Top