ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Simple Addon: Play sounds with skills (HELP) (https://www.esoui.com/forums/showthread.php?t=9206)

Dracin 06/09/20 05:34 AM

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

Baertram 06/09/20 07:08 AM

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

Dracin 06/09/20 09:05 AM

Quote:

Originally Posted by Baertram (Post 41458)
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.

Dracin 06/09/20 11:25 AM

I have another quick question. Is it possible to add a short delay before playing sounds? a faction of a second.

Micke2nd 06/09/20 11:36 AM

NewAddonTemplate
you can use that as start point

Baertram 06/09/20 11:47 AM

Lua Code:
  1. zo_callLater(function() PlaySound(SOUNDS.SOUND_NAME) end, delayInMilliseconds)

Dracin 06/09/20 01:12 PM

Quote:

Originally Posted by Micke2nd (Post 41470)
NewAddonTemplate
you can use that as start point

Quote:

Originally Posted by Baertram (Post 41471)
Lua Code:
  1. zo_callLater(function() PlaySound(SOUNDS.SOUND_NAME) end, delayInMilliseconds)

Perfect! thank you :)

Dracin 06/09/20 01:13 PM

Quote:

Originally Posted by Micke2nd (Post 41470)
NewAddonTemplate
you can use that as start point

Thanks, I'll check it out.

Dracin 06/10/20 04:26 AM

@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

Baertram 06/10/20 08:45 AM

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)

Dracin 06/10/20 03:04 PM

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.

Baertram 06/10/20 03:14 PM

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...


All times are GMT -6. The time now is 02:48 AM.

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