• 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.

How to make condition if at least 2 units are in region then they teleport

Status
Not open for further replies.
Level 12
Joined
Jul 17, 2013
Messages
544
  • zasadzka jak idziesz do boromira Copy 2
    • Events
      • Unit - A unit enters do bora <gen>
    • Conditions
      • (Number of units in (Units in do bora <gen> matching (((Matching unit) is A Hero) Equal to True))) Equal to 2
    • Actions
      • Unit - Move Aragorn 0001 <gen> instantly to (Center of niezabijajbora2 <gen>)
      • Unit - Move Gimli 0005 <gen> instantly to (Center of niezabijajbora2 <gen>)
      • Unit - Move Legolas 0004 <gen> instantly to (Center of niezabijajbora2 <gen>)
      • Unit - Hide Circle of Power amon hen 1863 <gen>
      • Floating Text - Destroy tekst2
      • Trigger - Turn off (This trigger)
  • here!
Ok so i have a problem i have three heroes i want them to teleport futher if at least two of them enters region. i did something like this as u can see but it doesnt work why? frist hero is alreday in region then second hero enters region but game doesnt count him as a hero who is alreday in that region so trigger doesnt run. only when something else enters region too while two herores are in region it works but thats not the point and what i want :( any other idea how to do this ? changing event of trigger to every 1 sec of game would be also helpfull cuz it would check every 1 sec but it will create a bit lag and my game is alreday laggy



if u didnt understant my english which is up the problem with this trigger is that it only runs when a other unit enters region while two heroes are in or third hero enters region then it runs. but it want to be so that it will run when at least 2 heroers are in region/ or are entering that region
 
You said yourself that it works when the third unit entes the region, so change it to "Equal to 1" and it should work on the second unit.

In general, all triggers are executed before the actual event that triggers it happens. For example, if you create a trigger that fires whenever a unit takes damage, the code of that trigger is executed before the damage is applied to that unit. Similarly, I think the code in your trigger is executed before the unit is actually inside the region.

If your game is laggy, it might be because you have Memory Leaks. Your trigger leaks a Unit Group every time a unit enters the region. Read more about Memory Leaks here.
 
Level 4
Joined
Jul 29, 2011
Messages
44
I remember testing something like this before and I believe that this trigger will work correctly only for 2 out of 4 edges of the region; waiting for 0.1 seconds before counting the units will work unless the entering unit stops exactly on one of the bad edges (which is really hard to do and probably will never happen)
A cleaner solution to this problem is having two regions, one slightly bigger than the other; event = entering the smaller region, count units in the larger one
And I second that you should learn about memory leaks - they are very often the primary cause of lags and you're not dealing with them in the trigger you showed.
 
At the event the unit should be already inside region, but the problem is probably really that the check is being wrong.

Here's the explanation: [General] - game does not realise when region contains unit

One fix here would be to check if "All Units Inside Region" are exactly 1 and are NOT currently (Triggering Unit) -> then this would mean one other unit is already inside + TriggeringUnit() has already entered, so it is two:

  • Custom script: set bj_wantDestroyGroup = true
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Number of units in (Units in YOUR_REGION <gen> matching ((Triggering unit) Not equal to (Picked unit)))) Equal to 1
    • Then - Actions
    • Else - Actions
 
Last edited:
Level 12
Joined
Jul 17, 2013
Messages
544
At the event the unit should be already inside region, but the problem is probably really that the check is being wrong.

Here's the explanation: [General] - game does not realise when region contains unit

One fix here would be to check if "All Units Inside Region" are exactly 1 and are NOT currently (Triggering Unit) -> then this would mean one other unit is already inside + TriggeringUnit() has already entered, so it is two:

  • Custom script: set bj_wantDestroyGroup = true
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Number of units in (Units in YOUR_REGION <gen> matching ((Triggering unit) Not equal to (Picked unit)))) Equal to 1
    • Then - Actions
    • Else - Actions
ty for help but i think i will use idea of adrash making small region inside my big region which are units meant to go in is great idea, i think its fine? cuz checking like this aint a problem and it works ok lol sometimes a bit iq is required xd i didnt think of it eralier
I remember testing something like this before and I believe that this trigger will work correctly only for 2 out of 4 edges of the region; waiting for 0.1 seconds before counting the units will work unless the entering unit stops exactly on one of the bad edges (which is really hard to do and probably will never happen)
A cleaner solution to this problem is having two regions, one slightly bigger than the other; event = entering the smaller region, count units in the larger one
And I second that you should learn about memory leaks - they are very often the primary cause of lags and you're not dealing with them in the trigger you showed.
i made small region inside of my region where i want my units to be in is that what u mean right? it works fine anyway
 
Status
Not open for further replies.
Top