ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Adding a Keybind for My Addon (https://www.esoui.com/forums/showthread.php?t=10351)

PrimeRibeye 10/25/22 04:24 PM

Adding a Keybind for My Addon
 
Hey guys, I'm looking to add a keybind for my addon instead of people having to type a /command in chat. Any help will be possible.



It's just a simple add on I have that allows people to port to my house by typing /crafting in text chat. I'd like to add a hotkey option where they can hotkey and have the ability to jump pressing 1 button.

Link to Addon: https://www.esoui.com/downloads/info...tingHouse.html

wookiefriseur 10/25/22 10:43 PM

Or just use Housing Hub
 
Some useful links in https://www.esoui.com/forums/showthread.php?t=9867


You could probably do something like that:


Bindings.xml

Xml Code:
  1. <Bindings>
  2.     <Layer name="SI_KEYBINDINGS_CATEGORY_GENERAL">
  3.         <Category name="PrimeRibeye's AddOn">
  4.             <Action name="Travel to Crafting House">
  5.                 <Down>CraftingHouse.Port()</Down>
  6.             </Action>
  7.         </Category>
  8.     </Layer>
  9. </Bindings>


Don't forget to make the local Port function available globally, for instance with
Lua Code:
  1. CraftingHouse.Port = Port()
, and to add the Bindings.xml to your CraftingHouse.txt
That should be enough, but can't test it ingame right now.

Baertram 10/26/22 01:36 AM

Edit:
As this is related to addon coding I've moved the thread to the lua/XML forum.



A good start is the ESOUI WIKI, to find examples, tutorials and code snippets, or the threads that Wookiefriseur linked above (it contains the info about the WIKI too).
https://wiki.esoui.com/Main_Page

Just search for keybind there andyou will find some tutorials using keybinds in their addons:
https://wiki.esoui.com/w/index.php?t...=keybind&go=Go

https://wiki.esoui.com/Keybindings
https://wiki.esoui.com/How_to_add_bu..._keybind_strip

PrimeRibeye 10/27/22 04:41 PM

Quote:

Originally Posted by wookiefriseur (Post 46674)
Some useful links in https://www.esoui.com/forums/showthread.php?t=9867


You could probably do something like that:


Bindings.xml

Xml Code:
  1. <Bindings>
  2.     <Layer name="SI_KEYBINDINGS_CATEGORY_GENERAL">
  3.         <Category name="PrimeRibeye's AddOn">
  4.             <Action name="Travel to Crafting House">
  5.                 <Down>CraftingHouse.Port()</Down>
  6.             </Action>
  7.         </Category>
  8.     </Layer>
  9. </Bindings>


Don't forget to make the local Port function available globally, for instance with
Lua Code:
  1. CraftingHouse.Port = Port()
, and to add the Bindings.xml to your CraftingHouse.txt
That should be enough, but can't test it ingame right now.



XML
Quote:

<Bindings>
<Layer name="SI_KEYBINDINGS_CATEGORY_GENERAL">
<Category name="Crafting House">
<Action name="Port to Craftinghouse">
<Down>CraftingHouse.Port()</Down>
</Action>
</Category>
</Layer>
</Bindings>

LUA
Quote:

CraftingHouse = {}
CraftingHouse.name = "CraftingHouse"
------------------------
function CraftingHouse.Port()

d("Porting to the crafting house.")
JumpToSpecificHouse("@lIIIlIIIl", 47)
end

function CraftingHouse.OnAddOnLoaded(event, addonName)
if addonName == CraftingHouse.name then
SLASH_COMMANDS["/crafting"] = CraftingHouse.Port


EVENT_MANAGER:UnregisterForEvent(CraftingHouse.name, EVENT_ADD_ON_LOADED)
end
end

EVENT_MANAGER:RegisterForEvent(CraftingHouse.name, EVENT_ADD_ON_LOADED, CraftingHouse.OnAddOnLoaded)
I did everything exactly right but I can't get it to show up under keybinds in game.

wookiefriseur 10/27/22 06:59 PM

Oh, yeah..looks like the Binding.xml expects a variable to generate the string, instead of writing the text directly into it.


CraftingHouse.lua
Lua Code:
  1. -- *** CraftingHouse ***
  2.  
  3. CraftingHouse = {}
  4. CraftingHouse.name = "CraftingHouse"
  5. ------------------------
  6. function CraftingHouse.Port()
  7.  
  8.    d("Porting to the crafting house.")
  9.    JumpToSpecificHouse("@lIIIlIIIl", 47)
  10. end
  11.  
  12. function CraftingHouse.OnAddOnLoaded(event, addonName)
  13.   if addonName == CraftingHouse.name then
  14.     SLASH_COMMANDS["/crafting"] = CraftingHouse.Port
  15.    
  16.     EVENT_MANAGER:UnregisterForEvent(CraftingHouse.name, EVENT_ADD_ON_LOADED)
  17.   end
  18. end
  19.  
  20. ZO_CreateStringId("SI_BINDING_NAME_CRAFTINGHOUSE_PORT", "Travel to Crafting House")
  21. EVENT_MANAGER:RegisterForEvent(CraftingHouse.name, EVENT_ADD_ON_LOADED, CraftingHouse.OnAddOnLoaded)


Bindings.xml
Xml Code:
  1. <Bindings>
  2.    <Layer name="SI_KEYBINDINGS_CATEGORY_GENERAL">
  3.      <Category name="PrimeRibeye's AddOn">
  4.        <Action name="CRAFTINGHOUSE_PORT">
  5.          <Down>CraftingHouse.Port()</Down>
  6.       </Action>
  7.     </Category>
  8.   </Layer>
  9. </Bindings>




CraftingHouse.txt
Code:

## Title: | CraftingHouse |r
## Description: Use "/crafting" to port to the crafting house
## Author: |PrimeRibeye|r
## Version: 2.7
## APIVersion: 101034 101035
## SavedVariables:
## DependsOn:

##AddOnVersion: 2
##IsLibrary: false

CraftingHouse.lua
Bindings.xml

# This Addon is not created by, affiliated with, or sponsored by
# ZeniMax Media Inc. or its affiliates
# The Elder Scrolls (c) and related logos are registered trademarks
# or trademarks of ZeniMax Media Inc. in the United States and/or
# other countries.  All rights reserved


Baertram 10/28/22 05:22 AM

Quote:

Originally Posted by wookiefriseur (Post 46679)
Oh, yeah..looks like the Binding.xml expects a variable to generate the string, instead of writing the text directly into it.

Yep, ESO forces you to use Multi language support here, which is the correct way imo ;-)

https://wiki.esoui.com/Key_bindings
Code:

<Bindings>
  <Layer name="SI_MY_ADDON_LAYER">
      <Category name="SI_MAIN_FUNCTIONS">
        <Action name="TURN_RIGHT">
            <Down>TurnRightStart()</Down>
            <Up>TurnRightStop()</Up>
        </Action>
      </Category>
  </Layer>
</Bindings>

Quote:

Layers and categories use the same names internally and on the UI; the game will pass the names through GetString to display them. Actions will have the string SI_BINDING_NAME_ prepended to their names, and the results will be passed through GetString for display (i.e. our example above would be GetString(SI_BINDING_NAME_TURN_RIGHT) which needs to be defined in your addon as string constant
https://wiki.esoui.com/How_to_add_lo...eating_strings
).


All times are GMT -6. The time now is 07:42 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI