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

lock selection to unit (unable to deselect)

Status
Not open for further replies.
Level 3
Joined
Jan 7, 2010
Messages
37
I was wondering if there is a way to lock the selection to a single unit, so the player can "left-click" other units while keeping the first unit selected?

I got quite close with 0.03 seconds timer that selects the unit all the time, but it still deselects the unit and I'm also not sure about how this would be in an online multiplayer map.
 
You can do this with a simple trigger:
  • Events:
    • Player 1 selects a unit
    • Player 2 selects a unit
    • ...
    • Player 12 selects a unit
  • Conditions:
    • Selected unit not equal to YourUnit[Player number of (Triggering Player)
  • Actions:
    • Select YourUnit[Player number of (Triggering Player)] for (Triggering Player)
YourUnit is a Unit array variable. You need to set YourUnit[1] to a unit which you want to be permanently selected for Player 1. YourUnit[2] is the unit for Player 2, and so on.

What this trigger does is: whenever a unit is selected, it checks whether it's the unit that should always be selected. If it is not, then it selects the correct unit. Very simple, yet effective.
 
Level 12
Joined
Mar 13, 2012
Messages
1,121
You can do this with a simple trigger:
  • Events:
    • Player 1 selects a unit
    • Player 2 selects a unit
    • ...
    • Player 12 selects a unit
  • Conditions:
    • Selected unit not equal to YourUnit[Player number of (Triggering Player)
  • Actions:
    • Select YourUnit[Player number of (Triggering Player)] for (Triggering Player)
YourUnit is a Unit array variable. You need to set YourUnit[1] to a unit which you want to be permanently selected for Player 1. YourUnit[2] is the unit for Player 2, and so on.

What this trigger does is: whenever a unit is selected, it checks whether it's the unit that should always be selected. If it is not, then it selects the correct unit. Very simple, yet effective.

That trigger does not solve his problem and can break the game.

Try this:

JASS:
    if (GetLocalPlayer() == Player(0))then
        call EnableSelect( false, true )
    endif
    call SelectUnitForPlayerSingle( unit, Player(0) )

Mind that this will disable the selection circle of your selected unit. You will have to create a dummy selection circle.
 
Level 3
Joined
Jan 7, 2010
Messages
37
Thanks to you two.

@Ezekiel "EnableSelect" doesn't work for me. The left-clicking doesn't trigger a selection event :/

This is what I got:

JASS:
scope LockSelection initializer Init
    private function F takes nothing returns boolean
    local integer i = GetPlayerId(GetTriggerPlayer())
        if GetLocalPlayer() == Player(i) then
            if cH[i] != cS[i] then
                call ClearSelection()
                call SelectUnit(cH[i], true)
            endif
        endif
        return false
   endfunction

//===========================================================================
    private function Init takes nothing returns nothing
    local trigger trg = CreateTrigger()
    local integer i
        set i = 0
        loop
            exitwhen i > 2
                call TriggerRegisterPlayerUnitEvent(trg, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
            set i = i + 1
        endloop
        call TriggerAddCondition( trg, function F )
    endfunction
endscope

Is there anything I need to keep in mind? Desync/GetLocalPlayer...
 
Last edited:
Level 12
Joined
Mar 13, 2012
Messages
1,121
"EnableSelect" doesn't work for me. The left-clicking doesn't trigger a selection event :/

True. If you need selection events then I fear there is no other way as doing constants deselects of other units. This is not optimal and there will be always a small delay though.

Is there anything I need to keep in mind? Desync/GetLocalPlayer...
Yes, dont put ClearSelection and SelectUnit in the GetLocalPlayer block.
 
This would be the best way so you don't have to deal with loops or timers or repeated mass-calls/functions. It is quite simple and easy too.

[trigger=]
Events
Map initialization
Conditions
Actions
Game - Disable selection and deselection functionality (Enable selection circles)
Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
Selection - Select (Last created unit) for Player 1 (Red)
Unit - Create 1 Footman for Player 2 (Blue) at (Center of (Playable map area)) facing Default building facing degrees

[/trigger]

You might be facing a selection circle problem though it works better then every way listed so far here.
 
Status
Not open for further replies.
Top