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

Remove/kill everything in a region but keep one unit

Status
Not open for further replies.
Level 2
Joined
Jun 19, 2016
Messages
26
Hello guys !

I got a little problem, i do a units defense but after the wave i want to remove every units ( building and units ) in the region but keep the worker who is in the region

So i ask you to help me with this, i didnt find a way to do this, i was thinking but every units and building in a variable group and kill the variable group but i dont know if it's work.

Thank you for help me with this, and i have heard about memory leak that cause lag if we dont delete them , so i ask you help for this too, thanks !
 
Level 6
Joined
Apr 5, 2015
Messages
166
I would have done it with a unitgroup too, even tho there probably are better ways to do it.

  • Actions
    • Unit Group - Pick every unit in (Units in YourRegion <gen>) and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Unit-type of (Picked unit)) Not equal to YourBuilder
          • Then - Actions
            • Unit - Kill (Picked unit)
          • Else - Actions
And if you want to learn how to remove leaks you should read this.

Edit: I'm not sure myself tho if this unitgroup would be leaking or not.
 
Last edited:
Level 12
Joined
May 22, 2015
Messages
1,051
I would have done it with a unitgroup too, even tho there probably are better ways to do it.

  • Actions
    • Unit Group - Pick every unit in (Units in YourRegion <gen>) and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Unit-type of (Picked unit)) Not equal to YourBuilder
          • Then - Actions
            • Unit - Kill (Picked unit)
          • Else - Actions
And if you want to learn how to remove leaks you should read this.

Edit: I'm not sure myself tho if this unitgroup would be leaking or not.
It will leak. When you do the (Units in <region>) part, it is creating a new unit group.
 
Level 4
Joined
Sep 13, 2014
Messages
106
Use

  • Custom script: set bj_wantDestroyGroup = true
Before executing the pick every unit in unit group. You have to do this each time you want to create a unit group inside a pick every unit in unit group function (or alternatively stop leaks in the standard way).
 
Level 2
Joined
Jun 19, 2016
Messages
26
Sorry to not reply first, i have find a way to do it, thanks, and i will check the memory leak too !
 
Level 4
Joined
Sep 13, 2014
Messages
106
Only set bj_wantDestroyGroup = true before each for loop which has a unit group created implicitly within it. It will cause the for loop to destroy the group it operates upon. If you have a variable holding the value of the group, or the GUI actually converts to a variable defined by blizzard.j (such as bj_lastCreatedGroup), you probably do not want to destroy the group. Since you create your unit group once at map initialization, and you are not implicitly creating it in the for loop, you probably do not want to destroy it.

This is the JASS called by the GUI for unit group function

JASS:
function ForGroupBJ takes group whichGroup, code callback returns nothing
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    call ForGroup(whichGroup, callback)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(whichGroup)
    endif
endfunction



This, for example, is the reason you might want to set bj_wantDestroyGroup = true:

  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
    • Loop - Actions
This converts to the JASS:

JASS:
    set bj_wantDestroyGroup = true
    call ForGroupBJ( GetUnitsInRectAll(GetPlayableMapRect()), function Trig_Melee_Initialization_Func002A )

Which is equivalent to:

JASS:
    set bj_wantDestroyGroup = true
    call ForGroupBJ( GetUnitsInRectMatching(GetPlayableMapRect(), null), function Trig_Melee_Initialization_Func002A )

Which is equivalent to:

JASS:
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, GetPlayableMapRect(), null)
    set bj_wantDestroyGroup = true
    call DestroyBoolExpr(null)
    call ForGroupBJ( g, function Trig_Melee_Initialization_Func002A )

As you can see, it has implicitly got a CreateGroup() in there, even if it does not look like it to begin with. And if you keep creating groups, the game starts to lag. So you use bj_wantDestroyGroup to avoid playing around with variables.

 
Last edited by a moderator:
Level 2
Joined
Jun 19, 2016
Messages
26
Hmmm, i dont really understand, but, i use the same variable for 4 wave, ( named unitsred ) but with your custom script, it will destroy the group so i can send them ? ( i use a loop on the bandit screen but i have 4 units, so i use 4 loop, so i dont know what will happen ), i'm really bad with custom script and i dont understand what u put in your message, sorry and thanks for helping me
 
Level 4
Joined
Sep 13, 2014
Messages
106
Looking at your code it looks like you probably don't want to destroy the unit group.

To be clear, destroying a unit group will not destroy the units in the unit group but it will rather destroy the place in memory that remembers that certain units are in this unit group.

If you want the unit group to be remembered afterwards, don't destroy it.

If you don't necessarily want the unit group to be remembered afterwards but you do want the unit group to exist afterwards, you may or may not want to destroy it and create it again.

If you only created it to be used once in a single pick each unit loop, you should destroy it.


I don't really understand how your specific implementation works.
 
Level 2
Joined
Jun 19, 2016
Messages
26
Well, i'm not native english so..


Well i think i understand, see the screen of the wave, i think i might not destroy it, but if u still want to help, i give u some screen for help me with memory leak, if i understand wrong about Destroygroup, help me again, thank you !

here some screen :

the wave 3, with many troops now :

http://www.noelshack.com/2016-27-1467882607-spawn-wave-3-declencheur.png

how the wave end is check :

http://www.noelshack.com/2016-27-1467882609-wave-end-check-declencheur.png

Now i have some trigger that remove every units and building for a player, but i'm sure this will leak hard cause its big and i'm doing it every wave (4 time, and when player lose )

here how he start

http://www.noelshack.com/2016-27-1467882601-unit-remove-declencheur-trigger.png

and now how it work

http://www.noelshack.com/2016-27-1467882605-unit-remove-declencheur.png

please dont die when u see it.

Thanks for help i'm really new to memory leak and i want my map to be good, Thank you !

PS : I don't know how to get the screen directly so i'm using this for screen, sorry !
 
Last edited:
Level 4
Joined
Sep 13, 2014
Messages
106
Basically, in the wave 3 triggers, everything is being done in a single unit group pointed to by a single variable, so it will not leak, and you do not need to delete the unit group.

In the delete triggers, all of the actions have implicitly created unit groups in them except for the one at the very end. "BlueUnits", the group operated upon by the very last action only has units added to it, and is never set to store the value of a completely different unit group, so you don't want to destroy that one. You need to set bj_wantDestroyGroup = true in front of each of these actions except for the one at the very end.
1467882605-unit-remove-declencheur.png



Also, http://www.hiveworkshop.com/threads/how-to-easily-post-triggers.163285/

Basically wrap

[trigger] Your copied GUI here [/trigger]

tags around your copied GUI trigger if you want to paste GUI triggers.
 
Level 2
Joined
Jun 19, 2016
Messages
26
Sorry but my world editor is in french so it doesnt really work with this forum

Is it good ?

  • unit remove bleu
    • Evénements
    • Conditions
    • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • Si - Conditions
    • (Région construction bleu <gen> contains IvanLinvincible) Egal à True
    • Alors - Actions
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Sorcier novice 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Arcane Sanctum bleu 1) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Ecuyer 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Milicien 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type caserne milicien bleu1) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Tour de garde 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Tour de guet 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Forge 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Scierie 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Caserne chevalier 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Chevalier 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Paysant apeuré barricadé 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Tente capitaine bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Capitaine 2 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Fusilier 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Fusilier 2 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Caserne fusilier 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Caserne fusilier 2 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Caserne fantassin 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Caserne fantassin 2 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Fantassin 1 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Custom script: set bj_wantDestroyGroup = true
    • Groupe unité - Pick every unit in (Units of type Fantassin 2 bleu) and do (Groupe unité - Add (Picked unit) to BlueUnits)
    • Sinon - Actions
    • Wait 0.25 seconds
    • Groupe unité - Pick every unit in BlueUnits and do (Unité - Remove (Picked unit) from the game)

here a screen :

