Thread Tools Display Modes
06/09/20, 05:34 AM   #1
Dracin
Join Date: Jun 2020
Posts: 7
Simple Addon: Play sounds with skills (HELP)

Hi Everyone,

I'm very new to addons in eso and I was wondering if anyone with experience could help me?

I would like to make a simple addon that plays sounds when abilities are activated. Including light and heavy attacks. The addon "Light Attack Helper" has been useful in that I could edit the code to play sounds when a light attack was successful. I would however like the sound to play even if a light attack isn't connecting with a target.

The skills would be different as I would like them only to play a sound when hitting a target.

Any help would be greatly appreciated.


Cheers
  Reply With Quote
06/09/20, 07:08 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
https://wiki.esoui.com/Events#Combat

EVENT_COMBAT_EVENT

But be warned: Not all events return a value or a unitTag so you are maybe not able to determine if you, and who you have hit with what value.
Define yourself a callback function for the event and check if it returns e.g. the dmg you have done to some enemy NPC/player.

Be sure to also register event filters so the event will not fire for EACH non-wanted stuff!!!
https://wiki.esoui.com/AddFilterForEvent
  Reply With Quote
06/09/20, 09:05 AM   #3
Dracin
Join Date: Jun 2020
Posts: 7
Originally Posted by Baertram View Post
https://wiki.esoui.com/Events#Combat

EVENT_COMBAT_EVENT

But be warned: Not all events return a value or a unitTag so you are maybe not able to determine if you, and who you have hit with what value.
Define yourself a callback function for the event and check if it returns e.g. the dmg you have done to some enemy NPC/player.

Be sure to also register event filters so the event will not fire for EACH non-wanted stuff!!!
https://wiki.esoui.com/AddFilterForEvent
Hi Baertram,

Thanks for the response. Honestly though, I have little to no knowledge when it comes to writing lua script. "PlaySound" is as far as I've got. Editing an existing script is probably all I can manage right now. I was hoping it would be a simple solution but maybe not.
  Reply With Quote
06/09/20, 11:25 AM   #4
Dracin
Join Date: Jun 2020
Posts: 7
I have another quick question. Is it possible to add a short delay before playing sounds? a faction of a second.
  Reply With Quote
06/09/20, 11:36 AM   #5
Micke2nd
AddOn Author - Click to view addons
Join Date: Mar 2017
Posts: 43
NewAddonTemplate
you can use that as start point
  Reply With Quote
06/09/20, 11:47 AM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Lua Code:
  1. zo_callLater(function() PlaySound(SOUNDS.SOUND_NAME) end, delayInMilliseconds)
  Reply With Quote
06/09/20, 01:12 PM   #7
Dracin
Join Date: Jun 2020
Posts: 7
Originally Posted by Micke2nd View Post
NewAddonTemplate
you can use that as start point
Originally Posted by Baertram View Post
Lua Code:
  1. zo_callLater(function() PlaySound(SOUNDS.SOUND_NAME) end, delayInMilliseconds)
Perfect! thank you
  Reply With Quote
06/09/20, 01:13 PM   #8
Dracin
Join Date: Jun 2020
Posts: 7
Originally Posted by Micke2nd View Post
NewAddonTemplate
you can use that as start point
Thanks, I'll check it out.
  Reply With Quote
06/10/20, 04:26 AM   #9
Dracin
Join Date: Jun 2020
Posts: 7
@Baertram Is it possible to have a sound play even when the light attacks miss? I'm able to get sounds to play on successful attacks using the Light Attack Helper Addon. This section seems to handle the combat event for light and heavy attacks.


function LightAttackHelper.onCombatEvent(_, _, _, abilityName, _, abilityActionSlotType, sourceName, _, _, _, hitValue)


if abilityActionSlotType == ACTION_SLOT_TYPE_LIGHT_ATTACK and LightAttackHelper.playerName == sourceName and abilityName == GetString(LAH_LIGHT_ATTACK) then


PlaySound("Map_Auto_Navigation_Begin_Zoom") --good


LightAttackHelper.castingHeavyAttack = false
LightAttackHelper.usedAbilityDuringHeavyAttack = false
--d("LA")

LightAttackHelper.setCounter(LightAttackHelper.LightAttackCounter + 1)
LightAttackHelper.updateRatio(true)

