Files
GTA4RP/scripts/server/radio.js
Vortrex 9d8d5d1418 Bunch of changes (see description)
* New script files to organize GUI
* Added clientside pickup detection to reduce server load for enter/exit
* Added notips command for players to toggle random tips
* Select account last IP as part of wildcard (was separate due to old INT)
* Save account registration with datetime instead of unix timestamp
* Don't force mouse camera on moving anims in SA+
* Add IP ban to server runtime memory in subnet ban command
* Add non-roleplay character name account moderation flag
* Fix bizowner and bizclan commands
* Fix bug that allowed buying items without having the needed cash
* Fix set biz blip command
* Add dealership help label type command
* Added command to show all clan flag types
* Added discord config and load from database
* Fix angle for directional teleport and anim move directions
* Use new colour structure in preparation for locale translations
* Add on-foot only item usetype array to prevent using when in veh
* Fix wrong const value for exit pickup type
* Start using datetime in MySQL tables instead of unix timestamps
* Start adding webhooks for discord (unfinished)
* Added new discord URL to discord help category
* Added house reset pickups/blips utils
* Prevent using items when in skin selector
* Fix get player command
* Fix give player money command
* Add coffee shop and vehicle repair shop default biz item templates
* Remove old game fixes util (resource now in server config)
* Fix bug where characters in clans wouldn't be shown in char select
* Slimmed down the amount of timers
* Made some potentially large numbers more readable (commas)
* Remove colours in message for console output
2021-09-28 11:41:33 -05:00

217 lines
8.0 KiB
JavaScript

