Thread Tools Display Modes
09/25/22, 08:48 PM   #1
rado98
Join Date: Aug 2022
Posts: 3
How "OnWeaponSwap()" equivalent

Hi

I need simple way to get a "True" if swapping weapons (as in mid weapon swap) as I understand the OnWeaponSwap() function would work (as that is private..

I am very inexperienced so the simpler the better.
  Reply With Quote
09/26/22, 01:12 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,965
The game provides events for things like that and you need to register a callback function in your addon to this event.
https://wiki.esoui.com/Events

Code:
 EVENT_ACTIVE_WEAPON_PAIR_CHANGED (number eventCode, ActiveWeaponPair activeWeaponPair, boolean locked)
ActiveWeaponPair can be one of these globals: https://wiki.esoui.com/Globals#ActiveWeaponPair


Same like starting your addon via EVENT_MANAGER:RegisterforEvent("YourAddonName_event_AddOnLoaded", EVENT_ADD_ON_LOADED, callbackFuncForEventAddOnLoaded) you need to do soemthing like:


Lua Code:
  1. local function callbackFuncForEventActiveWeaponPairSwapped(eventId, activeWeaponPairId, locked)
  2.   if activeWeaponPairId == ACTIVE_WEAPON_PAIR_MAIN then
  3.  ---your code here for weapon bar 1
  4.   elseif activeWeaponPairId == ACTIVE_WEAPON_PAIR_BACKUP then
  5.  ---your code here for weapon bar 2
  6.   end
  7. end
  8.  
  9. EVENT_MANAGER:RegisterforEvent("YourAddonName_event_active_weapon_pair_swapped", EVENT_ACTIVE_WEAPON_PAIR_CHANGED , callbackFuncForEventActiveWeaponPairSwapped)


You can find getting started, examples and tutorials here, right side:
https://wiki.esoui.com/Main_Page
  Reply With Quote
09/26/22, 09:21 AM   #3
rado98
Join Date: Aug 2022
Posts: 3
[quote=Baertram;46603]The game provides events for things like that and you need to register a callback function in your addon to this event.
https://wiki.esoui.com/Events

Thanks for the feed back but I think that would give me something other than what I need. I don't need anything to trigger based on bar swap. I need to know if I am in the middle of a bar swap. It would be part of a and/or statement

Along the lines of: "if XXX > 0 and n >= 3 and n <= 8 and.... or BAR SWAPPING" if that makes sense.

I am looking at tweaking an existing addon that is not being supported (not sure what the etiquette is on that mind you, other than not stealing the code as my own)
  Reply With Quote
09/26/22, 10:52 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,965
There is no way to detect if you currently swap the bars afaik.
You'd either have to check the vanilla game code and see if the lua provides that but I doubt it, it will be handled at the C code outside of lua which we cannot reach (as the private function also tell us: Do not touch ).


Only the events telling you as the bar swap finished.
You can use the event and check the parameter "locked". Maybe it fires multiple times for a weapon bar change, like 1st with locked = true and old barId, then locked = false and new barId?
You'd have to test this.

About stealing addon code please read this and follow the rules if you want to revive any addon:
https://www.esoui.com/forums/showthread.php?t=9865
-> If you request an addon fix/update/revive
-> If you want to take-over an abandoned addon/Before creating a patch/copy of an addon
  Reply With Quote
09/29/22, 05:43 PM   #5
rado98
Join Date: Aug 2022
Posts: 3
Thanks again for the feedback. I thought that what I neededwas not going to that straigth forward.

Hmm, maybe add a delay after a new bar is set, as a bar swapping period.

Still probably a bit beyond my skill level but I'll have a look.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » How "OnWeaponSwap()" equivalent


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