Use arrays for client init states, not client data

This commit is contained in:
Vortrex
2022-05-30 07:38:48 -05:00
parent ea49a41c45
commit a097da7a63
3 changed files with 47 additions and 16 deletions

View File

@@ -107,9 +107,9 @@ function updatePlayerPing(client) {
// =========================================================================== // ===========================================================================
function playerClientReady(client) { function playerClientReady(client) {
setEntityData(client, "vrr.isReady", true, false); playerResourceReady[client.index] = true;
logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client resources are downloaded and ready!`); logToConsole(LOG_DEBUG, `[VRR.Client] ${getPlayerDisplayForConsole(client)}'s client resources are downloaded and ready! Started: ${getYesNoFromBool(playerResourceStarted[client.index])}`);
if(getEntityData(client, "vrr.isStarted") == true) { if(playerResourceStarted[client.index] == true) {
initClient(client); initClient(client);
} }
} }
@@ -117,16 +117,16 @@ function playerClientReady(client) {
// =========================================================================== // ===========================================================================
function playerGUIReady(client) { function playerGUIReady(client) {
setEntityData(client, "vrr.guiReady", true, false); playerGUI[client.index] = true;
logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client GUI is initialized and ready!`); logToConsole(LOG_DEBUG, `[VRR.Client] ${getPlayerDisplayForConsole(client)}'s client GUI is initialized and ready!`);
} }
// =========================================================================== // ===========================================================================
function playerClientStarted(client) { function playerClientStarted(client) {
setEntityData(client, "vrr.isStarted", true, false); playerResourceStarted[client.index] = true;
logToConsole(LOG_DEBUG, `${getPlayerDisplayForConsole(client)}'s client resources are started and running!`); logToConsole(LOG_DEBUG, `[VRR.Client] ${getPlayerDisplayForConsole(client)}'s client resources are started and running! Ready: ${getYesNoFromBool(playerResourceReady[client.index])}`);
if(getEntityData(client, "vrr.isReady") == true) { if(playerResourceReady[client.index] == true) {
initClient(client); initClient(client);
} }
} }
@@ -134,7 +134,7 @@ function playerClientStarted(client) {
// =========================================================================== // ===========================================================================
function playerClientStopped(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); 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) { function sendAllBusinessesToPlayer(client) {
let businesses = getServerData().businesses; let businesses = getServerData().businesses;
for(let i in businesses) { for(let i in businesses) {
@@ -1119,12 +1131,21 @@ function sendAllHousesToPlayer(client) {
// ========================================================================== // ==========================================================================
function sendAllJobsToPlayer(client) { function sendAllJobsToPlayer(client) {
//let jobs = getServerData().jobs; let jobs = getServerData().jobs;
//for(let i in jobs) { for(let i in jobs) {
// for(let j in jobs[i].locations) { for(let j in jobs[i].locations) {
// sendJobToPlayer(client, jobs[i].index, jobs[i].name, jobs[i].locations[j].position, jobs[i].blipModel); 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 serverStartTime = 0;
let logLevel = LOG_INFO|LOG_DEBUG|LOG_VERBOSE; // LOG_ERROR|LOG_WARN; 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); resetClientStuff(client);
getServerData().clients[getPlayerId(client)] = null; 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()) { if(!areServerElementsSupported()) {
sendAllBusinessesToPlayer(client); sendAllBusinessesToPlayer(client);
sendAllHousesToPlayer(client); sendAllHousesToPlayer(client);
sendAllJobsToPlayer(client); //sendAllJobsToPlayer(client);
//sendAllVehiclesToPlayer(client); //sendAllVehiclesToPlayer(client);
requestPlayerPedNetworkId(client); requestPlayerPedNetworkId(client);
} }