• 🏆 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!

[SOLVED] Activate an ability with JASS?

Status
Not open for further replies.
Level 1
Joined
Mar 13, 2021
Messages
5
Total beginner here with JASS, making my first non-GUI map to practice the basics.

I'm trying to make an ability using button frames, but I can't find a way to 'begin' the casting process of an ability without just casting it?
I want the ability to activate after the button is clicked (or the hotkey is pressed), and for the player to then have to select a target unit/area before the ability casts.

I have tried searching the forums but I can't find any other similar examples.

Thanks for any and all help!
 
Level 6
Joined
Dec 29, 2019
Messages
82
If i understand you right you are creating custom UI and you are trying to make hotkey for your custom buttons.

Well you can set shortcut key in your .fdf file using this guide UI: GLUEBUTTON

but for me this wasn't solution in my project since i wanted to be able to change shortcuts during the game and make it more generic in the code, since there is no native function to set hotkey for frame you need to improvies a little bit.

I solved it this way, let's say you got button frame stored in variable "YOUR_BUTTON_FRAME", this button should react on click and on pressing Q key on keyboard, after that you want to cast "Blink" ability for example.

What you do is set Blink ability hotkey in Object Data Editor to "O" for Example or any other key which u won't use as an button shortcut and is not part of default keys like "A" for attack or "M" for move ect.

Once you got your other key binded to your ability you can register event to trigger which will handle clicking on the button frame or pressing your shortcut and then forcing UI key press with this code:

Lua:
-- if you are starting and want to mess with UI i highly recommend you to use Lua instead of JASS, it's much more flexible and user friendly

local trig = CreateTrigger()

BlzTriggerRegisterFrameEvent(trig, YOUR_BUTTON_FRAME, FRAMEEVENT_CONTROL_CLICK)
BlzTriggerRegisterPlayerKeyEvent(trig, PLAYER, OSKEY_Q, KEY_PRESSED_NONE, true)
TriggerAddAction(trig, function()
    ForceUIKeyBJ(PLAYER, 'O')
end)
 
Level 1
Joined
Mar 13, 2021
Messages
5
If i understand you right you are creating custom UI and you are trying to make hotkey for your custom buttons.

Well you can set shortcut key in your .fdf file using this guide UI: GLUEBUTTON

but for me this wasn't solution in my project since i wanted to be able to change shortcuts during the game and make it more generic in the code, since there is no native function to set hotkey for frame you need to improvies a little bit.

I solved it this way, let's say you got button frame stored in variable "YOUR_BUTTON_FRAME", this button should react on click and on pressing Q key on keyboard, after that you want to cast "Blink" ability for example.

What you do is set Blink ability hotkey in Object Data Editor to "O" for Example or any other key which u won't use as an button shortcut and is not part of default keys like "A" for attack or "M" for move ect.

Once you got your other key binded to your ability you can register event to trigger which will handle clicking on the button frame or pressing your shortcut and then forcing UI key press with this code:

Lua:
-- if you are starting and want to mess with UI i highly recommend you to use Lua instead of JASS, it's much more flexible and user friendly

local trig = CreateTrigger()

BlzTriggerRegisterFrameEvent(trig, YOUR_BUTTON_FRAME, FRAMEEVENT_CONTROL_CLICK)
BlzTriggerRegisterPlayerKeyEvent(trig, PLAYER, OSKEY_Q, KEY_PRESSED_NONE, true)
TriggerAddAction(trig, function()
    ForceUIKeyBJ(PLAYER, 'O')
end)
Thank you for the quick reply!

I had initially intended to do that, but I have made my own custom tiles for the UI and have hidden all of the original command buttons - an unfortunate side effect of this is that they can no longer be activated by key binds either.

My original thought was to activate the casting process of an ability with code alone if possible, and not need to use the Object editor hotkeys at all. Following your solution though, is there then a way to hide the command buttons without preventing their hotkeys from working?

I assume I could potentially reduce their size until they no longer render, but does that affect performance at all?

EDIT* I've just noticed your recommendation to use LUA instead, I'll also look into that now! Thanks :)
 
Level 6
Joined
Dec 29, 2019
Messages
82
If you hide all origin frames their hotkeys will still be accesible ... i don't know how this works for custom frames from .fdf files or created from sratch via code, but as far as i know there is no command or other way to force casting process ... only using hotkey of the ability... you should always just think about what you want to achiev in your project and after that decide which way you're gonna use, which is most optimal ... when it comes to Custom UI i've got decent practice at this point :D since my "little" project is full of it... and i've managed ability using via custom buttons that way.

This is a little showcase of the result :)

 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,569
It gets pretty unresponsive, especially in multiplayer, to rely on things like forcing a hotkey to be pressed.

Assuming you control a single hero:
Remove the option to manually click abilities with the mouse.

Then have hidden abilities on your Hero which act as the hotkeys.

You can detect when these hotkeys are pressed using the newer natives, IE:
  • Game - Button for ability Bloodlust and order Orc Shaman - Bloodlust pressed.
This allows you to sync up your custom UI with the standard wc3 abilities.

See the attached map for an example, it's an unfinished project I was working on a while back that uses this design. Sorry about the messy/awful code.

There's also this for an alternate approach:
 

Attachments

  • Ability Hotkeys.w3m
    92.8 KB · Views: 37
Level 1
Joined
Mar 13, 2021
Messages
5
It gets pretty unresponsive, especially in multiplayer, to rely on things like forcing a hotkey to be pressed.

Assuming you control a single hero:
Remove the option to manually click abilities with the mouse.

Then have hidden abilities on your Hero which act as the hotkeys.

You can detect when these hotkeys are pressed using the newer natives, IE:
  • Game - Button for ability Bloodlust and order Orc Shaman - Bloodlust pressed.
This allows you to sync up your custom UI with the standard wc3 abilities.

See the attached map for an example, it's an unfinished project I was working on a while back that uses this design. Sorry about the messy/awful code.

There's also this for an alternate approach:
Thank you this is more what I was looking for! It's clear I need to switch to LUA ASAP as well.
Thanks guys and girls!
 
Status
Not open for further replies.
Top