- 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.
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:
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.
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()
-
Events
-
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.
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
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: