• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Have unit ignore player input

Status
Not open for further replies.
Level 1
Joined
Apr 8, 2020
Messages
110
At the moment, I redirect orders but it is not ideal. For instance, unit is attacking but will stop attacking when given a new order. This will slow the unit down and might even get it killed.

So, I was wondering there is way to have a unit completely ignore player input and just continue doing whatever it is doing without interference.

All this will be temporary until he finishes an order that has a higher priority than an order issued from user side. And the player needs to be able to select the unit while all this is happening.

@Zwiebelchen @Tasyen @Uncle @TriggerHappy @DracoL1ch
 
Level 5
Joined
Jul 31, 2020
Messages
103
This will do what you're looking for:

vJASS:
/********************************************************
*                                                       *
*   gg_unit_hfoo_0000 = Footman placed in the editor.   *
*                                                       *
*********************************************************/

scope S initializer sInit
    globals
        private trigger trgMakeIgnore = CreateTrigger()  // This trigger makes the Footman run to the center of the map, making it ignore user input. "1" in chat runs it.
        private trigger trgMakeObey   = CreateTrigger()  // This trigger gives control over the Footman again. "2" in chat runs it.
    endglobals

    private function TrgMakeIgnoreActions takes nothing returns nothing
        local rect r = GetWorldBounds()
        local location loc = Location(GetRectCenterX(r), GetRectCenterY(r))

        call IssuePointOrderLoc(gg_unit_hfoo_0000, "move", loc)
        call RemoveLocation(loc)

        call BlzUnitDisableAbility(gg_unit_hfoo_0000, 'Amov', false, true)  // This one hides Move, Hold Position, and Patrol.
        call BlzUnitDisableAbility(gg_unit_hfoo_0000, 'Aatk', false, true)  // This one hides Stop, and Attack.
        call BlzUnitDisableAbility(gg_unit_hfoo_0000, 'Adef', false, true)  // This one hides Defend. Any additional ability the unit has should be added in the same fashion.
    endfunction

    private function TrgMakeObeyActions takes nothing returns nothing
        call BlzUnitDisableAbility(gg_unit_hfoo_0000, 'Amov', false, false)  // Giving abilities back once more... Move, Hold Position, Patrol
        call BlzUnitDisableAbility(gg_unit_hfoo_0000, 'Aatk', false, false)  // Stop, Attack
        call BlzUnitDisableAbility(gg_unit_hfoo_0000, 'Adef', false, false)  // Defend
    endfunction

    private function sInit takes nothing returns nothing
        local fogmodifier allVision = CreateFogModifierRect(Player(0), FOG_OF_WAR_VISIBLE, GetWorldBounds(), true, false)  // This line and the next just gives vision across the map.
        call FogModifierStart(allVision)

        call SetPlayerTechResearched(Player(0), 'Rhde', 1)  // Researching Defend for the Footman.

        call TriggerRegisterPlayerChatEvent(trgMakeIgnore, Player(0), "1", true)  // Setting up triggers from here on.
        call TriggerAddAction(trgMakeIgnore, function TrgMakeIgnoreActions)

        call TriggerRegisterPlayerChatEvent(trgMakeObey, Player(0), "2", true)
        call TriggerAddAction(trgMakeObey, function TrgMakeObeyActions)
    endfunction
endscope

The map I did it in literally has a Footman placed I control, and an enemy Peasant.

Posting "1" in the chat will make my Footman run to the center of the map. I still control it, and I can still select it. Right-clicking on the ground (smart command) will do nothing. Right-clicking the enemy Peasant will play a Move voice line, but otherwise do nothing. Pressing any hotkey (S, A, H, D, P, M) will do nothing.

Posting "2" in the chat returns the Footman to its regular state, allowing it to be controlled once more.
 
Level 1
Joined
Apr 8, 2020
Messages
110
@pr114 Then they will be targeted as enemies, which will conflict with my AI system that is in place. Thanks for your input.

@J2Krauser Umm, if the abilities are hidden, can the unit even be ordered to use them? In addition, the icons will appear disabled, won't it? That does not work in my favor then. Thanks for your input.
 
Level 5
Joined
Jul 31, 2020
Messages
103
@J2Krauser Umm, if the abilities are hidden, can the unit even be ordered to use them? In addition, the icons will appear disabled, won't it? That does not work in my favor then. Thanks for your input.

Well, you said you wanted the unit to continue doing what it was doing without interruption, which is exactly what I did. Anyway.

vJASS:
scope S initializer sInit
    globals
        ...
        private trigger trgSendToCorner = CreateTrigger()  // This trigger sends the Footman to the bottom left corner of the map. "3" in the chat runs in.
    endglobals

    ...

    private function TrgSendToCornerActions takes nothing returns nothing
        local rect r = GetWorldBounds()
        local location loc = Location(GetRectMinX(r), GetRectMinY(r))

        call BlzUnitDisableAbility(gg_unit_hfoo_0000, 'Amov', false, false)  // Temporarily enabled the Move command again to make the unit move somewhere.
        call IssuePointOrderLoc(gg_unit_hfoo_0000, "move", loc)
        call RemoveLocation(loc)
        call BlzUnitDisableAbility(gg_unit_hfoo_0000, 'Amov', false, true)   // Disable it again.
    endfunction

    private function sInit takes nothing returns nothing
        ...

        call TriggerRegisterPlayerChatEvent(trgSendToCorner, Player(0), "3", true)
        call TriggerAddAction(trgSendToCorner, function TrgSendToCornerActions)
    endfunction
endscope

I didn't do the honours of detecting whether the Move command is disabled or enabled in the moment you post "3" in the chat. You can do this in several ways, I trust you would be able to find out on your own. A boolean variable to keep track of it is one way, stored inside a hashtable for example for each unit's abilities. If there's only one such unit, this becomes even easier. You get what I'm saying. (Why keep track of it? Because if it's already enabled when the trigger fires, you don't want to disable it.)
 
Level 1
Joined
Apr 8, 2020
Messages
110
@pr114 I very much prefer if everything was functioning normally for second split decisions on the user end. I recently came across a way to disable keyboard input. It is not perfect and only half the ideal solution. I need to find a way to temporarily disable mouse input.

@J2Krauser I will check it out eventually. Thanks for the trouble.
 
Status
Not open for further replies.
Top