HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How do I prevent a certain unit from being removed?

04-14-2006, 10:45 AM#1
Eternal_Dread
Trigger:
Remove
Collapse Events
Player - Player 1 (Red) types a chat message containing remove as An exact match
Player - Player 2 (Blue) types a chat message containing remove as An exact match
Player - Player 3 (Teal) types a chat message containing remove as An exact match
Player - Player 4 (Purple) types a chat message containing remove as An exact match
Player - Player 5 (Yellow) types a chat message containing remove as An exact match
Player - Player 6 (Orange) types a chat message containing remove as An exact match
Player - Player 7 (Green) types a chat message containing remove as An exact match
Player - Player 8 (Pink) types a chat message containing remove as An exact match
Player - Player 9 (Gray) types a chat message containing remove as An exact match
Player - Player 10 (Light Blue) types a chat message containing remove as An exact match
Conditions
Collapse Actions
Collapse Unit Group - Pick every unit in (Units currently selected by (Triggering player)) and do (Actions)
Collapse Loop - Actions
Unit - Remove (Picked unit) from the game

How do I prevent that from removing certain units?
04-14-2006, 10:50 AM#2
blu_da_noob
Use a pick every unit in (group) matching (condition) loop and set your condition to exclude units of whatever type. An if/then/else in the loop actions would also work.
04-14-2006, 11:12 AM#3
Eternal_Dread
Quote:
Originally Posted by blu_da_noob
Use a pick every unit in (group) matching (condition) loop and set your condition to exclude units of whatever type. An if/then/else in the loop actions would also work.
That cannot be done with units currently selected.

Problem solved. Nevermind.
04-14-2006, 11:27 AM#4
blu_da_noob
Sorry, I haven't used GUI in ages, so I wasn't aware that you couldn't use a filter for Unit Selected :/
04-14-2006, 11:35 AM#5
Eternal_Dread
Well, this is what I did:
Trigger:
Remove
Collapse Events
Player - Player 1 (Red) types a chat message containing remove as An exact match
Player - Player 2 (Blue) types a chat message containing remove as An exact match
Player - Player 3 (Teal) types a chat message containing remove as An exact match
Player - Player 4 (Purple) types a chat message containing remove as An exact match
Player - Player 5 (Yellow) types a chat message containing remove as An exact match
Player - Player 6 (Orange) types a chat message containing remove as An exact match
Player - Player 7 (Green) types a chat message containing remove as An exact match
Player - Player 8 (Pink) types a chat message containing remove as An exact match
Player - Player 9 (Gray) types a chat message containing remove as An exact match
Player - Player 10 (Light Blue) types a chat message containing remove as An exact match
Conditions
Collapse Actions
Unit Group - Add all units of (Units currently selected by (Triggering player)) to selection[(Player number of (Triggering player))]
Collapse Unit Group - Pick every unit in selection[(Player number of (Triggering player))] and do (Actions)
Collapse Loop - Actions
If (Spawner[(Player number of (Triggering player))] Equal to (Picked unit)) then do (Unit Group - Remove Spawner[(Player number of (Triggering player))] from selection[(Player number of (Triggering player))]) else do (Do nothing)
Collapse Unit Group - Pick every unit in selection[(Player number of (Triggering player))] and do (Actions)
Collapse Loop - Actions
Unit - Remove (Picked unit) from the game
And it WORKS! Wewt.
04-14-2006, 11:46 AM#6
blu_da_noob
I thought nested group loops don't work?

You are over complicating it anyway.
Trigger:
Unit Group - Pick every unit in (Units currently selected by (Triggering player)) and do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Picked unit) Not equal to Spawner[(Player number of (Triggering player))]
Collapse Then - Actions
Unit - Remove (Picked unit) from the game
Else - Actions
04-14-2006, 12:05 PM#7
Eternal_Dread
I'm making it so if it is selected, it doesn't remove spawner, and continues removal. It's not an overcomplication.
04-14-2006, 08:26 PM#8
blu_da_noob
So, looping through the group and removing a unit if it's a certain one, then looping through the group again to remove the others is not more process intensive than looping through once and removing units only if they are not a specific one?
04-14-2006, 08:32 PM#9
Vuen
Yeah, your way is very overcomplicated Eternal_Dread. What's more is it won't even work, because you're looping through the unit group again in every iteration of the original loop. It will only check the first item to see if it's a spawner, and then it will remove everything; it'll then drop out of both loops, since the group is now empty. If the spawner's not the first item, it will get removed.

It would work if you move the second loop out, but it's still very inefficient. Iterating unit groups are a very intensive process, which should really be avoided when unneccessary.

