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

Remove Player Control of Unit

Status
Not open for further replies.
I've just about succeeded in this, but the player can still order the unit to stop.


Anyone know how to make it so a player can't control a specific unit?


This is what I've done thus far (but it messes with all units).

JASS:
call SetPlayerAbilityAvailable(player, 'Amov', true)
call SetPlayerAbilityAvailable(player, 'Aatk', true)
//create unit
//order unit
call SetPlayerAbilityAvailable(player, 'Amov', false)
call SetPlayerAbilityAvailable(player, 'Aatk', false)

But I can't remove Stop D:.


Anyways, anyone know how to stop a player from controlling a unit entirely, or to use the method I'm using right now to prevent a player form ordering a unit to stop?

Tx ^)^.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Try adding ward classification in object editor. It removes all command icons.

Do you want to be able to select the unit? Does the unit get AI commands?

Adding Cargo Hold (orc burrow) ability (with 0 cargo capacity) disables attack for a unit.
call SetUnitPropWindoAngle(unit,0) makes a unit unable to move, but it will still turn.
 
Last edited:
Hm... so Ward will allow the unit to move and attack etc, but the player won't be able to control it?

Very nice : ).

edit
Although the icons are removed, the player can still order the unit around wih the Ward classification.


The unit gets AI Commands, I just don't want the human player to be able to command it. I want it to be able to move and attack and etc, everything it normally does.


Making 'Amov' unavailable works, but the player has other units that they do need to move around and control.


edit
Trying this

JASS:
struct PreventSelect extends array
    private static trigger selectt
    private static trigger deselectt
    private static boolean online
    private static method select takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local player p = GetTriggerPlayer()
        local integer pi = GetPlayerId(GetTriggerPlayer())
        if (isSend[GetUnitUserData(u)] and p == GetOwningPlayer(u)) then
            if (0 == canCommand[pi]) then
                call SetPlayerAbilityAvailable(p, 'Amov', false)
            endif
            set canCommand[pi] = canCommand[pi] + 1
        endif
        set u = null
        set p = null
        return false
    endmethod
    private static method deselect takes nothing returns boolean
        local unit u = GetTriggerUnit()
        local player p = GetTriggerPlayer()
        local integer pi = GetPlayerId(GetTriggerPlayer())
        if (isSend[GetUnitUserData(u)] and p == unitOwner[i]) then
            set canCommand[pi] = canCommand[pi] - 1
            if (0 == canCommand[pi]) then
                call SetPlayerAbilityAvailable(p, 'Amov', true)
            endif
        endif
        set u = null
        set p = null
        return false
    endmethod
    private static method onInit takes nothing returns nothing
        local integer i = 9
        set selectt = CreateTrigger()
        set deselectt = CreateTrigger()
        call TriggerAddCondition(selectt, Condition(function thistype.select))
        call TriggerAddCondition(deselectt, Condition(function thistype.deselect))
        loop
            call TriggerRegisterPlayerUnitEvent(selectt, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
            call TriggerRegisterPlayerUnitEvent(deselectt, Player(i), EVENT_PLAYER_UNIT_DESELECTED, null)
            exitwhen 0 == i
            set i = i - 1
        endloop
    endmethod
endstruct

JASS:
library Move
    function MoveToRect takes unit u, rect r returns nothing
        local integer i = GetUnitUserData(u)
        local player p = GetOwningPlayer(u)
        local integer id = GetPlayerId(p)
        set unitMoveX[i] = GetRectCenterX(r)
        set unitMoveY[i] = GetRectCenterY(r)
        if (0 < canCommand[id]) then
            call SetPlayerAbilityAvailable(p, 'Amov', true)
        endif
        call IssueImmediateOrder(u, "stop")
        call IssuePointOrder(u, "move", unitMoveX[i], unitMoveY[i])
        if (0 < canCommand[id]) then
            call SetPlayerAbilityAvailable(p, 'Amov', false)
        endif
        set p = null
    endfunction
endlibrary

: )


edit
Any way to check if a unit is a ward? There doesn't seem to be a way... If I could do this all automatically, then I could make a general system to do this for people ^)^.
 
Last edited:
Like I said in the chat, detecting if a unit is a ward can be done like this:

JASS:
// ORDER = Order Id of an ability that only targets wards
// dummy = Global dummy unit
// STOP = Stop orderId

function IsUnitWard takes unit target returns boolean
    local boolean b
    call IssueTargetOrderById(dummy, ORDER, target)
    set b = GetUnitCurrentOrder(dummy) == ORDER
    call IssueImmediateOrderById(dummy, STOP)
    return b
endfunction

I know you think that it's too much overhead, but hey, it's either this, or a Table with a lot of data :|
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
IssueTargetOrderById has a return value btw.

When you disable 'Amov', the unit cannot move using the move order anymore. This includes trigger commands. Also it would be enough to do this on order event for a split second rather than that delayed selection events (multi-selection ftw?).

Another possibility would be to give the unit the 'ARal' ability which replaces the right-click/smart order with rally point setting.
 
IssueTargetOrderById has a return value btw.

When you disable 'Amov', the unit cannot move using the move order anymore. This includes trigger commands. Also it would be enough to do this on order event for a split second rather than that delayed selection events (multi-selection ftw?).

Another possibility would be to give the unit the 'ARal' ability which replaces the right-click/smart order with rally point setting.

I know all that and I run things accordingly. I've been using my current method with 0 bugs and 0 problems and other map makers who have seen it in-game have asked me how I pulled it off ^)^.
 
Status
Not open for further replies.
Top