Merge branch 'nightly' into ragemp

This commit is contained in:
Vortrex
2022-05-31 08:35:59 -05:00
17 changed files with 207 additions and 66 deletions

View File

@@ -101,6 +101,8 @@ function closeAllWindows() {
guiRightKey = false;
guiUpKey = false;
guiDownKey = false;
setChatWindowEnabled(true);
}
// ===========================================================================

View File

@@ -20,9 +20,10 @@ let jobBlipBlinkTimer = null;
// ===========================================================================
class JobData {
constructor(jobId, name, position, blipModel, pickupModel) {
constructor(jobId, jobLocationId, name, position, blipModel, pickupModel) {
this.index = -1;
this.jobId = jobId;
this.jobLocationId = jobLocationId;
this.name = name;
this.position = position;
this.blipModel = blipModel;
@@ -134,12 +135,13 @@ function hideJobRouteLocation() {
// ===========================================================================
function receiveJobFromServer(jobId, name, position, blipModel, pickupModel) {
function receiveJobFromServer(jobId, jobLocationId, name, position, blipModel, pickupModel) {
logToConsole(LOG_DEBUG, `[VRR.Job] Received job ${jobId} (${name}) from server`);
if(getGame() == VRR_GAME_GTA_IV) {
if(getJobData(jobId) != false) {
let jobData = getJobData(jobId);
jobData.jobLocationId = jobLocationId;
jobData.name = name;
jobData.position = position;
jobData.blipModel = blipModel;
@@ -178,9 +180,9 @@ function receiveJobFromServer(jobId, name, position, blipModel, pickupModel) {
}
} else {
logToConsole(LOG_DEBUG, `[VRR.Job] Job ${jobId} doesn't exist. Adding ...`);
let tempJobData = new JobData(jobId, name, position, blipModel, pickupModel);
let tempJobData = new JobData(jobId, jobLocationId, name, position, blipModel, pickupModel);
if(blipModel != -1) {
let blipId = createGameBlip(tempJobData.blipModel, tempJobData.position, tempJobData.name);
let blipId = createGameBlip(blipModel, tempJobData.position, tempJobData.name);
if(blipId != -1) {
tempJobData.blipId = blipId;
}
@@ -188,7 +190,7 @@ function receiveJobFromServer(jobId, name, position, blipModel, pickupModel) {
} else {
logToConsole(LOG_DEBUG, `[VRR.Job] Job ${jobId} has no blip.`);
}
jobs.push(tempJobData);
getServerData().jobs.push(tempJobData);
setAllJobDataIndexes();
}
}
@@ -201,9 +203,9 @@ function receiveJobFromServer(jobId, name, position, blipModel, pickupModel) {
* @return {JobData} The job's data (class instance)
*/
function getJobData(jobId) {
for(let i in jobs) {
if(jobs[i].jobId == jobId) {
return jobs[i];
for(let i in getServerData().jobs) {
if(getServerData().jobs[i].jobId == jobId) {
return getServerData().jobs[i];
}
}
@@ -213,7 +215,7 @@ function receiveJobFromServer(jobId, name, position, blipModel, pickupModel) {
// ===========================================================================
function setAllJobDataIndexes() {
for(let i in jobs) {
for(let i in getServerData().jobs) {
jobs[i].index = i;
}
}

View File

@@ -207,16 +207,16 @@ function onServerSpawnedLocalPlayer(state) {
calledDeathEvent = false;
}, 1000);
getPeds().filter(ped => !ped.isType(ELEMENT_PLAYER)).forEach(ped => {
getElementsByType(ELEMENT_PED).filter(ped => !ped.isType(ELEMENT_PLAYER)).forEach(ped => {
syncCivilianProperties(ped);
});
getPlayers().forEach(player => {
getElementsByType(ELEMENT_PLAYER).forEach(player => {
syncPlayerProperties(player);
});
getVehicles().forEach(veh => {
syncVehicleProperties(veh);
getElementsByType(ELEMENT_VEHICLE).forEach(vehicle => {
syncVehicleProperties(vehicle);
});
}
}

View File

@@ -7,11 +7,56 @@
// TYPE: Client (JavaScript)
// ===========================================================================
function receiveVehicleFromServer(vehicleId, position, model, colour1, colour2, colour3 = 0, colour4 = 0) {
logToConsole(LOG_DEBUG, `[VRR.Job] Received vehicle ${vehicleId} (${getVehicleNameFromModel(model, getGame())}) from server`);
class VehicleData {
constructor(vehicleId, model, position, heading, colour1, colour2, colour3, colour4, locked, lights, engine, licensePlate) {
this.index = -1;
this.vehicleId = vehicleId;
this.model = model;
this.position = position;
this.heading = heading;
this.colour1 = colour1;
this.colour2 = colour2;
this.colour3 = colour3;
this.colour4 = colour4;
this.pickupModel = pickupModel;
this.locked = locked;
this.lights = lights;
this.engine = engine;
this.licensePlate = licensePlate;
this.ivNetworkId = -1;
}
}
if(getGame() == VRR_GAME_GTA_IV) {
// ===========================================================================
function receiveVehicleFromServer(vehicleId, position, model, colour1, colour2, colour3 = 0, colour4 = 0, locked = false, lights = false, engine = false, licensePlate = "") {
logToConsole(LOG_DEBUG, `[VRR.Vehicle] Received vehicle ${vehicleId} (${getVehicleNameFromModel(model, getGame())}) from server`);
if(getGame() != VRR_GAME_GTA_IV) {
return false;
}
if(getVehicleData(vehicleId) != false) {
let vehicleData = getVehicleData(vehicleId);
//vehicleData.position = position;
//vehicleData.heading = heading;
//vehicleData.model
vehicleData.colour1 = colour1;
vehicleData.colour2 = colour2;
vehicleData.colour3 = colour3;
vehicleData.colour4 = colour4;
vehicleData.engine = engine;
vehicleData.lights = lights;
vehicleData.locked = locked;
vehicleData.licensePlate = "";
let vehicle = natives.getVehicleFromNetworkId(vehicleId.ivNetworkId);
} else {
//logToConsole(LOG_DEBUG, `[VRR.Vehicle] Vehicle ${vehicleId} doesn't exist. Adding ...`);
//let tempVehicleData = new VehicleData(vehicleId, name, position, blipModel, pickupModel);
//vehicles.push(tempVehicleData);
//setAllJobDataIndexes();
}
}
@@ -59,4 +104,28 @@ function setVehiclePurchaseState(state, vehicleId, position) {
vehiclePurchasePosition = position;
}
// ===========================================================================
/**
* @param {number} vehicleId - The ID of the job (initially provided by server)
* @return {VehicleData} The vehicle's data (class instance)
*/
function getVehicleData(vehicleId) {
for(let i in getServerData().vehicles) {
if(getServerData().vehicles[i].vehicleId == vehicleId) {
return getServerData().vehicles[i];
}
}
return false;
}
// ===========================================================================
function setAllVehicleDataIndexes() {
for(let i in getServerData().vehicles) {
getServerData().vehicles[i].index = i;
}
}
// ===========================================================================

View File

@@ -1169,28 +1169,41 @@ function savePlayerToDatabase(client) {
// ===========================================================================
function initClient(client) {
logToConsole(LOG_DEBUG, `[VRR.Account] Initializing client ${getPlayerDisplayForConsole(client)} ...`);
if(isConsole(client)) {
logToConsole(LOG_DEBUG|LOG_ERROR, `[VRR.Account] Client initialization failed for ${getPlayerDisplayForConsole(client)}! (is console client)`);
return false;
}
if(doesEntityDataExist(client, "vrr.isInitialized") || getEntityData(client, "vrr.isInitialized") == true) {
logToConsole(LOG_DEBUG, `[VRR.Account] Initializing client ${getPlayerDisplayForConsole(client)} ...`);
if(playerInitialized[client.index] == true) {
logToConsole(LOG_DEBUG|LOG_ERROR, `[VRR.Account] Client initialization failed for ${getPlayerDisplayForConsole(client)}! (already initialized)`);
return false;
}
setEntityData(client, "vrr.isInitialized", true, false);
sendPlayerGUIColours(client);
logToConsole(LOG_DEBUG, `[VRR.Account] Initializing GUI for ${getPlayerDisplayForConsole(client)} ...`);
sendPlayerGUIInit(client);
updatePlayerSnowState(client);
logToConsole(LOG_DEBUG, `[VRR.Account] Showing connect camera to ${getPlayerDisplayForConsole(client)} ...`);
showConnectCameraToPlayer(client);
messageClient(`Please wait ...`, client, getColourByName("softGreen"));
logToConsole(LOG_DEBUG, `[VRR.Account] Waiting for 2.5 seconds to prevent race attack ...`);
setTimeout(function() {
if(client != null) {
clearChatBox(client);
logToConsole(LOG_DEBUG, `[VRR.Account] Loading account for ${getPlayerDisplayForConsole(client)}`);
let tempAccountData = loadAccountFromName(getPlayerName(client), true);
logToConsole(LOG_DEBUG, `[VRR.Account] Loading subaccounts for ${getPlayerDisplayForConsole(client)}`);
let tempSubAccounts = loadSubAccountsFromAccount(tempAccountData.databaseId);
getServerData().clients[getPlayerId(client)] = new ClientData(client, tempAccountData, tempSubAccounts);

View File

@@ -732,11 +732,12 @@ function getBusinessInfoCommand(command, params, client) {
break;
case VRR_BIZOWNER_NONE:
submitBugReport(client, `[AUTOMATED REPORT] getBusinessInfoCommand() - Invalid ownerType for business ${businessId}/${getBusinessData(businessId).databaseId}`);
ownerName = "INVALID";
//submitBugReport(client, `[AUTOMATED REPORT] getBusinessInfoCommand() - Invalid ownerType for business ${businessId}/${getBusinessData(businessId).databaseId}`);
ownerName = "None";
break;
default:
submitBugReport(client, `[AUTOMATED REPORT] getBusinessInfoCommand() - Invalid ownerType ${businessData.ownerType} for business ${businessId}/${getBusinessData(businessId).databaseId}`);
ownerName = "None";
break;
}

View File

@@ -18,22 +18,22 @@ function initChatScript() {
function processPlayerChat(client, messageText) {
if(!isConsole(client)) {
if(!getPlayerData(client)) {
messagePlayerError(client, "You need to login before you can chat!");
messagePlayerError(client, getLocaleString(client, "MustBeLoggedInAndSpawnedToChat"));
return false;
}
if(!isPlayerLoggedIn(client)) {
messagePlayerError(client, "You need to login before you can chat!");
messagePlayerError(client, getLocaleString(client, "MustBeLoggedInAndSpawnedToChat"));
return false;
}
if(!isPlayerSpawned(client)) {
messagePlayerError(client, "You need to spawn before you can chat!");
messagePlayerError(client, getLocaleString(client, "MustBeLoggedInAndSpawnedToChat"));
return false;
}
if(isPlayerMuted(client)) {
messagePlayerError(client, "You are muted and can't chat!");
messagePlayerError(client, getLocaleString(client, "MutedCantChat"));
return false;
}
@@ -74,7 +74,7 @@ function meActionCommand(command, params, client) {
function doActionCommand(command, params, client) {
if(isPlayerMuted(client)) {
messagePlayerError(client, "You are muted and can't chat!");
messagePlayerError(client, getLocaleString(client, "MutedCantChat"));
return false;
}
@@ -91,7 +91,7 @@ function doActionCommand(command, params, client) {
function shoutCommand(command, params, client) {
if(isPlayerMuted(client)) {
messagePlayerError(client, "You are muted and can't chat!");
messagePlayerError(client, getLocaleString(client, "MutedCantChat"));
return false;
}
@@ -108,7 +108,7 @@ function shoutCommand(command, params, client) {
function megaphoneChatCommand(command, params, client) {
if(isPlayerMuted(client)) {
messagePlayerError(client, "You are muted and can't chat!");
messagePlayerError(client, getLocaleString(client, "MutedCantChat"));
return false;
}
@@ -118,7 +118,7 @@ function megaphoneChatCommand(command, params, client) {
}
if(!canPlayerUseMegaphone(client)) {
messagePlayerError(client, "You must have a megaphone item or be in an emergency vehicle!");
messagePlayerError(client, getLocaleString(client, "CantUseMegaphone"));
return false;
}
@@ -130,7 +130,7 @@ function megaphoneChatCommand(command, params, client) {
function talkCommand(command, params, client) {
if(isPlayerMuted(client)) {
messagePlayerError(client, "You are muted and can't chat!");
messagePlayerError(client, getLocaleString(client, "MutedCantChat"));
return false;
}
@@ -147,7 +147,7 @@ function talkCommand(command, params, client) {
function whisperCommand(command, params, client) {
if(isPlayerMuted(client)) {
messagePlayerError(client, "You are muted and can't chat!");
messagePlayerError(client, getLocaleString(client, "MutedCantChat"));
return false;
}
@@ -164,7 +164,7 @@ function whisperCommand(command, params, client) {
function adminChatCommand(command, params, client) {
if(isPlayerMuted(client)) {
messagePlayerError(client, "You are muted and can't chat!");
messagePlayerError(client, getLocaleString(client, "MutedCantChat"));
return false;
}
@@ -180,7 +180,7 @@ function adminChatCommand(command, params, client) {
function clanChatCommand(command, params, client) {
if(isPlayerMuted(client)) {
messagePlayerError(client, "You are muted and can't chat!");
messagePlayerError(client, getLocaleString(client, "MutedCantChat"));
return false;
}

View File

@@ -107,9 +107,9 @@ function updatePlayerPing(client) {
// ===========================================================================
function playerClientReady(client) {
setEntityData(client, "vrr.isReady", true, false);
logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client resources are downloaded and ready!`);
if(getEntityData(client, "vrr.isStarted") == true) {
playerResourceReady[client.index] = true;
logToConsole(LOG_DEBUG, `[VRR.Client] ${getPlayerDisplayForConsole(client)}'s client resources are downloaded and ready! Started: ${getYesNoFromBool(playerResourceStarted[client.index])}`);
if(playerResourceStarted[client.index] == true) {
initClient(client);
}
}
@@ -117,16 +117,16 @@ function playerClientReady(client) {
// ===========================================================================
function playerGUIReady(client) {
setEntityData(client, "vrr.guiReady", true, false);
logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client GUI is initialized and ready!`);
playerGUI[client.index] = true;
logToConsole(LOG_DEBUG, `[VRR.Client] ${getPlayerDisplayForConsole(client)}'s client GUI is initialized and ready!`);
}
// ===========================================================================
function playerClientStarted(client) {
setEntityData(client, "vrr.isStarted", true, false);
logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client resources are started and running!`);
if(getEntityData(client, "vrr.isReady") == true) {
playerResourceStarted[client.index] = true;
logToConsole(LOG_DEBUG, `[VRR.Client] ${getPlayerDisplayForConsole(client)}'s client resources are started and running! Ready: ${getYesNoFromBool(playerResourceReady[client.index])}`);
if(playerResourceReady[client.index] == true) {
initClient(client);
}
}
@@ -134,7 +134,7 @@ function playerClientStarted(client) {
// ===========================================================================
function playerClientStopped(client) {
logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client resources have stopped (possibly error?). Kicking them from the server ...`);
logToConsole(LOG_DEBUG, `[VRR.Client] ${getPlayerDisplayForConsole(client)}'s client resources have stopped (possibly error?). Kicking them from the server ...`);
disconnectPlayer(client);
}
@@ -1100,6 +1100,18 @@ function sendHouseToPlayer(client, houseId, description, entrancePosition, blipM
// ==========================================================================
function sendJobToPlayer(client, jobId, jobLocationId, name, position) {
sendNetworkEventToPlayer("vrr.job", client, jobId, jobLocationId, name, position);
}
// ==========================================================================
function sendVehicleToPlayer(client, vehicleId, model, position, heading, colour1, colour2, colour3, colour4) {
sendNetworkEventToPlayer("vrr.vehicle", client, vehicleId, model, position, heading, colour1, colour2, colour3, colour4);
}
// ==========================================================================
function sendAllBusinessesToPlayer(client) {
let businesses = getServerData().businesses;
for(let i in businesses) {
@@ -1119,12 +1131,21 @@ function sendAllHousesToPlayer(client) {
// ==========================================================================
function sendAllJobsToPlayer(client) {
//let jobs = getServerData().jobs;
//for(let i in jobs) {
// for(let j in jobs[i].locations) {
// sendJobToPlayer(client, jobs[i].index, jobs[i].name, jobs[i].locations[j].position, jobs[i].blipModel);
// }
//}
let jobs = getServerData().jobs;
for(let i in jobs) {
for(let j in jobs[i].locations) {
sendJobToPlayer(client, jobs[i].index, jobs[i].locations[j].index, jobs[i].name, jobs[i].locations[j].position, jobs[i].blipModel);
}
}
}
// ==========================================================================
function sendAllVehiclesToPlayer(client) {
let vehicles = getServerData().vehicles;
for(let i in vehicles) {
sendVehicleToPlayer(client, vehicles[i].index, vehicles[i].model, vehicles[i].syncPosition, vehicles[i].syncHeading, vehicles[i].colour1, vehicles[i].colour2, vehicles[i].colour3, vehicles[i].colour4);
}
}
// ==========================================================================

View File

@@ -11,6 +11,11 @@ let scriptVersion = "1.1";
let serverStartTime = 0;
let logLevel = LOG_INFO|LOG_DEBUG|LOG_VERBOSE; // LOG_ERROR|LOG_WARN;
let playerResourceReady = new Array(server.maxClients).fill(false);
let playerResourceStarted = new Array(server.maxClients).fill(false);
let playerInitialized = new Array(server.maxClients).fill(false);
let playerGUI = new Array(server.maxClients).fill(false);
// ===========================================================================
/**

View File

@@ -126,6 +126,11 @@ function onPlayerQuit(event, client, quitReasonId) {
resetClientStuff(client);
getServerData().clients[getPlayerId(client)] = null;
}
playerResourceReady[client.index] = false;
playerResourceStarted[client.index] = false;
playerInitialized[client.index] = false;
playerGUIReady[client.index] = false;
}
// ===========================================================================
@@ -623,7 +628,7 @@ function onPlayerSpawn(client) {
if(!areServerElementsSupported()) {
sendAllBusinessesToPlayer(client);
sendAllHousesToPlayer(client);
sendAllJobsToPlayer(client);
//sendAllJobsToPlayer(client);
//sendAllVehiclesToPlayer(client);
requestPlayerPedNetworkId(client);
}

View File

@@ -659,20 +659,22 @@ function getClosestHouseExit(position, dimension) {
// ===========================================================================
function getPlayerHouse(client) {
if(getPlayerDimension(client) == getGameConfig().mainWorldDimension[getGame()]) {
let closestEntrance = getClosestHouseEntrance(getPlayerPosition(client), getPlayerDimension(client));
if(getDistance(getPlayerPosition(client), getHouseData(closestEntrance).entrancePosition) <= getGlobalConfig().enterPropertyDistance) {
return getHouseData(closestEntrance).index;
}
} else {
let closestEntrance = getClosestHouseEntrance(getPlayerPosition(client), getPlayerDimension(client));
if(getDistance(getPlayerPosition(client), getHouseData(closestEntrance).entrancePosition) <= getGlobalConfig().enterPropertyDistance) {
return getHouseData(closestEntrance).index;
}
if(getServerData().houses.length > 0) {
if(getPlayerDimension(client) == getGameConfig().mainWorldDimension[getGame()]) {
let closestEntrance = getClosestHouseEntrance(getPlayerPosition(client), getPlayerDimension(client));
if(getDistance(getPlayerPosition(client), getHouseData(closestEntrance).entrancePosition) <= getGlobalConfig().enterPropertyDistance) {
return getHouseData(closestEntrance).index;
}
} else {
let closestEntrance = getClosestHouseEntrance(getPlayerPosition(client), getPlayerDimension(client));
if(getDistance(getPlayerPosition(client), getHouseData(closestEntrance).entrancePosition) <= getGlobalConfig().enterPropertyDistance) {
return getHouseData(closestEntrance).index;
}
for(let i in getServerData().houses) {
if(getServerData().houses[i].hasInterior && getServerData().houses[i].exitDimension == getPlayerDimension(client)) {
return i;
for(let i in getServerData().houses) {
if(getServerData().houses[i].hasInterior && getServerData().houses[i].exitDimension == getPlayerDimension(client)) {
return i;
}
}
}
}

View File

@@ -1008,7 +1008,7 @@ function playerUseItem(client, hotBarSlot) {
let clients = getClients();
for(let i in clients) {
if(getDistance(getPlayerPosition(client), getPlayerPosition(clients[i])) <= 7) {
makeChatBoxSectionHeader(clients[i], getLocaleString(client, "Badge", getCharacterFullName(client)));
makeChatBoxSectionHeader(clients[i], getLocaleString(client, "HeaderBadgeInfo", getCharacterFullName(client)));
messagePlayerNormal(client, `{clanOrange}Type:{MAINCOLOUR} ${getJobData(getPlayerJob(client)).name}`);
messagePlayerNormal(client, `{clanOrange}ID:{MAINCOLOUR} ${addPrefixNumberFill(getPlayerCurrentSubAccount(client).databaseId, 5)}`);
messagePlayerNormal(client, `{clanOrange}Rank:{MAINCOLOUR} ${getJobRankName(getPlayerJob(client), getPlayerJobRank(client))}`);

View File

@@ -641,9 +641,10 @@ function stopWorking(client) {
restorePlayerJobLockerItems(client);
respawnJobVehicle(client);
sendPlayerStopJobRoute(client);
messageDiscordEventChannel(`💼 ${getPlayerName(client)} has stopped working as a ${getJobData(jobId).name}`);
let jobId = getPlayerJob(client);
messageDiscordEventChannel(`💼 ${getPlayerName(client)} has stopped working as a ${getJobData(jobId).name}`);
switch(getJobType(jobId)) {
case VRR_JOB_POLICE:
messagePlayerInfo(client, "Your uniform, equipment, and vehicle have been returned to the police station");

View File

@@ -46,8 +46,6 @@ function addKeyBindCommand(command, params, client) {
// ===========================================================================
function removeKeyBindCommand(command, params, client) {
let splitParams = params.split(" ");
let keyId = getKeyIdFromParams(getParam(params, " ", 1));
if(!keyId) {

View File

@@ -61,12 +61,30 @@ function getGroupedLocaleString(client, stringName, index, ...args) {
function getRawLocaleString(stringName, localeId) {
return getLocaleStrings()[localeId][stringName];
//if(findResourceByName("agrp_locale").exports.doesLocaleStringExist(localeId, stringName) == false) {
// return "";
//}
//let tempString = findResourceByName("agrp_locale").exports.getRawLocaleString(localeId, stringName);
//if(tempString == "" || tempString == null || tempString == undefined) {
// return "";
//}
}
// ===========================================================================
function getRawGroupedLocaleString(stringName, localeId, index) {
return getLocaleStrings()[localeId][stringName][index];
//if(findResourceByName("agrp_locale").exports.doesLocaleStringExist(localeId, stringName) == false) {
// return "";
//}
//let tempString = findResourceByName("agrp_locale").exports.getRawLocaleString(localeId, stringName);
//if(tempString == "" || tempString == null || tempString == undefined) {
// return "";
//}
}
// ===========================================================================

View File

@@ -461,9 +461,13 @@ function getNPCInfoCommand(command, params, client) {
function getClosestNPC(position) {
let npcs = getServerData().npcs;
let interior = getPlayerInterior(client);
let dimension = getPlayerDimension(client);
let closest = 0;
for(let i in npcs) {
if(getDistance(npcs[i].ped.position, position) < getDistance(npcs[closest].ped.position, position)) {
if(getDistance(npcs[i].ped.position, position) < getDistance(npcs[closest].ped.position, position) && npcs[closest].interior == interior && npcs[closest].dimension == dimension) {
closest = i;
}
}

View File

@@ -6631,7 +6631,7 @@ let gameData = {
["Apartment 107", 0, 200, toVector3(209.76, -1273.40, 19.27), toVector3(26.67, -1328.89, 13.00), 11, null],
],
npcs: [
["Front Desk Clerk", 160, toVector(215.11, -1272.65, 12.09), 2.95],
["Front Desk Clerk", 160, toVector3(215.11, -1272.65, 12.09), 2.95],
]
}
}