Just do it blu's way.
04-14-2006, 09:17 PM#10
Earth-Fury
Collapse JASS:
function checkUnit takes unit U returns boolean
    return GetUnitTypeId(U) != 'e000' and GetOwningPlayer(U) == GetTriggerPlayer()
endfunction

Theres my check unit function for the RP map im making. (put it in the non-trigger script thingy part of your map)

Collapse JASS:
function Trig_remove_Func002A takes nothing returns nothing
    if ( checkUnit( GetEnumUnit() ) ) then
        call RemoveUnit( GetEnumUnit() )
    endif
endfunction

function Trig_remove_Actions takes nothing returns nothing
    local group tempGroup = GetUnitsSelectedAll(GetTriggerPlayer())
    call ForGroupBJ( tempGroup, function Trig_remove_Func002A )
    call DestroyGroup( tempGroup ) 
endfunction

//===========================================================================
function InitTrig_remove takes nothing returns nothing
    set gg_trg_remove = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_remove, Player(0), "remove", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_remove, Player(1), "remove", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_remove, Player(2), "remove", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_remove, Player(3), "remove", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_remove, Player(4), "remove", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_remove, Player(5), "remove", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_remove, Player(6), "remove", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_remove, Player(7), "remove", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_remove, Player(8), "remove", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_remove, Player(9), "remove", true )
    call TriggerAddAction( gg_trg_remove, function Trig_remove_Actions )
endfunction

and the remove trigger.

I have a bunch of RP Triggers you welcome to, they are leak free and jass. Or you could just help me on my RP map =)
04-14-2006, 09:26 PM#11
Vuen
It's pointless to check whether the owner of the unit is the triggering player, because when you use GetUnitsSelectedAll, it only returns those units which are owned in the first place. It won't even return selected units of players who have given shared control.

I know this because in my D&D, I wanted the DM to be able to use 'kill' and 'remove' commands on hero-owned or shared-control units, but it doesnt work. I had to get the unit group of every unit on the map, and check each one to see if it's selected by the player.


And personally, I find it much simpler to lump all commands into one single trigger. Just have the trigger fire on "contains <empty string>", and then check if the string is each one of your commands. That way you don't need to have all these events and triggers for every single command; adding new commands takes seconds with very little overhead. I can send you my D&D map if you want to see how it works.
04-14-2006, 09:50 PM#12
Earth-Fury
Quote:
Originally Posted by Vuen
It's pointless to check whether the owner of the unit is the triggering player, because when you use GetUnitsSelectedAll, it only returns those units which are owned in the first place. It won't even return selected units of players who have given shared control.

I know this because in my D&D, I wanted the DM to be able to use 'kill' and 'remove' commands on hero-owned or shared-control units, but it doesnt work. I had to get the unit group of every unit on the map, and check each one to see if it's selected by the player.


And personally, I find it much simpler to lump all commands into one single trigger. Just have the trigger fire on "contains <empty string>", and then check if the string is each one of your commands. That way you don't need to have all these events and triggers for every single command; adding new commands takes seconds with very little overhead. I can send you my D&D map if you want to see how it works.

But then, every message sent is presumed to be a command. This produces overhead when not typing commands. =) and overhead of checkign every string for every command. I think there is less overhead in making new triggers ^^
04-14-2006, 09:56 PM#13
Vuen
Quote:
Originally Posted by Earth-Fury
But then, every message sent is presumed to be a command. This produces overhead when not typing commands. =) and overhead of checkign every string for every command. I think there is less overhead in making new triggers ^^

Lol... Every string is checked for every command anyway. If you register a player chat message matching "remove", obviously it's going to check every message entered for "remove"! So you've got exactly the same overhead too.

So if you have 40 commands, you've got 40 triggers all separately checking every single chat message entered for their respecting commands. Much more overhead than a single trigger doing it all at once.
04-14-2006, 10:13 PM#14
Earth-Fury
Quote:
Originally Posted by Vuen
Lol... Every string is checked for every command anyway. If you register a player chat message matching "remove", obviously it's going to check every message entered for "remove"! So you've got exactly the same overhead too.

So if you have 40 commands, you've got 40 triggers all separately checking every single chat message entered for their respecting commands. Much more overhead than a single trigger doing it all at once.

Ah, but wouldnt the WC3 engine be optamised to deal with the string events, as opposed to using the scripting language built ON the engine to do it?! =)
04-14-2006, 11:42 PM#15
Vuen
Possibly, but I'd consider the overhead of 40 triggers with 12 events each being handled separately for every chat message as outweighing that of having to do the checking myself.

In any case, I hide player chat messages and only game-message (as OOC) those that aren't commands. This means I have to amalgamate them all in one trigger anyway, so that I can tell when a message isn't a command. I prefer it this way.