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

[Solved] Reducing the number of units that can be selected

Status
Not open for further replies.
Level 9
Joined
Jun 22, 2012
Messages
472
Hey there!

For my new map I would like to put the limit of selection to 6 units instead of 12. I don't know if it is possible, I didn't find anything on the internet...

Any idea?

Thanks in advance!
 
Level 10
Joined
Dec 15, 2012
Messages
650
Unit Group can pick units that currently selected by players so use it :D
Example :
  • Trigger exp
    • Events
      • Player - Player 1 (Red) Selects a unit
      • Player - Player 2 (Blue) Selects a unit
      • Player - Player 3 (Teal) Selects a unit
      • Player - Player 4 (Purple) Selects a unit
      • Player - Player 5 (Yellow) Selects a unit
      • Player - Player 6 (Orange) Selects a unit
      • Player - Player 7 (Green) Selects a unit
      • Player - Player 8 (Pink) Selects a unit
      • Player - Player 9 (Gray) Selects a unit
      • Player - Player 10 (Light Blue) Selects a unit
      • Player - Player 11 (Dark Green) Selects a unit
      • Player - Player 12 (Brown) Selects a unit
    • Conditions
      • (Number of units in (Units currently selected by (Triggering player))) Greater than 6
    • Actions
      • Set Unit_Picked = (Number of units in (Units currently selected by (Triggering player)))
      • For each (Integer Integer_Loop) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set Unit_Picked = (Unit_Picked - 1)
          • Selection - Remove (Random unit from (Random 1 units from (Units currently selected by (Triggering player)))) from selection for (Triggering player)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Unit_Picked Equal to 6
            • Then - Actions
              • Set Integer_Loop = 6
            • Else - Actions
 
Last edited:
Level 9
Joined
Jun 22, 2012
Messages
472
I understood the way it should work but :

The condition doesn't seem to work, it's strange... I tryed to remove it and put later like this :
  • Actions
    • Set Unit_picked = (Number of units in (Units currently selected by (Triggering player)))
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Unit_picked greater 6
      • Then - Actions
        • For each (Integer Int_loop) from 1 to 6, do (Actions)
          • Loop - Actions
            • Set Unit_picked = (Unit_picked - 1)
            • Selection - Remove (Random unit from (Random 1 units from (Units currently selected by (Triggering player)))) from selection for (Triggering player)
            • If (Unit_picked equal 6) then do (Set Int_loop = 6) else do (Do nothing)
      • Sinon - Actions
        • Do nothing
But here is a problem : there are Unit_picked different loops because when we do "Set Unit_picked = number units", it is done for each unit selected... This problem is logical but without the condition at the right place like on your example, I don't see any solution...

Help ^^?
 
Level 6
Joined
Feb 5, 2012
Messages
1,685
Ok i will try..

Your event is correct and using a unit group is correct..

Now your only problem is to make the unit group to have at 6 members only..

So one of the possibilities is..

If the number of units in UNIT GROUP X is equal to 7

Then

Unit remove 1 random unit from the group

Else

If the number of units in UNIT GROUP X is equal to 8

Then

Unit remove 1 random unit from the group
Unit remove 1 random unit from the group

Else

If the number of units in UNIT GROUP X is equal to 9

Then

Unit remove 1 random unit from the group
Unit remove 1 random unit from the group
Unit remove 1 random unit from the group

Else

If the number of units in UNIT GROUP X is equal to 10

Then

Unit remove 1 random unit from the group
Unit remove 1 random unit from the group
Unit remove 1 random unit from the group
Unit remove 1 random unit from the group

You know the pattern dude.. 6 - 7 = remove 1 /6-8 remove 2 /6-9 remove 3

Its really rude and unfriendly but it will work.. if still don't add a wait 0.02 seconds on each remove action..
 
Level 9
Joined
Jun 22, 2012
Messages
472
Ok fine, but I think there is a problem with the event :

When I display the number of units selected, the number appears for each unit selected! For example : if I select 7 units, the number "7" will display 7 times, and so that means that the trigger will trigger 7 times... It is quite annoying ^^...
 
Level 37
Joined
Mar 6, 2006
Messages
9,243

  • Limit Selection Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Max number of selectable units --------
      • Set LS_MAX = 6
      • -------- ========================== --------
      • Hashtable - Create a hashtable
      • Set LS_HT = (Last created hashtable)
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Custom script: if udg_LS_TMR[bj_forLoopAIndex] == null then
          • Custom script: set udg_LS_TMR[bj_forLoopAIndex] = CreateTimer()
          • Custom script: endif
          • Custom script: set udg_I = GetHandleId(udg_LS_TMR[bj_forLoopAIndex])
          • Hashtable - Save Handle Of(Player((Integer A))) as 0 of I in LS_HT
          • Trigger - Add to Limit Selection Limit <gen> the event (Time - LS_TMR[(Integer A)] expires)
          • Trigger - Add to Limit Selection Select <gen> the event (Player - (Player((Integer A))) Selects a unit)
  • Limit Selection Select
    • Events
    • Conditions
    • Actions
      • Set I = (Player number of (Triggering player))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (0 is stored as a Boolean of I in LS_HT) Equal to False
        • Then - Actions
          • Hashtable - Save True as 0 of I in LS_HT
          • Countdown Timer - Start LS_TMR[I] as a One-shot timer that will expire in 0.00 seconds
        • Else - Actions
  • Limit Selection Limit
    • Events
    • Conditions
    • Actions
      • Custom script: set udg_PLR = LoadPlayerHandle(udg_LS_HT, GetHandleId(GetExpiredTimer()), 0)
      • -------- ============================== --------
      • Custom script: set udg_I = 0
      • Custom script: call SyncSelections()
      • Custom script: call GroupEnumUnitsSelected(udg_GRP, udg_PLR, null)
      • Custom script: loop
      • Custom script: set udg_U = FirstOfGroup(udg_GRP)
      • Custom script: exitwhen udg_U == null
      • Custom script: if udg_I >= udg_LS_MAX then
      • Custom script: call SelectUnitRemoveForPlayer(udg_U, udg_PLR)
      • Custom script: endif
      • Custom script: set udg_I = udg_I + 1
      • Custom script: call GroupRemoveUnit(udg_GRP, udg_U)
      • Custom script: endloop
      • -------- ============================== --------
      • Custom script: set udg_I = GetConvertedPlayerId(udg_PLR)
      • Custom script: call RemoveSavedBoolean(udg_LS_HT, udg_I, 0)
 

Attachments

  • LimitSelection.w3x
    14.7 KB · Views: 47
Level 9
Joined
Jun 22, 2012
Messages
472
Thanks for your answers!

Maker, I face a problem when I import your trigger, a script error appears even if the script works well in your file... A variable name was expected...

EDIT : everything works fine! All the variables weren't copied... Thanks to all, +rep!
 

Attachments

  • Script error.PNG
    Script error.PNG
    29.4 KB · Views: 137
Last edited:
Status
Not open for further replies.
Top