• 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.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! Click here to post your idea!

What I want to do is impossible to do and there are no workarounds. Warcraft 3 is inconsistent.

Status
Not open for further replies.
Level 6
Joined
Jul 12, 2021
Messages
97
What I want to do is impossible to do and there are no workarounds. (Or so I think)

What I want to do is very simple. I want that when I press the key X the menu for an ability that a unit doesn't have or have inside an spellbook open.

I've tried this:
With the next code and the next trigger when the key X is pressed the trigger LetterX is run.
JASS:
function KeyPressActions takes nothing returns nothing

    local oskeytype pressedkey = BlzGetTriggerPlayerKey()
    if (pressedkey == OSKEY_X) then
       call ConditionalTriggerExecute(gg_trg_LetterX)
    endif

endfunction


function InitializeHotkey takes nothing returns nothing

    local trigger keytrig = CreateTrigger()
    call BlzTriggerRegisterPlayerKeyEvent(keytrig, Player(0), OSKEY_X, 0, true)

    call TriggerAddAction(keytrig, function KeyPressActions)

endfunction
  • IntitializeHotkey
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: call InitializeHotkey()
With the next trigger (LetterX) they ability Spellbook Empty is removed and the ability Spellbook Empty HotkeyB is added. As it name implies, the hotkey of the ability added is "B".
  • LetterX
    • Events
    • Conditions
    • Actions
      • Unit - Remove Spellbook Empty from Paladin 0006 <gen>
      • Unit - Add Spellbook Empty HotkeyB to Paladin 0006 <gen>
      • Game - Force Player 1 (Red) to press the key B.
      • Game - Force Player 1 (Red) to press the key B.
Later the ability Spellbook Empty HotkeyB is removed and the ability spellbook Empty is added again. We won't focus on that part since I have no issues with it.

It gets tricky here. The ability Spellbook Empty HotkeyB was added and inside it, it has an ability with the hotkey B. Immediately after that, the trigger orders the player 1 to press B twice. The Spellbook opens, but the ability inside isn't opened. The only way to open it is to put a wait or a timer between the 2 functions that order the player 1 to press B.
I tried adding the ability with the hotkey B instead of the Spellbook Empty HotkeyB but it still needs a wait or a timer. I want the ability to open immediately, so these two methods do not work, since they open it with [a short] delay.
I also tried to not add and remove any spellbook with triggers, and just force to press the hotkey of the Spellbook Empty ability and then the hotkey B, but it still opens the menu with [a short] delay.


Next I tried adding these two functions:
JASS:
 function TimerExpires takes nothing returns nothing
      call ForceUIKeyBJ( Player(0), "B" )
 endfunction

function Timer takes nothing returns nothing
   call TimerStart(udg_Timer3, 0.01, true, function TimerExpires)
endfunction
With the previous 2 functions the key B is pressed every 0.01 seconds. Now the trigger works properly... sometimes. When the letter H is pressed the ability with the hotkey B is added and the menu opens. Sometimes it opens immediately but other times it opens with [a very short] delay. Also, I don't like having a timer that is run every 0.01 all the time, because of performance issues.
I tried reducing the timer to less than 0.01 seconds but didn't work. Also tried to add a second timer that presses B every 0.01 seconds and starts 0.005 seconds after the first one, but it didn't work.
I tried many more things with timers but nothing works, Warcraft 3 is simply inconsistent. I tried so many things with timers that it lead me to believe that, either, timers aren't consistent or all functions used are inconsistent in time (Remove ability, Add ability and Force UI Press Key).


I need the trigger to open immediately all the times, not just sometimes, since I'm creating a complex system and this is the last piece of a big puzzle. The system will not meet my standards if the ability doesn't open immediately all the times. I would be really grateful if someone could provide me with a solution or a partial solution. Thanks ahead.
 
Last edited:

Uncle

Warcraft Moderator
Level 71
Joined
Aug 10, 2018
Messages
7,532
Spellbooks aren't really something you want to use if you're trying to avoid limitations. This is because the addition of custom UI has made a lot of the impossible, possible, you just have to design your map around it which can take a lot of work. Otherwise, you're stuck with an age old problem that doesn't have a proper solution since Forcing a hotkey isn't responsive and there's nothing you can do to change that.

The way I look at it, your map's foundation (the systems in place from the beginning) determine what you can and cannot do in the future. The more stuff you pile on top of that foundation the harder it will be to go back and make changes to it. So make sure you have a strong foundation (good systems in place that allow flexibility) and you can avoid problems like these and go above and beyond the limitations of Warcraft 3 that most players are used to.
 
Last edited:
Level 6
Joined
Jul 12, 2021
Messages
97
Thank you for your insight Uncle, I reallly appreciate it.

Spellbooks aren't really something you want to use if you're trying to avoid limitations.
Could you please elaborate on the limitations of Spellbooks?




This is because the addition of custom UI has made a lot of the impossible, possible, you just have to design your map around it which can take a lot of work.
...you can avoid problems like these and go above and beyond the limitations of Warcraft 3 that most players are used to.

ButtonsPositions X=Row.jpg


There are 12 slots available for each unit. The first 5 are used for the Command Buttons Move, Stop, Hold Position, Attack and Patrol. I want a unit to have 11 free slots. I want the slot #12 to be a spellbook that when opened it contains the Command Buttons Move, Stop, Hold Position, Attack and Patrol. I have already achieved this.

What I want to do but haven't achieved is that the hotkeys of the Command Buttons work when the spelllbook is closed. I have already achieved this for Stop and Hold Position, but not for Move, Attack and Patrol. I am completely ignorant regarding custom UI. Do you happen to know if this problem can be solved with custom UI?
 
Level 43
Joined
Feb 27, 2007
Messages
5,432
I have tried a fair bit to force successive key presses like you want to do here (B, then B again) and what I found is consistent with what you’ve written here.

A 0.00 timeout timer, ExecuteFunc, TriggerEvaluate, and hooking it all didn’t work to force the second key press; there has to be some finite amount of time passed before it can accept the second input. I theorized that it needed a minimum of 1 frame delay so that the second press actually does something after the UI element is redrawn. How long one frame is depends on the game’s current FPS.

Aside from an extremely fast timer that spams B there really isn’t a solution that ‘consistently works’. And even then with that timer you end up hearing a lot of clicks as the key press is spammed.
 
Status
Not open for further replies.
Top