Merge branch 'nightly' into ragemp
This commit is contained in:
@@ -1,36 +1,59 @@
|
||||
// ===========================================================================
|
||||
// Vortrex's Roleplay Resource
|
||||
// https://github.com/VortrexFTW/gtac_roleplay
|
||||
// Asshat Gaming Roleplay
|
||||
// https://github.com/VortrexFTW/agrp_main
|
||||
// (c) 2022 Asshat Gaming
|
||||
// ===========================================================================
|
||||
// FILE: radio.js
|
||||
// DESC: Provides radio station streaming
|
||||
// TYPE: Server (JavaScript)
|
||||
// ===========================================================================
|
||||
|
||||
class RadioStationData {
|
||||
constructor(dbAssoc = false) {
|
||||
this.databaseId = 0;
|
||||
this.name = "";
|
||||
this.url = "";
|
||||
this.genre = "";
|
||||
this.codec = "";
|
||||
this.index = -1;
|
||||
|
||||
if (dbAssoc) {
|
||||
this.databaseId = dbAssoc["radio_id"];
|
||||
this.name = dbAssoc["radio_name"];
|
||||
this.url = dbAssoc["radio_url"];
|
||||
this.genre = dbAssoc["radio_genre"];
|
||||
this.codec = dbAssoc["radio_codec"];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function initRadioScript() {
|
||||
logToConsole(LOG_INFO, "[VRR.Radio]: Initializing radio script ...");
|
||||
logToConsole(LOG_INFO, "[VRR.Radio]: Radio script initialized successfully!");
|
||||
logToConsole(LOG_INFO, "[AGRP.Radio]: Initializing radio script ...");
|
||||
logToConsole(LOG_INFO, "[AGRP.Radio]: Radio script initialized successfully!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function loadRadioStationsFromDatabase() {
|
||||
logToConsole(LOG_INFO, "[VRR.Radio]: Loading radio stations from database ...");
|
||||
async function loadRadioStationsFromDatabase() {
|
||||
logToConsole(LOG_INFO, "[AGRP.Radio]: Loading radio stations from database ...");
|
||||
let dbConnection = connectToDatabase();
|
||||
let tempRadioStations = [];
|
||||
let dbAssoc;
|
||||
if(dbConnection) {
|
||||
|
||||
if (dbConnection) {
|
||||
let dbQueryString = `SELECT * FROM radio_main`;
|
||||
dbAssoc = await fetchQueryAssoc(dbConnection, dbQueryString);
|
||||
for(let i in dbAssoc) {
|
||||
for (let i in dbAssoc) {
|
||||
let tempRadioStationData = new RadioStationData(dbAssoc[i]);
|
||||
tempRadioStations.push(tempRadioStationData);
|
||||
}
|
||||
disconnectFromDatabase(dbConnection);
|
||||
}
|
||||
|
||||
logToConsole(LOG_INFO, `[VRR.Radio]: ${tempRadioStations.length} radio stations loaded from database successfully!`);
|
||||
logToConsole(LOG_INFO, `[AGRP.Radio]: ${tempRadioStations.length} radio stations loaded from database successfully!`);
|
||||
return tempRadioStations;
|
||||
}
|
||||
|
||||
@@ -46,7 +69,7 @@ function loadRadioStationsFromDatabase() {
|
||||
*
|
||||
*/
|
||||
function playStreamingRadioCommand(command, params, client) {
|
||||
if(areParamsEmpty(params)) {
|
||||
if (areParamsEmpty(params)) {
|
||||
messagePlayerSyntax(client, getCommandSyntaxText(command));
|
||||
messagePlayerInfo(client, "Use /radiostations for a list of available radio stations.");
|
||||
return false;
|
||||
@@ -54,96 +77,100 @@ function playStreamingRadioCommand(command, params, client) {
|
||||
|
||||
let radioStationId = getRadioStationFromParams(params);
|
||||
|
||||
if(radioStationId != 0 && typeof getServerData().radioStations[radioStationId-1] == "undefined") {
|
||||
if (radioStationId != 0 && typeof getServerData().radioStations[radioStationId - 1] == "undefined") {
|
||||
messagePlayerError(client, getLocaleString(client, "InvalidRadioStation"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(isPlayerInAnyVehicle(client)) {
|
||||
if (isPlayerInAnyVehicle(client)) {
|
||||
let vehicle = getPlayerVehicle(client);
|
||||
|
||||
if(!getVehicleData(vehicle)) {
|
||||
if (!getVehicleData(vehicle)) {
|
||||
messagePlayerError(client, getLocaleString(client, "RandomVehicleCommandsDisabled"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(radioStationId == 0) {
|
||||
if (radioStationId == 0) {
|
||||
getVehicleData(vehicle).streamingRadioStation = -1;
|
||||
getVehicleData(vehicle).needsSaved = true;
|
||||
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])) {
|
||||
for (let i in clients) {
|
||||
if (getPlayerVehicle(client) == getPlayerVehicle(clients[i])) {
|
||||
playRadioStreamForPlayer(clients[i], "");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
getVehicleData(vehicle).streamingRadioStation = radioStationId-1;
|
||||
getPlayerData(client).streamingRadioStation = radioStationId-1;
|
||||
meActionToNearbyPlayers(client, getLocaleString(client, "ActionVehicleRadioStationChange", getRadioStationData(radioStationId-1).name, getRadioStationData(radioStationId-1).genre));
|
||||
getVehicleData(vehicle).streamingRadioStation = radioStationId - 1;
|
||||
getPlayerData(client).streamingRadioStation = radioStationId - 1;
|
||||
meActionToNearbyPlayers(client, getLocaleString(client, "ActionVehicleRadioStationChange", getRadioStationData(radioStationId - 1).name, getRadioStationData(radioStationId - 1).genre));
|
||||
|
||||
let clients = getClients();
|
||||
for(let i in clients) {
|
||||
if(vehicle == getPlayerVehicle(clients[i])) {
|
||||
playRadioStreamForPlayer(clients[i], getRadioStationData(radioStationId-1).url, true, getPlayerStreamingRadioVolume(client));
|
||||
for (let i in clients) {
|
||||
if (vehicle == getPlayerVehicle(clients[i])) {
|
||||
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;
|
||||
if (isPlayerInAnyHouse(client)) {
|
||||
let houseId = getPlayerHouse(client);
|
||||
if (radioStationId == 0) {
|
||||
getHouseData(houseId).streamingRadioStationIndex = -1;
|
||||
getHouseData(houseId).streamingRadioStationIndex = 0;
|
||||
getHouseData(houseId).needsSaved = true;
|
||||
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) {
|
||||
for (let i in clients) {
|
||||
if (getEntityData(clients[i], "agrp.inHouse") == houseId) {
|
||||
playRadioStreamForPlayer(clients[i], "");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getHouseData(houseId).streamingRadioStation = radioStationId-1;
|
||||
getHouseData(houseId).streamingRadioStationIndex = radioStationId - 1;
|
||||
getHouseData(houseId).streamingRadioStation = getRadioStationData(radioStationId - 1).databaseId;
|
||||
getHouseData(houseId).needsSaved = true;
|
||||
getPlayerData(client).streamingRadioStation = radioStationId-1;
|
||||
meActionToNearbyPlayers(client, getLocaleString(client, "ActionHouseRadioStationChange", getRadioStationData(radioStationId-1).name, getRadioStationData(radioStationId-1).genre));
|
||||
getPlayerData(client).streamingRadioStation = radioStationId - 1;
|
||||
meActionToNearbyPlayers(client, getLocaleString(client, "ActionHouseRadioStationChange", getRadioStationData(radioStationId - 1).name, getRadioStationData(radioStationId - 1).genre));
|
||||
|
||||
let clients = getClients();
|
||||
for(let i in clients) {
|
||||
if(getEntityData(clients[i], "vrr.inHouse") == houseId) {
|
||||
playRadioStreamForPlayer(clients[i], getRadioStationData(radioStationId-1).url, true, getPlayerStreamingRadioVolume(clients[i]));
|
||||
for (let i in clients) {
|
||||
if (getEntityData(clients[i], "agrp.inHouse") == houseId) {
|
||||
playRadioStreamForPlayer(clients[i], getRadioStationData(radioStationId - 1).url, true, getPlayerStreamingRadioVolume(clients[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(isPlayerInAnyBusiness(client)) {
|
||||
} else if (isPlayerInAnyBusiness(client)) {
|
||||
let businessId = getPlayerBusiness(client);
|
||||
if(radioStationId == 0) {
|
||||
getBusinessData(businessId).streamingRadioStation = -1;
|
||||
if (radioStationId == 0) {
|
||||
getBusinessData(businessId).streamingRadioStation = 0;
|
||||
getBusinessData(businessId).streamingRadioStationIndex = -1;
|
||||
getBusinessData(businessId).needsSaved = true;
|
||||
getPlayerData(client).streamingRadioStation = -1;
|
||||
meActionToNearbyPlayers(client, `turns off the business radio`);
|
||||
|
||||
let clients = getClients();
|
||||
for(let i in clients) {
|
||||
if(getPlayerBusiness(clients[i]) == businessId) {
|
||||
for (let i in clients) {
|
||||
if (getPlayerBusiness(clients[i]) == businessId) {
|
||||
stopRadioStreamForPlayer(clients[i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getBusinessData(businessId).streamingRadioStation = radioStationId-1;
|
||||
getBusinessData(businessId).streamingRadioStationIndex = radioStationId - 1;
|
||||
getBusinessData(businessId).streamingRadioStation = getRadioStationData(radioStationId - 1).databaseId;
|
||||
getBusinessData(businessId).needsSaved = true;
|
||||
getPlayerData(client).streamingRadioStation = radioStationId-1;
|
||||
meActionToNearbyPlayers(client, getLocaleString(client, "ActionBusinessRadioStationChange", getRadioStationData(radioStationId-1).name, getRadioStationData(radioStationId-1).genre));
|
||||
getPlayerData(client).streamingRadioStation = radioStationId - 1;
|
||||
meActionToNearbyPlayers(client, getLocaleString(client, "ActionBusinessRadioStationChange", getRadioStationData(radioStationId - 1).name, getRadioStationData(radioStationId - 1).genre));
|
||||
|
||||
let clients = getClients();
|
||||
for(let i in clients) {
|
||||
if(getPlayerBusiness(clients[i]) == businessId) {
|
||||
playRadioStreamForPlayer(clients[i], getRadioStationData(radioStationId-1).url, true, getPlayerStreamingRadioVolume(clients[i]));
|
||||
for (let i in clients) {
|
||||
if (getPlayerBusiness(clients[i]) == businessId) {
|
||||
playRadioStreamForPlayer(clients[i], getRadioStationData(radioStationId - 1).url, true, getPlayerStreamingRadioVolume(clients[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,14 +193,14 @@ function playStreamingRadioCommand(command, params, client) {
|
||||
*
|
||||
*/
|
||||
function setStreamingRadioVolumeCommand(command, params, client) {
|
||||
if(areParamsEmpty(params)) {
|
||||
if (areParamsEmpty(params)) {
|
||||
messagePlayerSyntax(client, getCommandSyntaxText(command));
|
||||
return false;
|
||||
}
|
||||
|
||||
let volumeLevel = params;
|
||||
|
||||
if(isNaN(volumeLevel)) {
|
||||
if (isNaN(volumeLevel)) {
|
||||
messagePlayerError(client, getLocaleString(client, "RadioVolumeNotNumber"));
|
||||
return false;
|
||||
}
|
||||
@@ -181,13 +208,13 @@ function setStreamingRadioVolumeCommand(command, params, client) {
|
||||
setPlayerStreamingRadioVolume(client, toInteger(volumeLevel));
|
||||
getPlayerData(client).accountData.streamingRadioVolume = toInteger(volumeLevel);
|
||||
let volumeEmoji = '';
|
||||
if(volumeLevel >= 60) {
|
||||
if (volumeLevel >= 60) {
|
||||
volumeEmoji = '🔊';
|
||||
} else if(volumeLevel >= 30 && volumeLevel < 60) {
|
||||
} else if (volumeLevel >= 30 && volumeLevel < 60) {
|
||||
volumeEmoji = '🔉';
|
||||
} else if(volumeLevel > 0 && volumeLevel < 30) {
|
||||
} else if (volumeLevel > 0 && volumeLevel < 30) {
|
||||
volumeEmoji = '🔈';
|
||||
} else if(volumeLevel <= 0) {
|
||||
} else if (volumeLevel <= 0) {
|
||||
volumeEmoji = '🔇';
|
||||
}
|
||||
|
||||
@@ -197,7 +224,7 @@ function setStreamingRadioVolumeCommand(command, params, client) {
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerStreamingRadioVolume(client) {
|
||||
if(!getPlayerData(client) || !isPlayerLoggedIn(client) || !isPlayerSpawned(client)) {
|
||||
if (!getPlayerData(client) || !isPlayerLoggedIn(client) || !isPlayerSpawned(client)) {
|
||||
return 20;
|
||||
}
|
||||
return getPlayerData(client).accountData.streamingRadioVolume;
|
||||
@@ -215,13 +242,13 @@ function getPlayerStreamingRadioVolume(client) {
|
||||
*
|
||||
*/
|
||||
function showRadioStationListCommand(command, params, client) {
|
||||
let stationList = getServerData().radioStations.map(function(x) { return `{ALTCOLOUR}${toInteger(x.index)+1}: {MAINCOLOUR}${x.name}`; });
|
||||
let stationList = getServerData().radioStations.map(function (x) { return `{ALTCOLOUR}${toInteger(x.index) + 1}: {MAINCOLOUR}${x.name}`; });
|
||||
|
||||
let chunkedList = splitArrayIntoChunks(stationList, 4);
|
||||
|
||||
messagePlayerNormal(client, makeChatBoxSectionHeader(getLocaleString(client, "HeaderRadioStationsList")));
|
||||
|
||||
for(let i in chunkedList) {
|
||||
for (let i in chunkedList) {
|
||||
messagePlayerInfo(client, chunkedList[i].join(", "));
|
||||
}
|
||||
}
|
||||
@@ -229,7 +256,7 @@ function showRadioStationListCommand(command, params, client) {
|
||||
// ===========================================================================
|
||||
|
||||
function setAllRadioStationIndexes() {
|
||||
for(let i in getServerData().radioStations) {
|
||||
for (let i in getServerData().radioStations) {
|
||||
getServerData().radioStations[i].index = i;
|
||||
}
|
||||
}
|
||||
@@ -267,14 +294,14 @@ function reloadAllRadioStationsCommand(command, params, client) {
|
||||
// ===========================================================================
|
||||
|
||||
function getRadioStationFromParams(params) {
|
||||
if(isNaN(params)) {
|
||||
for(let i in getServerData().radioStations) {
|
||||
if(toLowerCase(getServerData().radioStations[i].name).indexOf(toLowerCase(params)) != -1) {
|
||||
if (isNaN(params)) {
|
||||
for (let i in getServerData().radioStations) {
|
||||
if (toLowerCase(getServerData().radioStations[i].name).indexOf(toLowerCase(params)) != -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(typeof getServerData().radioStations[params] != "undefined") {
|
||||
if (typeof getServerData().radioStations[params] != "undefined") {
|
||||
return toInteger(params);
|
||||
}
|
||||
}
|
||||
@@ -282,4 +309,34 @@ function getRadioStationFromParams(params) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getRadioStationIdFromDatabaseId(databaseId) {
|
||||
if (databaseId <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (let i in getServerData().radioStations) {
|
||||
if (getServerData().radioStations[i].databaseId == databaseId) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getRadioStationData(radioStationIndex) {
|
||||
if (radioStationIndex == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof getServerData().radioStations[radioStationIndex] == "undefined") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getServerData().radioStations[radioStationIndex];
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
Reference in New Issue
Block a user