Events
BeamVoice.on("playerLeftVoice", function(playerId, reason) print(MP.GetPlayerName(playerId) .. " left the voice chat (" .. reason .. ")")end)BeamVoice.on(event, listener) can be called at any time, even before BeamVoice is loaded. Registering the same function twice for an event does nothing. Listeners run in your plugin, a moment after the change (so a call made from a listener may already see a newer state). An error in a listener is logged and does not stop the other listeners. You can call the API from a listener. To stop listening, or if you edit your plugin while the server runs, see Remove listeners.
| Event | Arguments | When |
|---|---|---|
serviceStateChanged |
enabled (boolean), epoch (number) |
The voice chat goes down, or comes up after a (re)connection (new epoch). |
playerJoinedVoice |
playerId |
A player joined the voice chat. |
playerLeftVoice |
playerId, reason |
A player left the voice chat. reason: "left" (used /vc again), "disconnected" (left the game server), "timeout" (their game stopped sending positions), "kicked" (voice access set to "none"), "serviceDown" (the voice chat went down or reconnected). |
audioConnectedChanged |
playerId, connected (boolean) |
The player’s voice page connected or disconnected. Needs the presence capability. |
speakingChanged |
playerId, speaking (boolean), detail ({ proximity, group } booleans) |
The player started or stopped talking, or now talks somewhere else. Only with api.speaking_state = true. |
voiceKey |
playerId, key |
A player in the voice chat pressed a BeamVoice key: "mute", "group_mute", "group_deafen", "ptt_in" (push to talk pressed) or "ptt_out" (released). Only with api.voice_keys = true. |
voiceAccessChanged |
playerId, access |
setVoiceAccess changed the player’s access. |
groupChanged |
groupId, change, playerId |
change: "created", "deleted", "renamed", "options", "memberJoined", "memberLeft" or "roleChanged". playerId is set for the three member changes, else nil. |
When a player leaves the voice chat the events come in this order: speakingChanged(playerId, false, ...) if they were talking, audioConnectedChanged(playerId, false) if they were connected, groupChanged(groupId, "memberLeft", playerId) if they were in a group, then playerLeftVoice.
When the voice chat goes down or reconnects, every group gets groupChanged(groupId, "deleted") and every player playerLeftVoice(playerId, "serviceDown"). No "memberLeft" is sent for the members of a deleted group, whether it was deleted with groupChat.delete or because the voice chat went down or reconnected.
Remove listeners
Section titled “Remove listeners”BeamVoice.off removes listeners added with BeamVoice.on or BeamVoice.onReady. It only touches the listeners of your own plugin and can be called at any time, even before BeamVoice is loaded.
| Call | Removes | Returns |
|---|---|---|
BeamVoice.off(event, listener) |
That function, for that event only. | true when it was registered, else false. |
BeamVoice.off(event) |
Every listener of that event. | true when there was at least one, else false. |
BeamVoice.off("ready") |
Every onReady listener. |
Same as BeamVoice.off(event). |
All three return nil, "invalidArgument" when event is not a string, or when listener is given and is not a function.
Remove one listener
Section titled “Remove one listener”Pass the same function you gave to BeamVoice.on. Keep it in a variable: an inline function can’t be passed a second time, so it can only be removed with BeamVoice.off(event).
local function welcome(playerId) MP.SendChatMessage(playerId, "Welcome to the voice chat!")end
BeamVoice.on("playerJoinedVoice", welcome)
-- later, for example once your race has startedBeamVoice.off("playerJoinedVoice", welcome)Edit your plugin on a running server
Section titled “Edit your plugin on a running server”BeamMP runs your main.lua again each time you save it while the server runs. The listeners of the previous run stay registered, and the new run creates new functions, which BeamVoice.on can’t recognize as the same ones. Without off, every save adds one more copy and your code runs twice per event, then three times, and so on.
Call BeamVoice.off(event) right before each BeamVoice.on, and BeamVoice.off("ready") before BeamVoice.onReady. This is what the example plugin does:
-- BeamMP runs this file again when it changes, drop the listeners of the previous runBeamVoice.off("playerJoinedVoice")BeamVoice.on("playerJoinedVoice", function(playerId) MP.SendChatMessage(playerId, "Type /cat or /mouse to join a group chat!")end)
BeamVoice.off("ready")BeamVoice.onReady(createGroupChats)BeamVoice.off(event)clears the event for your whole plugin. If you add several listeners to the same event, clear it once, then add them all.- Your
onReadylistener runs again right away after the save, since it is a new function. Make it work when its groups already exist. offdoesn’t touch groups: the groups created by the previous run are still there. The example plugin finds them again by name withgroupChat.getGroups().