http://www.noelshack.com/2016-27-1467895890-declencheur-remove-bleu-fix.png
 
Level 2
Joined
Jun 19, 2016
Messages
26
Wow thanks man ! i was worries about the lag if i had more player, but now i think i'm ok, i have a little problem, it's about timer, like u see for my wave end check it wait that all creep in the wave are dead , and it start the wave after a specific time ( ex 150 sec ), but it's not the same for every player ( player 1 could finish before player 2 and start the second wave before him, and i'm not good with timer, so i don't know if a timer could be use here, it could be good if it could be ! i have use the research fonction and didn't find something appropriated, sorry for my basically english and if u cant understand i'll remake my words.

Thank you again !

And before u answer of this, should i create a now post for the timer, so many people could he me more fast ? cause i don't think sme people that are good with timer will come here.

Thanks again !
 
Level 15
Joined
Sep 6, 2015
Messages
576
Hello guys !

I got a little problem, i do a units defense but after the wave i want to remove every units ( building and units ) in the region but keep the worker who is in the region

So i ask you to help me with this, i didnt find a way to do this, i was thinking but every units and building in a variable group and kill the variable group but i dont know if it's work.

Thank you for help me with this, and i have heard about memory leak that cause lag if we dont delete them , so i ask you help for this too, thanks !
I haven't read all the replies, but there is a very simple solution to this:
mY2C6wQ.png


  • Untitled Trigger 001
    • Events
    • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
    • Unit - Hide Peasant 0010 <gen>
    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Units in Region 000 <gen>) and do (Unit - Kill (Picked unit))
    • Unit - Unhide Peasant 0010 <gen>
"Unit - Hide" hides the unit from the trigger selection, and the peasant surveves, while everything else in the region dies.
 
Last edited:
Level 4
Joined
Sep 13, 2014
Messages
106
I think you could just check if all the units in the wave for player 1 were dead AND all the units in the wave for player 2 were dead AND all the units in the wave for player 3 were dead... etc.

Alternatively, you could check if all the units in the wave for player 1 were dead OR all the units in the wave for player 2 were dead OR all the units in the wave for player 3 were dead... etc.

Alternatively, you could use timers, I guess, so that each wave starts at a specific time, or something. To do this, first create a timer variable in the variable editor.

Use the event

  • Time - t expires
To detect when you want to start each wave. After each wave begins, use this action:

  • Countdown Timer - Start t as a One-shot timer that will expire in However_many seconds
Or alternatively, use this action once at the start of the first wave.

  • Countdown Timer - Start t as a Repeating timer that will expire in However_many seconds
Make sure each trigger that uses the event

  • Time - t expires
is initially turned off, and use the actions

  • Trigger - Turn off (This trigger)
  • Trigger - Turn on Next wave trigger <gen>
To turn on the trigger for the next wave.

I don't know about creating a new post... I think it is better to keep the forum less cluttered, because then it is easier for others to find the information they want.
 
Last edited:
Level 2
Joined
Jun 19, 2016
Messages
26
Well, i got a problem with some rifleman, i used them like in a "protect the guy", if he die, u lose, so i want him to cant be able too move, but i want him to shoot, it's already done, but he doesnt rotate, so he shoot facing the wall and hitting behind him, it's really weird, and if i change the rotation it's the same, he don't adjust himself, he just shoot cuz he had the range.

I want him to rotate on himself, so i ask if i can do it in unit editor or i need to go with trigger (i think it's not trigger )

Thanks for future answering
 
Level 2
Joined
Jun 19, 2016
Messages
26
Thanks man !

Now i got another little problem, i wanted player to change color in-game ( because team are already done ( red and blue as user are ally with dg ( as computer) vs brown as computer, so i lock team, but i wanted to make change color, but when i do, it fuck up the map literally ( the map stop working, timer stop destroying,synchronise on other, building doesnt disapear, or it do on another player.. So the map don't work when they change their color, so i ask if there is a way to make them change color with player force lock and that doesnt fuck up the map
 
Status
Not open for further replies.
Top