Thread Tools Display Modes
05/18/24, 06:38 PM   #1
vsrs_au
Join Date: Dec 2022
Posts: 24
slash commands question

Are ESO addons allowed to run slash commands? Or is it prevented due to possible exploits?
  Reply With Quote
05/18/24, 08:48 PM   #2
Vilkasmanga
AddOn Author - Click to view addons
Join Date: Dec 2023
Posts: 8
Not sure what you mean, can you elaborate?

Addons can add slash commands (like, enable additional functionality from the command line) and they can invoke a lot of the same (non-combat related) tasks as some of the existing slash commands...?

What did you have in mind?

-V
  Reply With Quote
05/18/24, 09:18 PM   #3
vsrs_au
Join Date: Dec 2022
Posts: 24
Originally Posted by Vilkasmanga View Post
Not sure what you mean, can you elaborate?

Addons can add slash commands (like, enable additional functionality from the command line) and they can invoke a lot of the same (non-combat related) tasks as some of the existing slash commands...?

What did you have in mind?

-V
I want to know if addons can invoke slash commands, i.e. the command itself, not the code it runs.
  Reply With Quote
05/18/24, 09:25 PM   #4
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 410
Yes. Slash commands are stored in the SLASH_COMMANDS table as functions. Thus, you can call commands as you would any other other table stored in a function.e.g. /script SLASH_COMMANDS['/sit']()

There's no possible exploits, as far as I'm aware, and most slash commands are either emotes or commands created by addons anyway.
  Reply With Quote
05/18/24, 09:32 PM   #5
vsrs_au
Join Date: Dec 2022
Posts: 24
Originally Posted by Dolgubon View Post
Yes. Slash commands are stored in the SLASH_COMMANDS table as functions. Thus, you can call commands as you would any other other table stored in a function.e.g. /script SLASH_COMMANDS['/sit']()

There's no possible exploits, as far as I'm aware, and most slash commands are either emotes or commands created by addons anyway.
Fantastic! I wanted to be able to invoke emotes with a single keypress (e.g. it's very nice for role-playing), and I didn't realise I could just invoke the SLASH_COMMANDS table entry as a no-argument function.
  Reply With Quote
05/18/24, 10:25 PM   #6
vsrs_au
Join Date: Dec 2022
Posts: 24
I can't get the keybind to invoke the slash command. I updated an existing addon I've been working on, as follows:

Added new file Bindings.xml:
Code:
<Bindings>
  <Layer name="Slash commands">
    <Category name="Slash commands category 1">
      <Action name="SLASH_SLEEP">
        <Down>MyAddon.RunSlashCommand("/sleep")</Down>
      </Action>
    </Category>
  </Layer>
</Bindings>
Then, in the Initialise() function of my addon, I added the line:
Code:
	ZO_CreateStringId("SI_BINDING_NAME_SLASH_SLEEP", "Run slash command: /sleep")
and added a new function:
Code:
function MyAddon.RunSlashCommand(argtext)
	SLASH_COMMANDS[argtext]()
end
I also added the new filename Bindings.xml to the MyAddon.txt file. I don't know what I'm doing wrong here. There's no error popups, but when I assign a key to my custom keybind (which I can see in the "Controls" page), then press it, nothing happens.

I tried replacing the line in the new function with
Code:
d("slash cmd: sleep")
and then with
Code:
SLASH_COMMANDS["/sleep"]()
but they don't run, either, so it seems the keybind isn't running anything, so I guess the link between the keybind and the function call is broken??

Last edited by vsrs_au : 05/18/24 at 10:50 PM. Reason: updated problem description
  Reply With Quote
05/19/24, 02:16 AM   #7
vsrs_au
Join Date: Dec 2022
Posts: 24
I found a way to make it work. For some reason, changing the layer name to "General" makes the code work, so I can press a single key and my player does /sleep. What's even odder is that the fix I found comes from a 10-year old ESOUI thread, LOL!

https://www.esoui.com/forums/showthread.php?p=3978

Perhaps someone could explain (a) why the layer name affects the keybind-function link, and (b) whether I can get this working with my own custom layer name?
  Reply With Quote
05/19/24, 05:22 AM   #8
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 578
It depends on which layers are currently active.

You should not use the name "General", but its translatable string identifier: SI_KEYBINDINGS_LAYER_GENERAL
For example:
Lua Code:
  1. <Bindings>
  2.   <Layer name="SI_KEYBINDINGS_LAYER_GENERAL">
  3.     <Category name="SI_KEYBINDINGS_CATEGORY_USER_INTERFACE">
  4.       <Action name="POTIONMAKER">
  5.         <Down>SLASH_COMMANDS["/potionmaker"]()</Down>
  6.       </Action>
  7.     </Category>
  8.   </Layer>
  9. </Bindings>

If you want to use your own layer name, you have to push and remove the layer depending on where and when your keybinds should be enabled.
For example:
Lua Code:
  1. local function stateChanged(oldState, newState)
  2.     if newState == SCENE_SHOWN then
  3.         PushActionLayerByName(layerName)
  4.     elseif newState == SCENE_HIDING then
  5.         RemoveActionLayerByName(layerName)
  6.     end
  7. end
  8. HUD_SCENE:RegisterCallback("StateChange", stateChanged)
But I think the SI_KEYBINDINGS_LAYER_GENERAL layer is what you want to use anyway.
  Reply With Quote
05/19/24, 06:15 AM   #9
Calamath
AddOn Author - Click to view addons
Join Date: Aug 2019
Posts: 37
Originally Posted by vsrs_au View Post
Perhaps someone could explain (a) why the layer name affects the keybind-function link, and (b) whether I can get this working with my own custom layer name?
The action layers are hierarchical, so if you define your own action layer, you must manage it in your add-on. The code you initially showed did not work because it lacked the processing for that. So you have to understand how ESOUI scenes work, design which scenes activate your own action layer, and manage it using the api mentioned by votan.

But what you want to do is quite simple, and it is safer to take advantage of the GENERAL action layer of the vanilla UI.
  Reply With Quote
05/19/24, 12:24 PM   #10
vsrs_au
Join Date: Dec 2022
Posts: 24
Thanks for the useful replies! Sorry for the delay in my reply: I was sleeping, and it's 4:30am here, I'm getting ready for work.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » slash commands question


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off