Communications class
Part of Radios
Radios lets characters talk to each other over any distance.
A radio is an item with a frequency. A character who keeps an enabled radio in their
hotbar speaks on its frequency by starting a chat message with one of
Communications.prefixes, and everyone with an enabled radio tuned to that frequency in
their own hotbar receives the message wherever they are. The players standing near the
speaker overhear it, like anything else that is said out loud.
The frequency of a radio is changed through its item menu: the server asks the player for the new frequency with a prompt and checks the answer before the radio is retuned.
Three server-side hooks surround a transmission: PlayerCanRadio can forbid a player to
speak on the radio, PlayerAdjustRadioInfo decides who receives the message and
PlayerRadioUsed is run once it has been sent. If the Display Typing plugin is loaded,
players who are typing a radio message are shown as 'radioing'.
Summary
Functions
Communications.prefixes.Methods
Communications.speak_radio is sending, which also tells it that the message has not been canceled.Communications.speak_radio is sending the message, the listeners of that transmission; for any other message with a frequency, the players with an enabled radio tuned to it in their hotbar.Functions
Checks whether a player may speak on the radio, by asking the PlayerCanRadio hook.
Parameters
- actor Player player about to speak
- text String message, without the radio prefix
- item_obj Item the radio the player speaks into
Returns
- Boolean false if a plugin has forbidden it
- String phrase or text that says why, if the plugin has given one
Checks whether a player may retune a radio right now: it has to be a radio that still exists and is turned on, and the player has to have it at hand, which means that it is in one of their inventories or, if it lies in the world, within their reach.
The PlayerCanUseItem hook is not asked here. The item menu has asked it by the time
the frequency button reaches the radio, and asking it again when the answer to the
frequency prompt arrives would refuse players for what pressing the button has done,
such as spending their last move turn in combat. This check only makes sure that the
radio has not left the player in the meantime.
Parameters
- actor Player player who retunes the radio
- item_obj Item the radio
Returns
- Boolean
Writes a radio frequency the way players enter it: three digits, a decimal point and one more digit.
Parameters
- frequency Number
Returns
- String for example '100.1', or an empty string if the frequency is not a number
Returns the first enabled radio in a player's hotbar.
Parameters
- owner Player player to check
Returns
- Item enabled radio, nil if there is none
Returns the enabled radios a player has in their hotbar. A player who has no character loaded has no inventories and therefore no radios.
Parameters
- owner Player player to check
Returns
- List<Item> enabled radios, empty if there are none
Checks whether a chat text is a radio message, that is whether it starts with one of
Communications.prefixes. Letter case is ignored, as it is when the message is sent.
Parameters
- text String chat text, or its outline made by the Display Typing plugin
Returns
- Boolean
Checks whether a player has an enabled radio tuned to a frequency in their hotbar.
Parameters
- owner Player player to check
- frequency Number frequency to look for
Returns
- Boolean
Turns what a player has typed into a radio frequency. A frequency is written as three digits, a decimal point and one more digit, such as '100.1'; a comma is accepted in place of the point and the spaces around the text are ignored.
Parameters
- value String text to parse
Returns
- Number the frequency, or nil if the text is not a valid frequency
Asks a player for the new frequency of a radio and retunes the radio to the answer. A prompt that the player has not answered yet is closed when a new one is opened.
Parameters
- actor Player player to ask
- item_obj Item the radio
Returns
- Boolean true if the player has been asked
Makes a player say a text over the radio in their hotbar. The player is notified if
they have no enabled radio there, if they may not speak in character (see
RPCommands:can_say_ic), or if the PlayerCanRadio hook forbids them to speak and says why.
Nothing happens if there is nothing in the text but spaces.
Parameters
- actor Player player who speaks
- text String message, without the radio prefix
Returns
- Boolean true if the message has been sent
See also
Communications.speak_radio(speaker, text, frequency, item_obj)
server plugins/radios/plugin/sv_plugin.lua:129Sends a radio message on a frequency. It is received anywhere by the speaker and by
the players with an enabled radio tuned to the frequency in their hotbar, and overheard
by the players near the speaker. The PlayerAdjustRadioInfo hook can change who receives
it, and the PlayerRadioUsed hook is run once it has been sent. The PlayerCanRadio hook
is not asked here, see Communications.say_radio for that.
Parameters
- speaker Player player talking
- text String message
- frequency Number frequency to talk on
- item_obj Item optional, defaults to
nilthe radio the player speaks into, passed on to the hooks
Returns
- Boolean true if the message has been sent, false if there was nothing to say, the frequency is not a number or a plugin has canceled the message
Tunes a radio to the frequency a player has entered, if the text is a valid frequency and the player may retune the radio. The player is notified of the outcome.
Parameters
- actor Player player who retunes the radio
- item_obj Item the radio
- value String the frequency as the player typed it, such as '100.1'
Returns
- Boolean true if the radio has been retuned
See also
Methods
Communications:AdjustMessageData(_listener, message_data)
server plugins/radios/plugin/sv_hooks.lua:40Keeps the list of the players a radio message is sent to out of the copy of the message that each of them receives, so that a client cannot tell who else is listening.
Parameters
- _listener Player player the copy of the message is for
- message_data Map the copy of the message data, radio messages have a frequency field
Communications:ChatboxMessageSent(message_data, receivers)
server plugins/radios/plugin/sv_hooks.lua:50Notes who has received the radio message that Communications.speak_radio is sending,
which also tells it that the message has not been canceled.
Parameters
- message_data Map message data, radio messages have a frequency field
- receivers List<Player> the players the message has been sent to
Shows players who are typing a message with a radio prefix as 'radioing'. The text may be
the outline of what is typed (see DisplayTyping:outline), which is matched the same way.
Parameters
- _target Player player that is typing
- text String text being typed, or its outline
Returns
- String 'radioing' for a radio message, nil for anything else
Registers the 'radioing' kind of speech with the Display Typing plugin, if it is loaded. The bubble of a player who is typing a radio message is visible from as far away as the message itself is overheard.
Makes radio messages reach their listeners wherever they are: the speaker and, while
Communications.speak_radio is sending the message, the listeners of that transmission;
for any other message with a frequency, the players with an enabled radio tuned to it in
their hotbar.
The chatbox only lets this hook force a message through, so the false returned for everyone else does not block anything: those players are still checked against the radius of the message, which is how the players near the speaker overhear it. That is intended.
Parameters
- listener Player player that would hear the message
- message_data Map message data, radio messages have a frequency field
Returns
- Boolean true if the listener receives the radio message over the radio, false if they can only overhear it, nil for other messages