elseif abilityActionSlotType == ACTION_SLOT_TYPE_HEAVY_ATTACK then

if abilityName == GetString(LAH_HEAVY_ATTACK) and LightAttackHelper.playerName == sourceName then

LightAttackHelper.castingHeavyAttack = false
LightAttackHelper.usedAbilityDuringHeavyAttack = false

if LightAttackHelper.savedVariables.countHeavyAttacks then
LightAttackHelper.setCounter(LightAttackHelper.LightAttackCounter + 1)
LightAttackHelper.updateRatio(true)
end

--d("HA")
end

end




end
  Reply With Quote
06/10/20, 08:45 AM   #10
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
LightAttackHelper.onCombatEvent must be assigned as callback function to an event like EVENT_COMBAT_EVENT e.g.
So if this event also fires as the light attack does not hit you need to find out what parameters the callback function "LightAttackHelper.onCombatEvent" returns in this case.

Currently it checks for
Lua Code:
  1. if abilityActionSlotType == ACTION_SLOT_TYPE_LIGHT_ATTACK and LightAttackHelper.playerName == sourceName and abilityName == GetString(LAH_LIGHT_ATTACK) then
Makes sense. Only if the actionSlotType is a light attack, if the source is you and if the abilityName used is something for light attack.
Maybe one could also use an abilitId instead of a name here, not sure if it's always the same abilityId.

You could check what the parameters return by adding something like this at the start of the function LightAttackHelper.onCombatEvent
d("ActionSlotType: " ..tostring(abilityActionSlotType ) .. ", source: " .. tostring(sourceName) )
Just add additional .. "variableName: " .. tostring(variable) after the tostring(sourceName) (within the opening ( and closing ) of d) to see what the values are. Do a reloadui then and do some tests what is shown in your chat.

The possible variables of the function are these:
LightAttackHelper.onCombatEvent(_, _, _, abilityName, _, abilityActionSlotType, sourceName, _, _, _, hitValue)

Where all the _ could be special variables as well but you'd need to rename them to use them for a chat output.
The event_combat_event uses this parameters:
Code:
 EVENT_COMBAT_EVENT (number eventCode, number ActionResult result, boolean isError, string abilityName, number abilityGraphic, number ActionSlotType abilityActionSlotType, string sourceName, number CombatUnitType sourceType, string targetName, number CombatUnitType targetType, number hitValue, number CombatMechanicType powerType, number DamageType damageType, boolean log, number sourceUnitId, number targetUnitId, number abilityId, number overflow)
number, boolean, string etc. are the type of variables, and after that there is the name of the value that gets returned, like ActionResult or isError or abilityName.
You see, if you lay my event_combat_event function definition with all parameters above the function LightAttackHelper.onCombatEvent that the 1st _ would be eventCode, the 2nd would be Actionresult, the 3rd isError and then there is abilityName. And so on.
Just replace the _ in the function LightAttackHelper.onCombatEvent with the variables names I have shown you and you would be able to use them in your d() chat output, like e.g. ", isError: " .. tostring(isError)
  Reply With Quote
06/10/20, 03:04 PM   #11
Dracin
Join Date: Jun 2020
Posts: 7
Thanks, Baertram! I was able to make some progress with the advice you gave me. I can now play sounds when a specific skill is used. My only problem now is I can't figure out how I play a sound for light attacks when they are not connecting with a target. It seems like all of the events are tied to combat. Thanks again, I really appreciate the help.

Last edited by Dracin : 06/11/20 at 03:37 AM.
  Reply With Quote
06/10/20, 03:14 PM   #12
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Well, as I said: There is no way to detect this except maybe with this event, which checks each mouse click:
Code:
EVENT_GLOBAL_MOUSE_DOWN (number eventCode, MouseButtonIndex button, boolean ctrl, boolean alt, boolean shift, boolean command)
Search on ESOUI Source Code EVENT_GLOBAL_MOUSE_UP (number eventCode, MouseButtonIndex button, boolean ctrl, boolean alt, boolean shift, boolean command)
You could check in global on mouse down if you are in combat via the API functions IsUnitInCombat("player").
But this will not tell you if you just did a light attack or heavy attack or if you have clicked somewhere on the UI just because you like to activate skills via mouse during combat. It tracks ALL clicks...
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Simple Addon: Play sounds with skills (HELP)

Thread Tools
Display Modes

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