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

Deselect selected unit

Status
Not open for further replies.
Level 16
Joined
May 1, 2008
Messages
1,605
Seas =)

The plan: I (re)create a map and I need the following: Players can send units - that spawn -> to steal a life from another enemy team.( Tower wars) Now I need something, that if they select a "spawn-able" unit, they this unit gets autmatic deselected, so they can't controll them.

"Spawn-able" means all the units who can be selected to spawn - so that this "Deselecting" not effect by structures and/or builder - and the units must be still attackable and able to get buffs.

Also would be nice, if the solution would be in Jass and without extra variables. (If not needed)

Thanks
~ Dr. Boom
 
JASS:
globals
    group SelectGroup = CreateGroup()
endglobals
function DeselectCond takes nothing returns boolean
    return IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE)
//replace this with your filter, eg GetUnitTypeId() == 'h000'
endfunction
function DeselectxChild takes nothing returns nothing
    call SelectUnit(GetEnumUnit(),false)
endfunction
function Deselectx takes nothing returns nothing
    local integer i = 0
    loop
        exitwhen i == 12
        call GroupEnumUnitsSelected(SelectGroup,Player(i),Condition(function DeselectCond)) 
        call ForGroup(SelectGroup,function DeselectxChild)
        set i = i + 1
    endloop
endfunction
function InitTrig_Deselection takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t,0.02,true)
    call TriggerAddAction(t,function Deselectx)
    set t = null
endfunction

This will kind of simulate an 'unselectable' kind of effect. I tested it and it works fine. You can select them for a split second but that is kind of unavoidable no matter how low the frequency is. You can just try messing around with this function, and try to get it to work how you want it to. Yes, they can still be attacked and buffed.

EDIT: Yeah, I forgot that there was a select event.
 
Last edited:
Level 18
Joined
Jan 21, 2006
Messages
2,552
PurgeandFire111, there are much better ways of doing that:

JASS:
scope Example initializer init

globals
    public constant integer     YOUR_TYPE       = 'hfoo'
endglobals

public function onSelect takes nothing returns nothing
    call SelectUnit(GetTriggerUnit(), false)
endfunction
public function isType takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit())==YOUR_TYPE
endfunction
public function init takes nothing returns nothing
    local trigger t=CreateTrigger()
    local integer i=0
    loop
        exitwhen (i==16)
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
        set i=i+1
    endloop
    call TriggerAddCondition(t, Filter(function isType))
    call TriggerAddAction(t, function onSelect)
endfunction

endscope

There are better ways of disabling player control over specific units though. Why exactly do you not want players to be able to select these units, so they cannot control them by the user?
 
Last edited:
Level 18
Joined
Jan 21, 2006
Messages
2,552
Well I actually removed the statement that he's quoting me for because I tested it out and it seems that it ignores pathing (which is probably not desirable). I believe they can still be buffed though.

Justify said:
chaos and stuff like "removing locust" will end in unselectable but ingame normal behaving units.

For example:

JASS:
call UnitAddAbility( someUnit, 'Aloc' )
call UnitRemoveAbility( someUnit, 'Aloc' )
call ShowUnit( someUnit, false )
call ShowUnit( someUnit, true )

This will make the model of "someUnit" not change the color of the cursor when hovering, and clicking on the model of the unit will no longer select it; instead you must drag your selection over it. If you want to see the Chaos bug I believe it is:

JASS:
call UnitAddAbility(u, 'Aloc')
call UnitRemoveAbility(u, 'Aloc')
call UnitAddAbility(u, 'Srtt')
call UnitRemoveAbility(u, 'Srtt')

Where u would be your unit variable.
 
Level 16
Joined
May 1, 2008
Messages
1,605
There are better ways of disabling player control over specific units though. Why exactly do you not want players to be able to select these units, so they cannot control them by the user?

Seas =)

So finally Im back - I create a tower wars map - I got 6 teams - now if every build - there still need a free way to the finish of each team. I can't do this with neutral units - so I add to each spawn-able units damage. Now (ofc) the player shouldn't abuse it - so I make nearly all units un-control-able
 
Level 12
Joined
Aug 22, 2008
Messages
911
1. You could save a specific unit classification for those units (for example ancient, tauren, giant, etc - they're rarely used in these maps), and deselect every unit of that type that the player selects.
2. You could begin to compare unit-types, something that would be horrible to code and probably work very slowly.
 
Status
Not open for further replies.
Top