@quietjoy Missed your messages, feel free to @ me next time. Here is a working example SelectionSounds.zip
mods/SelectionSounds/hook/lua/ui/game/selection.lua
function PlaySelectionSound(newSelection)
if playSelectionSound then
for k, unit in newSelection do
local bp = unit:GetBlueprint()
if EntityCategoryContains(categories.TECH1 * categories.STRUCTURE * categories.RADAR, unit) then
return
end
if bp.Audio.UISelection then
PlaySound(bp.Audio.UISelection)
return
end
end
end
end
Check the FAF files in the fa/lua/ui folder, to see what you can "hook", thats how you override the base files. Often you want to store the original function and run it after your code, but in this case it's not useful. Will not be compatible with other mods that hooks this function though.
https://github.com/FAForever/fa/blob/b3e14934761f3a8da7adbd845bcf2d52aeefb9e9/lua/ui/game/selection.lua
Check fa/units to see what categories you want to target, or you could target specific unit IDs.
Actually, I decided to update the code to be more useful for your needs:
local disableSoundsForUnitIDs = {
"url0001", -- Cybran commander
"url0105" -- Cybran engineer
}
local disableSoundsForUnitCategories = {
categories.STRUCTURE * categories.RADAR,
categories.BOMBER * categories.ANTINAVY,
-- Add mobile artillery as an exercise, you can find suitable categories to target in the unit file :)
}
function PlaySelectionSound(newSelection)
if playSelectionSound then
for k, unit in newSelection do
local bp = unit:GetBlueprint()
-- LOG(unit:GetUnitId()) -- Uncomment to print unit id in log when selecting them
local unitID = unit:GetUnitId()
if contains(disableSoundsForUnitIDs, unitID) then
return
end
for k, v in disableSoundsForUnitCategories do
if EntityCategoryContains(v, unit) then
return
end
end
if bp.Audio.UISelection then
PlaySound(bp.Audio.UISelection)
return
end
end
end
end
function contains(table, val)
for i, v in ipairs(table) do
if v == val then
return true
end
end
return false
end