OnClientPlayerVoiceStart: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (→Example) |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 3: | Line 3: | ||
<div style="border: 1px dotted blue; background: #00CC66;padding:4px;margin-bottom:2px;">'''Note''': This event should only be used as a low-level function for advanced users. For typical Voice scripting, please see the [[Resource:Voice|Voice Resource]]</div> | <div style="border: 1px dotted blue; background: #00CC66;padding:4px;margin-bottom:2px;">'''Note''': This event should only be used as a low-level function for advanced users. For typical Voice scripting, please see the [[Resource:Voice|Voice Resource]]</div> | ||
This event is triggered when a player starts talking through voice chat. | This event is triggered when a player starts talking through voice chat. | ||
__NOTOC__ {{Note|This event triggers inconsistently (https://github.com/multitheftauto/mtasa-blue/issues/1700). You should use onPlayerVoiceStart and trigger a custom client-sided event to get similar results, minus the cancelEvent effect.}} | |||
==Parameters== | ==Parameters== | ||
| Line 16: | Line 18: | ||
==Example== | ==Example== | ||
This example outputs to the console the player that started talking. | This example outputs to the console the player that started talking. | ||
<syntaxhighlight lang="lua">addEventHandler("onClientPlayerVoiceStart",root,function() | <section name="Example 1" class="client" show="true"> | ||
outputConsole(getPlayerName(source) | <syntaxhighlight lang="lua"> | ||
addEventHandler("onClientPlayerVoiceStart",root,function() | |||
outputConsole(getPlayerName(source).." has started talking.") | |||
end) | end) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
This example prevents the function from running multiple times due to inconsistent event execution. | |||
<section name="Example 2" class="client" show="true" > | |||
<syntaxhighlight lang="lua"> | |||
local toggleFix = 0 | |||
addEventHandler('onClientPlayerVoiceStart', localPlayer, | |||
function() | |||
if toggleFix == 0 then | |||
outputConsole("You've started talking") | |||
end | |||
end | |||
) | |||
addEventHandler('onClientPlayerVoiceStop', localPlayer, | |||
function() | |||
if not getKeyState("z") then | |||
toggleFix = 0 | |||
outputConsole("You've stopped talking") | |||
end | |||
end | |||
) | |||
</syntaxhighlight> | |||
</section> | |||
==See Also== | ==See Also== | ||
{{Client_player_events}} | {{Client_player_events}} | ||
Latest revision as of 04:25, 17 February 2026
Note: This event should only be used as a low-level function for advanced users. For typical Voice scripting, please see the Voice Resource
This event is triggered when a player starts talking through voice chat.
Parameters
No parameters.
Source
The source of this event is the player element that just started talking through voice chat.
Cancel effect
- If the source is the local player, the local player will not broadcast his voice chat to the server
- If the source is a remote player, the player who started talking will not be heard.
Example
This example outputs to the console the player that started talking.
Click to collapse [-]
Example 1addEventHandler("onClientPlayerVoiceStart",root,function()
outputConsole(getPlayerName(source).." has started talking.")
end)
This example prevents the function from running multiple times due to inconsistent event execution.
Click to collapse [-]
Example 2local toggleFix = 0
addEventHandler('onClientPlayerVoiceStart', localPlayer,
function()
if toggleFix == 0 then
outputConsole("You've started talking")
end
end
)
addEventHandler('onClientPlayerVoiceStop', localPlayer,
function()
if not getKeyState("z") then
toggleFix = 0
outputConsole("You've stopped talking")
end
end
)
See Also
- onClientPlayerChangeNick
- onClientPlayerChoke
- onClientPlayerDamage
- onClientPlayerHeliKilled
- onClientPlayerHitByWaterCannon
- onClientPlayerJoin
- onClientPlayerPickupHit
- onClientPlayerPickupLeave
- onClientPlayerQuit
- onClientPlayerRadioSwitch
- onClientPlayerSpawn
- onClientPlayerStealthKill
- onClientPlayerStuntFinish
- onClientPlayerStuntStart
- onClientPlayerTarget
- onClientPlayerVehicleEnter
- onClientPlayerVehicleExit
- onClientPlayerVoicePause
- onClientPlayerVoiceResumed
- onClientPlayerVoiceStart
- onClientPlayerVoiceStop
- onClientPlayerWasted
- onClientPlayerWeaponFire
- onClientPlayerWeaponSwitch