// ===========================================================================
// Vortrex's Roleplay Resource
// https://github.com/VortrexFTW/gtac_roleplay
// ===========================================================================
// FILE: radio.js
// DESC: Provides radio station streaming
// TYPE: Server (JavaScript)
// ===========================================================================
function initRadioScript() {
logToConsole(LOG_INFO, "[VRR.Radio]: Initializing radio script ...");
getServerData().radioStations = loadRadioStationsFromDatabase();
setRadioStationIndexes();
logToConsole(LOG_INFO, "[VRR.Radio]: Radio script initialized successfully!");
return true;
}
// ===========================================================================
function loadRadioStationsFromDatabase() {
logToConsole(LOG_INFO, "[VRR.Radio]: Loading radio stations from database ...");
let dbConnection = connectToDatabase();
let tempRadioStations = [];
let dbAssoc;
if(dbConnection) {
let dbQueryString = `SELECT * FROM radio_main`;
let dbQuery = queryDatabase(dbConnection, dbQueryString);
if(dbQuery) {
while(dbAssoc = fetchQueryAssoc(dbQuery)) {
let tempRadioStationData = new RadioStationData(dbAssoc);
tempRadioStations.push(tempRadioStationData);
}
freeDatabaseQuery(dbQuery);
}
disconnectFromDatabase(dbConnection);
}
logToConsole(LOG_INFO, `[VRR.Radio]: ${tempRadioStations.length} radio stations loaded from database successfully!`);
return tempRadioStations;
}
// ===========================================================================
function playStreamingRadioCommand(command, params, client) {
if(areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
messagePlayerInfo(client, "Use /radiostations for a list of available radio stations.");
return false;
}
let radioStationId = params;
if(radioStationId != 0 && typeof getServerData().radioStations[radioStationId-1] == "undefined") {
messagePlayerError(client, "That radio station ID does not exist!");
return false;
}
if(isPlayerInAnyVehicle(client)) {
if(!getVehicleData(getPlayerVehicle(client))) {
messagePlayerError(client, "This is a random traffic vehicle and commands can't be used for it.");
return false;
}
if(radioStationId == 0) {
getVehicleData(getPlayerVehicle(client)).streamingRadioStation = -1;
getPlayerData(client).streamingRadioStation = -1;
meActionToNearbyPlayers(client, `turns off their vehicle's radio`);
let clients = getClients();
for(let i in clients) {
if(getPlayerVehicle(client) == getPlayerVehicle(clients[i])) {
playRadioStreamForPlayer(clients[i], "");
}
}
return false;
}
getVehicleData(getPlayerVehicle(client)).streamingRadioStation = radioStationId-1;
getPlayerData(client).streamingRadioStation = radioStationId-1;
meActionToNearbyPlayers(client, `changes their vehicle's radio station to ${getRadioStationData(radioStationId-1).name} (${getRadioStationData(radioStationId-1).genre})`);
let clients = getClients();
for(let i in clients) {
if(getPlayerVehicle(client) == getPlayerVehicle(clients[i])) {
setPlayerVanillaRadioStation(clients[i], 0);
playRadioStreamForPlayer(clients[i], getRadioStationData(radioStationId-1).url, true, getPlayerStreamingRadioVolume(client));
}
}
} else {
if(doesEntityDataExist(client, "vrr.inHouse")) {
let houseId = getEntityData(client, "vrr.inHouse");
if(radioStationId == 0) {
getHouseData(houseId).streamingRadioStation = -1;
getPlayerData(client).streamingRadioStation = -1;
meActionToNearbyPlayers(client, `turns off the house radio`);
let clients = getClients();
for(let i in clients) {
if(getEntityData(clients[i], "vrr.inHouse") == houseId) {
playRadioStreamForPlayer(clients[i], "");
}
}
} else {
getHouseData(houseId).streamingRadioStation = radioStationId-1;
getPlayerData(client).streamingRadioStation = radioStationId-1;
meActionToNearbyPlayers(client, `changes their house radio station to ${getRadioStationData(radioStationId-1).name} (${getRadioStationData(radioStationId-1).genre})`);
let clients = getClients();
for(let i in clients) {
if(getEntityData(clients[i], "vrr.inHouse") == houseId) {
setPlayerVanillaRadioStation(clients[i], 0);
playRadioStreamForPlayer(clients[i], getRadioStationData(radioStationId-1).url, true, getPlayerStreamingRadioVolume(clients[i]));
}
}
}
} else if(isPlayerInAnyBusiness(client)) {
let businessId = getPlayerBusiness(client);
if(radioStationId == 0) {
getBusinessData(businessId).streamingRadioStation = -1;
getPlayerData(client).streamingRadioStation = -1;
meActionToNearbyPlayers(client, `turns off the business radio`);
let clients = getClients();
for(let i in clients) {
if(getPlayerBusiness(clients[i]) == businessId) {
stopRadioStreamForPlayer(clients[i]);
}
}
} else {
getBusinessData(businessId).streamingRadioStation = radioStationId-1;
getPlayerData(client).streamingRadioStation = radioStationId-1;
meActionToNearbyPlayers(client, `changes the business radio station to ${getRadioStationData(radioStationId-1).name} (${getRadioStationData(radioStationId-1).genre})`);
let clients = getClients();
for(let i in clients) {
if(getPlayerBusiness(clients[i]) == businessId) {
setPlayerVanillaRadioStation(clients[i], 0);
playRadioStreamForPlayer(clients[i], getRadioStationData(radioStationId-1).url, true, getPlayerStreamingRadioVolume(clients[i]));
}
}
}
} else {
messagePlayerError(client, "You need to be in a vehicle, business, or house to set it's radio station!");
return false;
}
}
}
// ===========================================================================
function setStreamingRadioVolumeCommand(command, params, client) {
if(areParamsEmpty(params)) {
messagePlayerSyntax(client, getCommandSyntaxText(command));
return false;
}
let volumeLevel = params;
if(isNaN(volumeLevel)) {
messagePlayerError(client, "Volume level must a number");
return false;
}
setPlayerStreamingRadioVolume(client, toInteger(volumeLevel));
getPlayerData(client).accountData.streamingRadioVolume = toInteger(volumeLevel);
let volumeEmoji = '';
if(volumeLevel >= 60) {
volumeEmoji = '🔊 ';
} else if(volumeLevel >= 30 && volumeLevel < 60) {
volumeEmoji = '🔉 ';
} else if(volumeLevel > 0 && volumeLevel < 30) {
volumeEmoji = '🔈 ';
} else if(volumeLevel <= 0) {
volumeEmoji = '🔇 ';
}
messagePlayerSuccess(client, `${volumeEmoji}You set your streaming radio volume to ${volumeLevel}%`);
}
// ===========================================================================
function getPlayerStreamingRadioVolume(client) {
if(!getPlayerData(client) || !isPlayerLoggedIn(client) || !isPlayerSpawned(client)) {
return 20;
}
return getPlayerData(client).accountData.streamingRadioVolume;
}
// ===========================================================================
function showRadioStationListCommand(command, params, client) {
let stationList = getServerData().radioStations.map(function(x) { return `${getInlineChatColourByName("lightGrey")}${x.index}: ${getInlineChatColourByName("white")}${x.name}`; });
let chunkedList = splitArrayIntoChunks(stationList, 4);
messagePlayerInfo(client, `${getInlineChatColourByType("clanOrange")}== ${getInlineChatColourByType("jobYellow")}Radio Stations ${getInlineChatColourByType("clanOrange")}===========================`);
for(let i in chunkedList) {
messagePlayerInfo(client, chunkedList[i].join(", "));
}
}
// ===========================================================================
function setRadioStationIndexes() {
for(let i in getServerData().radioStations) {
getServerData().radioStations[i].index = i;
}
}
// ===========================================================================
function getRadioStationData(radioStationId) {
return getServerData().radioStations[radioStationId];
}
// ===========================================================================