OnClientWorldSound: Difference between revisions
Jump to navigation
Jump to search
(Added example to see sound calls) |
|||
| Line 22: | Line 22: | ||
==Example== | ==Example== | ||
This example will cancel every vehicle sound. | <section name="Client" class="client" show="true"> | ||
'''Example 2:''' This example will cancel every vehicle sound. | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
addEventHandler("onClientWorldSound", root, function() | addEventHandler("onClientWorldSound", root, function() | ||
| Line 31: | Line 32: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This example lets you see how many times each sound that gets played has been played using '/seesoundlist'. | '''Example 1:''' This example lets you see how many times each sound that gets played has been played using '/seesoundlist'. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local sounds = {} | local sounds = {} | ||
| Line 56: | Line 57: | ||
addCommandHandler("seesoundlist", cmdSeeSoundList) | addCommandHandler("seesoundlist", cmdSeeSoundList) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== | ||
Revision as of 20:49, 5 April 2020
This event triggers whenever a GTA sound starts playing.
Parameters
int group, int index, float x, float y, float z
- group: An integer representing the world sound group
- index: An integer representing an individual sound within the group
- x: a floating point number representing the X coordinate on the map.
- y: a floating point number representing the Y coordinate on the map.
- z: a floating point number representing the Z coordinate on the map.
Source
The source of this event is the element, which emitted the sound.
Cancel effect
If this event is canceled, the sound won't play at all.
Example
Click to collapse [-]
ClientExample 2: This example will cancel every vehicle sound.
addEventHandler("onClientWorldSound", root, function()
if getElementType(source) == "vehicle" then
cancelEvent()
end
end)
Example 1: This example lets you see how many times each sound that gets played has been played using '/seesoundlist'.
local sounds = {}
addEventHandler("onClientWorldSound", root, function(group, index)
sounds[group.." | "..index] = (sounds[group.." | "..index] or 0) + 1
end)
function cmdSeeSoundList()
-- Put the non iterated table into an interated table so we can sort them
local tbl = {}
for sound, count in pairs(sounds) do
tbl[#tbl + 1] = {sound, count}
end
table.sort(tbl, function(a, b) return a[2] > b[2] end)
-- Output the table to clipboard
local str = "Group | Index: Times played\n"
for i, dat in ipairs(tbl) do
str = str..dat[1]..": "..dat[2].."\n"
end
setClipboard(str)
outputChatBox("Use CTRL + V in notepad to view the table.")
end
addCommandHandler("seesoundlist", cmdSeeSoundList)
See Also
World sound functions
Client other events
- onClientChatMessage
- onClientConsole
- onClientDebugMessage
- onClientExplosion
- onClientFileDownloadComplete
- onClientHUDRender
- onClientMinimize
- onClientMTAFocusChange
- onClientPedsProcessed
- onClientPlayerNetworkStatus
- onClientPreRender
- onClientRender
- onClientRestore
- onClientTransferBoxProgressChange
- onClientTransferBoxVisibilityChange
- onClientWorldSound
Client event functions
- triggerLatentServerEvent
- triggerServerEvent
- Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled