OnClientWorldSound: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Example added)
(→‎Example: pretty sure that needs to be root)
Line 24: Line 24:
This example will cancel every vehicle sound.
This example will cancel every vehicle sound.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler("onClientWorldSound", resourceRoot, function()
addEventHandler("onClientWorldSound", root, function()
     if getElementType(source) == "vehicle" then
     if getElementType(source) == "vehicle" then
         cancelEvent()
         cancelEvent()

Revision as of 09:41, 23 August 2019

This event triggers whenever a GTA sound starts playing.

[[{{{image}}}|link=|]] Note: Use setWorldSoundEnabled if you want to disable certain sounds conditionless.

For example, you should only cancel player emitted sounds in this event, because when you cancel certain vehicle sounds, the game will try to play the same sound on the next frame.

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

This example will cancel every vehicle sound.

addEventHandler("onClientWorldSound", root, function()
    if getElementType(source) == "vehicle" then
        cancelEvent()
    end
end)

See Also

World sound functions

Client other events


Client event functions