Difference between revisions of "SetWorldSoundEnabled"

From Multi Theft Auto: Wiki
m (merge notes)
(Example)
 
Line 42: Line 42:
 
     setWorldSoundEnabled ( 5, enabled ) -- And here the toggling happens.
 
     setWorldSoundEnabled ( 5, enabled ) -- And here the toggling happens.
 
     outputChatBox ( "Weapon sounds " .. state )
 
     outputChatBox ( "Weapon sounds " .. state )
 +
end
 +
addCommandHandler ( "toggleweaponsounds", toggleWeaponSounds_f )
 +
</syntaxhighlight>
 +
 +
This is the more advanced version of the
 +
<syntaxhighlight lang="lua">
 +
function toggleWeaponSounds_f ( )
 +
    local enabled = not isWorldSoundEnabled (5)
 +
    setWorldSoundEnabled ( 5, enabled ) -- And here the toggling happens.
 +
    outputChatBox ( "Weapon sounds " .. (enabled and "enabled" or "disabled"))
 
end
 
end
 
addCommandHandler ( "toggleweaponsounds", toggleWeaponSounds_f )
 
addCommandHandler ( "toggleweaponsounds", toggleWeaponSounds_f )

Latest revision as of 15:55, 30 June 2020

This function allows you to disable world sounds. A world sound is a sound effect which has not been caused by playSound or playSound3D.

[[{{{image}}}|link=]] Note:
  • The values for group and index can be determined by using the client command showsound in conjunction with setDevelopmentMode
  • This function does not affect sounds which are already playing, such as the wind sound that can only be stopped by entering an interior.
  • See also: setAmbientSoundEnabled

Syntax

bool setWorldSoundEnabled ( int group, [ int index = -1, ] bool enable [, bool immediate = false ] )

Required Arguments

Optional Arguments

  • index: An integer representing an individual sound within the group
  • immediate: A boolean if set to true will cancel the sound if it's already playing. This parameter only works for stopping the sound.

Returns

Returns true if the world sound was correctly enabled/disabled, false if invalid values were passed.

Example

This is a simplified example that lets the client toggle their weapon sounds.

function toggleWeaponSounds_f ( )
    local enabled = isWorldSoundEnabled ( 5 ) -- We place this variable here for checking.
    enabled       = not enabled -- And here we invert (toggle) the variable, so if it's false, it becomes true, if it's true, it becomes false.
    -- Used for the chat declaration:
    local state   = "enabled"

    if ( not enabled ) then
        state = "disabled"
    end
    --

    setWorldSoundEnabled ( 5, enabled ) -- And here the toggling happens.
    outputChatBox ( "Weapon sounds " .. state )
end
addCommandHandler ( "toggleweaponsounds", toggleWeaponSounds_f )

This is the more advanced version of the

function toggleWeaponSounds_f ( )
    local enabled = not isWorldSoundEnabled (5)
    setWorldSoundEnabled ( 5, enabled ) -- And here the toggling happens.
    outputChatBox ( "Weapon sounds " .. (enabled and "enabled" or "disabled"))
end
addCommandHandler ( "toggleweaponsounds", toggleWeaponSounds_f )

This example disables the wind sound effect immediately without changing the interior afterwards.

setWorldSoundEnabled(0, 0, false, true)
setWorldSoundEnabled(0, 29, false, true)
setWorldSoundEnabled(0, 30, false, true)

Requirements

Minimum supported server n/a
Minimum supported client 1.3.0-9.04134

Note: Using this function requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.3.0-9.04134" />

Changelog

Version Description
1.5.5-9.11860 Added immediate argument

See Also

BETA: FROM VERSION 1.5.7 r20450 ONWARDS