- Joined
- Dec 3, 2018
- Messages
- 894
Hello! I m trying to make a trigger which selects a unit when a key from the keyboard is clicked (for ex F4) and idk how to make the event can someone please help?
function Trig_MoveStart_Copy_Actions takes nothing returns nothing
*InsertActionsHere*
endfunction
//===========================================================================
function InitTrig_MoveStart_Copy takes nothing returns nothing
set gg_trg_MoveStart_Copy = CreateTrigger( )
call BlzTriggerRegisterPlayerKeyEvent(trigger,Player(0), OSKEY_W, 0, true)
call TriggerAddAction(gg_trg_MoveStart_Copy, function Trig_MoveStart_Copy_Actions)
endfunction
It's the triggers name. I.E. the one created in GUI before converting it to "custom text".variable gg_trg_MoveStart_Copy is not declared. what kind of variable is it?
All I m saying is that if i copy paste the stuff you wrote there it crashes, even after i add an action.
Here you go mate.Hello! I m trying to make a trigger which selects a unit when a key from the keyboard is clicked (for ex F4) and idk how to make the event can someone please help?
function KeyPressActions takes nothing returns nothing
local oskeytype pressedkey = BlzGetTriggerPlayerKey()
if (pressedkey == OSKEY_F4) then
call QuestMessageBJ(GetPlayersAll(), 1, "F4 pressed")
call ConditionalTriggerExecute(gg_trg_F4Pressed)
endif
endfunction
function InitializeHotkey takes nothing returns nothing
local trigger keytrig = CreateTrigger()
call BlzTriggerRegisterPlayerKeyEvent(keytrig, Player(0), OSKEY_F4, 0, true)
call TriggerAddAction(keytrig, function KeyPressActions)
endfunction
Thanks for clarifying this, was planning to when I got home tonight. Hard to do from a phone lolHere you go mate.
With the next code and triggers a specific unit is selected when someone presses F4. You can copy the code and triggers to try it or just download and open the map attached in this post.
You can assign almost any key. Feel free to ask me if you want to assign a key but don't how to program it. Remember that most of the function keys (F1-F12) already do something when pressed, so be careful when assigning something to them. Normally F4 selects a fourth hero.
JASS:function KeyPressActions takes nothing returns nothing local oskeytype pressedkey = BlzGetTriggerPlayerKey() if (pressedkey == OSKEY_F4) then call QuestMessageBJ(GetPlayersAll(), 1, "F4 pressed") call ConditionalTriggerExecute(gg_trg_F4Pressed) endif endfunction function InitializeHotkey takes nothing returns nothing local trigger keytrig = CreateTrigger() call BlzTriggerRegisterPlayerKeyEvent(keytrig, Player(0), OSKEY_F4, 0, true) call TriggerAddAction(keytrig, function KeyPressActions) endfunction
- Untitled Trigger 001
- Events
- Map initialization
- Conditions
- Actions
- Custom script: call InitializeHotkey()
- F4Pressed
- Events
- Conditions
- Actions
- Selection - Select Paladin 0001 <gen> for Player 1 (Red)