• 🏆 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] Remove Units in Region when no player-owned units in Region

Status
Not open for further replies.
Level 2
Joined
Mar 5, 2010
Messages
7
Hey,

Ive been racking my mind over this the last two days so any help would be appreciated.

I'm attempting to create a trigger to remove all units in a region owned by player 12 ((brown)Computer) when there are no units in the region owned by players 1-10 (Users) Ive tried any variation of trigger I can think of so I'm rather stumped. There are several different unit types in the region under Player 12's control so I'm not sure a 'remove unit type' would be appropriate in this situation. I have included the main trigger I have been trying with variations below but for simplicity sake only included units owned by Player 1 in the condition:

Unit Despawn
Events
Unit - A unit leaves Unit Spawn Region <gen>
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units in Unit Spawn Region <gen> owned by Player 1 (Red))) Equal to 0
Then - Actions
Unit Group - Pick every unit in (Units in Unit Spawn Region <gen>) and do (Unit - Remove (Picked unit) from the game)
Else - Actions

Thanks in advance!
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
So what exactly is the problem?
In your example you remove all units. If you only want units removed by player 12 you can do it like in the condition: Units in Spawn owned by player 12

You should however add additional events. If a unit dies "leaves region" is not triggered, so you need an extra event for a unit dies.
Maybe you also want the event "enters region". I don't know what you want to happen if there are no units of player 1-10 in the region and a unit owned by player 12 enters the region.

The triggers how you posted them here leak (Things That Leak).

Code:
you can post your triggers using the trigger tags: [trigger]your trigger[/trigger]
 
Level 2
Joined
Mar 5, 2010
Messages
7
So basically as you say, I have a trigger to spawn units when players enter region, and I want them to despawn again when the player leaves the region to prevent lag however as there could be more then one player in the region, I can't use 'player leaves region' on its own to remove the units, I need some form of condition to ensure there are no other players in the region before despawning the units in the region. I was initially using 'owned by player 12' but have tried many variations of this trigger to get it to work with no luck, this trigger was simply an example of what I was trying to achieve.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
That's the trigger.
If a unit owned by player 12 enters the region and there are no player 1-10 units in the region all units of player 12 in the region will be removed. If you do not want this behaviour, remove the A unit enters Region event.
If a unit dies and there are no player 1-10 units in the region all units of player 12 in the region will be removed. If you do not want this behaviour, remove the A unit Dies event.
  • Trigger
    • Events
      • Unit - A unit leaves Region 000 <gen>
      • Unit - A unit Dies
      • Unit - A unit enters Region 000 <gen>
    • Conditions
    • Actions
      • Set TempGroup = (Units in Region 000 <gen> matching ((((Matching unit) is alive) Equal to True) and ((Player number of (Owner of (Matching unit))) Less than or equal to 10)))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in TempGroup) Equal to 0
        • Then - Actions
          • Custom script: call DestroyGroup(udg_TempGroup)
          • Set TempGroup = (Units in Region 000 <gen> matching ((Owner of (Matching unit)) Equal to Player 12 (Brown)))
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • Unit - Remove (Picked unit) from the game
          • Custom script: call DestroyGroup(udg_TempGroup)
        • Else - Actions
          • Custom script: call DestroyGroup(udg_TempGroup)
 
Level 2
Joined
Mar 5, 2010
Messages
7
Awesome man, thanks! That did the trick! One last question, any chance you know a way to condition a trigger to your IP address or server or something? I want to make a trigger that changes my name e.g and possibly creator commands, but don't want other players on other servers or players on lan games to be able to access them?

  • Khonsu
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
      • (Player 1 (Red) controller) Equal to User
      • (Name of Player 1 (Red)) Equal to Warchieftan
    • Actions
      • Game - Display to (All players) the text: The Tok'ra Khonsu h...
      • Player - Set name of Player 1 (Red) to Khonsu
Thanks!
 
Level 6
Joined
Nov 18, 2016
Messages
75
There is an easier thing can remove every unit when not owned of player.you must first create an event = a unit enters [name of region].second you must create a condition from boolean= owner of entering unit is an enemy of [your target player] and finally create an action that removes entering units=remove entering unit from game
 
Status
Not open for further replies.
Top