cw.voices class
Defines the cw.voices library, voice lines that play a sound when a player says a set phrase in character.
Voice groups decide who may use their lines; one is registered per faction, and the RegisterVoiceGroups,
RegisterVoices and AdjustVoices hooks add more. The library is registered as the Voices plugin module, through
which it rewrites matching chat messages and plays the sound.
Summary
Methods
Methods
cw.voices:Add(groupName, command, phrase, sound, female, menu, pitch, volume)
shared gamemodes/catwork/gamemode/core/libraries/sh_voices.lua:81Adds a voice line to a group.
A player in the group who says command in IC chat plays sound and shows phrase instead.
Prints an error if the group is not registered.
voices:Add('Human', 'Figures', 'Figures.', 'vo/npc/male01/answer03.wav', 'vo/npc/female01/answer03.wav')
Parameters
- groupName String Name of the group
- command String Text that triggers the line; matched case-insensitively
- phrase String Text shown in chat; the message is hidden when empty or
nil - sound String Sound file path
- female Any optional, defaults to
nilWhen set in a gender group, female characters playsoundwith/malereplaced by/female - menu Any optional, defaults to
nilStored with the line, unused by Catwork - pitch Number optional, defaults to
nilSound pitch - volume Number optional, defaults to
nilSound level; 80 whennil
cw.voices:ChatboxAdjustMessageInfo(info)
shared gamemodes/catwork/gamemode/core/libraries/sh_voices.lua:146Called when chat box info should be adjusted; turns matching IC messages into voice lines.
When the message matches a voice line of a group the sender belongs to and the sender's voice
cooldown has passed (admins skip it), sets info.voice, replaces the text with the line's
phrase (or hides the message) and starts the voice_cooldown.
Parameters
- info Map The chat message info, with
filter,sender,textanddatakeys
Returns
- Boolean
truewhen the message became a voice line
cw.voices:ChatboxMessageSent(info)
shared gamemodes/catwork/gamemode/core/libraries/sh_voices.lua:210Called when a chat box message has been sent; plays the voice line's sound.
The sender emits the sound. For global lines and radio messages, every listener except the sender also hears it.
Parameters
- info Map The chat message info, with
voice,sender,listenersanddatakeys
Called when the framework initializes; registers a voice group per faction and collects voices.
Each faction gets a group its members can use. Then runs the RegisterVoiceGroups,
RegisterVoices and AdjustVoices hooks (via hook.Run), and on the client adds each group's
lines to the directory.
Returns a voice group.
Parameters
- id String Name of the group
Returns
- Map The group, or
nilif it is not registered
Returns every registered voice group.
Returns
- Map<Map> Voice groups keyed by name, each with
bGender,IsPlayerMemberandvoiceskeys
Returns the voice lines of a group.
Errors if the group is not registered.
Parameters
- id String Name of the group
Returns
- Map<Map> Voice lines keyed by their lowercased command
cw.voices:RegisterGroup(group, bGender, callback)
shared gamemodes/catwork/gamemode/core/libraries/sh_voices.lua:51Registers a voice group.
Does nothing if the group already exists.
voices:RegisterGroup('Combine', false, function(player)
return player:IsCombine()
end)
Parameters
- group String Name of the group
- bGender Boolean optional, defaults to
falseWhether female characters get the female version of each sound - callback Function Called as
callback(player); returns whether the player can use the group's voices