From e3eb3c3407ff2a90cf6c7848e6066fcc03e9f0cf Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Fri, 15 Oct 2021 22:37:23 -0500 Subject: [PATCH] Add megaphone chat --- scripts/server/chat.js | 50 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/scripts/server/chat.js b/scripts/server/chat.js index e31c3ea0..1526f12b 100644 --- a/scripts/server/chat.js +++ b/scripts/server/chat.js @@ -61,6 +61,27 @@ function shoutCommand(command, params, client) { // =========================================================================== +function megaphoneChatCommand(command, params, client) { + if(isPlayerMuted(client)) { + messagePlayerError(client, "You are muted and can't chat!"); + return false; + } + + if(areParamsEmpty(params)) { + messagePlayerSyntax(client, getCommandSyntaxText(command)); + return false; + } + + if(canPlayerUseMegaphone(client)) { + + } + + megaPhoneToNearbyPlayers(client, params); + return true; +} + +// =========================================================================== + function talkCommand(command, params, client) { if(isPlayerMuted(client)) { messagePlayerError(client, "You are muted and can't chat!"); @@ -178,6 +199,17 @@ function shoutToNearbyPlayers(client, messageText) { // =========================================================================== +function megaphoneToNearbyPlayers(client, messageText) { + let clients = getClientsInRange(getPlayerPosition(client), getGlobalConfig().megaphoneDistance); + for(let i in clients) { + if(getPlayerInterior(client) == getPlayerInterior(clients[i]) && getPlayerDimension(client) == getPlayerDimension(clients[i])) { + messagePlayerShout(clients[i], client, messageText); + } + } +} + +// =========================================================================== + function doActionToNearbyPlayers(client, messageText) { let clients = getClientsInRange(getPlayerPosition(client), getGlobalConfig().doActionDistance); for(let i in clients) { @@ -209,4 +241,20 @@ function clanChat(client, messageText) { } } -// =========================================================================== \ No newline at end of file +// =========================================================================== + +function canPlayerUseMegaphone(client) { + if(isPlayerHoldingItemOfType(client, VRR_ITEM_USETYPE_MEGAPHONE)) { + if(isPlayerActiveItemEnabled(client)) { + return true; + } + } + + if(getPlayerVehicle(client)) { + if(doesVehicleHaveMegaphone(getPlayerVehicle(client))) { + return true; + } + } + + return false; +} \ No newline at end of file