Use new native util functions

This commit is contained in:
Vortrex
2020-12-12 06:11:16 -06:00
parent df178de9e6
commit d4efdcd096
9 changed files with 83 additions and 52 deletions

View File

@@ -123,16 +123,16 @@ function updateNametags(element) {
let colour = COLOUR_WHITE; let colour = COLOUR_WHITE;
let afk = false; let afk = false;
if(client.getData("ag.name") != null) { if(getEntityData(client, "ag.name") != null) {
name = client.getData("ag.name"); name = getEntityData(client, "ag.name");
} }
if(client.getData("ag.afk") != null) { if(getEntityData(client, "ag.afk") != null) {
afk = true; afk = true;
} }
if(client.getData("ag.colour") != null) { if(getEntityData(client, "ag.colour") != null) {
colour = client.getData("ag.colour"); colour = getEntityData(client, "ag.colour");
} }
drawNametag(screenPos[0], screenPos[1], health, armour, name, 0, 1.0-distance/nametagDistance, distance, colour, afk, element.skin); drawNametag(screenPos[0], screenPos[1], health, armour, name, 0, 1.0-distance/nametagDistance, distance, colour, afk, element.skin);

View File

@@ -442,7 +442,7 @@ function loginSuccess(client) {
if(getClientData(client).subAccounts.length == 0) { if(getClientData(client).subAccounts.length == 0) {
if(getServerConfig().useGUI) { if(getServerConfig().useGUI) {
triggerNetworkEvent("ag.showPrompt", client, "You have no characters. Would you like to make one?", "No characters"); triggerNetworkEvent("ag.showPrompt", client, "You have no characters. Would you like to make one?", "No characters");
client.setData("ag.prompt", AG_PROMPT_CREATEFIRSTCHAR, false); setEntityData(client, "ag.prompt", AG_PROMPT_CREATEFIRSTCHAR, false);
} else { } else {
messageClientAlert(client, `You have no characters. Use /newchar to make one.`); messageClientAlert(client, `You have no characters. Use /newchar to make one.`);
} }
@@ -492,7 +492,7 @@ function createAccount(name, password, email = "") {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function checkLogin(client, password) { function checkLogin(client, password) {
let loginAttemptsRemaining = client.getData("ag.loginAttemptsRemaining")-1; let loginAttemptsRemaining = getEntityData(client, "ag.loginAttemptsRemaining")-1;
if(isClientLoggedIn(client)) { if(isClientLoggedIn(client)) {
if(getServerConfig().useGUI) { if(getServerConfig().useGUI) {
@@ -629,7 +629,7 @@ function checkRegistration(client, password, confirmPassword = "", emailAddress
if(getServerConfig().useGUI) { if(getServerConfig().useGUI) {
triggerNetworkEvent("ag.registrationSuccess", client); triggerNetworkEvent("ag.registrationSuccess", client);
triggerNetworkEvent("ag.showPrompt", client, "You have no characters. Would you like to make one?", "No Characters"); triggerNetworkEvent("ag.showPrompt", client, "You have no characters. Would you like to make one?", "No Characters");
client.setData("ag.prompt", AG_PROMPT_CREATEFIRSTCHAR, false); setEntityData(client, "ag.prompt", AG_PROMPT_CREATEFIRSTCHAR, false);
} else { } else {
messageClientAlert(client, `You have no characters. Use /newchar to make one.`); messageClientAlert(client, `You have no characters. Use /newchar to make one.`);
} }
@@ -686,7 +686,7 @@ function initClient(client) {
setTimeout(function() { setTimeout(function() {
let sessionId = saveSessionToDatabase(client); let sessionId = saveSessionToDatabase(client);
client.setData("ag.session", sessionId, false); setEntityData(client, "ag.session", sessionId, false);
clearChatBox(client); clearChatBox(client);
let tempAccountData = loadAccountFromName(client.name); let tempAccountData = loadAccountFromName(client.name);

View File

@@ -553,8 +553,8 @@ function getClosestBusinessEntrance(position) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function isPlayerInAnyBusiness(player) { function isPlayerInAnyBusiness(client) {
if(player.getData("ag.inBusiness")) { if(doesEntityDataExist(client, "ag.inBusiness")) {
return true; return true;
} }
@@ -563,9 +563,9 @@ function isPlayerInAnyBusiness(player) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function getPlayerBusiness(player) { function getPlayerBusiness(client) {
if(player.getData("ag.inBusiness")) { if(doesEntityDataExist(client, "ag.inBusiness")) {
return player.getData("ag.inBusiness"); return getEntityData(client, "ag.inBusiness");
} }
return false; return false;
@@ -658,8 +658,8 @@ function deleteBusiness(businessId) {
function removePlayersFromBusiness(businessId) { function removePlayersFromBusiness(businessId) {
getClients().forEach(function(client) { getClients().forEach(function(client) {
if(client.getData("ag.inBusiness")) { if(doesEntityDataExist(client, "ag.inBusiness")) {
if(client.getData("ag.inBusiness") == businessId) { if(getEntityData(client, "ag.inBusiness") == businessId) {
exitBusiness(client); exitBusiness(client);
} }
} }
@@ -669,8 +669,8 @@ function removePlayersFromBusiness(businessId) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function exitBusiness(client) { function exitBusiness(client) {
let businessId = client.getData("ag.inBusiness"); let businessId = getEntityData(client, "ag.inBusiness");
if(client.player) { if(isPlayerSpawned(client)) {
triggerNetworkEvent("ag.interior", client, getServerData().businesses[businessId].entranceInterior); triggerNetworkEvent("ag.interior", client, getServerData().businesses[businessId].entranceInterior);
triggerNetworkEvent("ag.dimension", client, getServerData().businesses[businessId].entranceDimension); triggerNetworkEvent("ag.dimension", client, getServerData().businesses[businessId].entranceDimension);
triggerNetworkEvent("ag.position", client, getServerData().businesses[businessId].entrancePosition); triggerNetworkEvent("ag.position", client, getServerData().businesses[businessId].entrancePosition);

View File

@@ -35,11 +35,11 @@ addNetworkHandler("ag.onPlayerExitSphere", function(client, sphere) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
addNetworkHandler("ag.promptAnswerNo", function(client) { addNetworkHandler("ag.promptAnswerNo", function(client) {
if(!client.getData("ag.prompt")) { if(!getEntityData(client, "ag.prompt")) {
return false; return false;
} }
switch(client.getData("ag.prompt")) { switch(getEntityData(client, "ag.prompt")) {
case AG_PROMPT_CREATEFIRSTCHAR: case AG_PROMPT_CREATEFIRSTCHAR:
triggerNetworkEvent("ag.showError", client, "You don't have a character to play. Goodbye!", "No Characters"); triggerNetworkEvent("ag.showError", client, "You don't have a character to play. Goodbye!", "No Characters");
setTimeout(function() { client.disconnect(); }, 5000); setTimeout(function() { client.disconnect(); }, 5000);
@@ -55,11 +55,11 @@ addNetworkHandler("ag.promptAnswerNo", function(client) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
addNetworkHandler("ag.promptAnswerYes", function(client) { addNetworkHandler("ag.promptAnswerYes", function(client) {
if(!client.getData("ag.prompt")) { if(!getEntityData(client, "ag.prompt")) {
return false; return false;
} }
switch(client.getData("ag.prompt")) { switch(getEntityData(client, "ag.prompt")) {
case AG_PROMPT_CREATEFIRSTCHAR: case AG_PROMPT_CREATEFIRSTCHAR:
triggerNetworkEvent("ag.showNewCharacter", client); triggerNetworkEvent("ag.showNewCharacter", client);
break; break;
@@ -92,7 +92,7 @@ addNetworkHandler("ag.onPlayerEnterSphere", function(client, sphere) {
addNetworkHandler("ag.afk", function(client, afkState) { addNetworkHandler("ag.afk", function(client, afkState) {
if(afkState) { if(afkState) {
client.setData("ag.afk", true, true); setEntityData(client, "ag.afk", true, true);
} else { } else {
client.removeData("ag.afk"); client.removeData("ag.afk");
} }
@@ -125,16 +125,16 @@ addNetworkHandler("ag.heldKey", function(client, key) {
addNetworkHandler("ag.player.sync", function(client, position, heading) { addNetworkHandler("ag.player.sync", function(client, position, heading) {
//console.log(`POS: ${position}, X: ${position.x}, Y: ${position.y}, Z: ${position.z}`); //console.log(`POS: ${position}, X: ${position.x}, Y: ${position.y}, Z: ${position.z}`);
client.setData("ag.position", position, true); setEntityData(client, "ag.position", position, true);
client.setData("ag.heading", heading, true); setEntityData(client, "ag.heading", heading, true);
}); });
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
addNetworkHandler("ag.player.death", function(client, position, heading) { addNetworkHandler("ag.player.death", function(client, position, heading) {
//console.log(`POS: ${position}, X: ${position.x}, Y: ${position.y}, Z: ${position.z}`); //console.log(`POS: ${position}, X: ${position.x}, Y: ${position.y}, Z: ${position.z}`);
client.setData("ag.position", position, true); setEntityData(client, "ag.position", position, true);
client.setData("ag.heading", heading, true); setEntityData(client, "ag.heading", heading, true);
processPlayerDeath(client); processPlayerDeath(client);
}); });
@@ -146,16 +146,15 @@ addNetworkHandler("ag.veh.sync", function(client, syncId, position, heading) {
vehicleData.syncPosition = position; vehicleData.syncPosition = position;
vehicleData.syncHeading = heading; vehicleData.syncHeading = heading;
} }
}); });
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
addNetworkHandler("ag.iv.veh", function(client, syncId) { addNetworkHandler("ag.player.vehicle", function(client, syncId) {
if(syncId == -1) { if(syncId == -1) {
client.removeData("ag.vehicle"); client.removeData("ag.vehicle");
} else { } else {
client.setData("ag.vehicle", syncId, true); setEntityData(client, "ag.vehicle", syncId, true);
} }
}); });

View File

@@ -343,10 +343,14 @@ function setSnowingCommand(command, params, client) {
} }
let splitParams = params.split(); let splitParams = params.split();
let fallingSnow = toInteger(splitParams[0]) || 0; let fallingSnow = splitParams[0] || 0;
let groundSnow = toInteger(splitParams[1]) || 0; let groundSnow = splitParams[1] || 0;
getServerConfig().fallingSnow = 0; fallingSnow = intToBool(toInteger(fallingSnow));
groundSnow = intToBool(toInteger(groundSnow));
getServerConfig().fallingSnow = fallingSnow;
getServerConfig().groundSnow = groundSnow;
messageAdminAction(`${client.name} turned falling snow ${getOnOffFromBool(intToBool(fallingSnow))} and ground snow ${getOnOffFromBool(intToBool(groundSnow))}`); messageAdminAction(`${client.name} turned falling snow ${getOnOffFromBool(intToBool(fallingSnow))} and ground snow ${getOnOffFromBool(intToBool(groundSnow))}`);
updateServerRules(); updateServerRules();

View File

@@ -190,16 +190,16 @@ function submitIdea(client, ideaText) {
let session = 0; let session = 0;
let databaseId = 0; let databaseId = 0;
if(client.getData("ag.position")) { if(getEntityData(client, "ag.position")) {
position = client.getData("ag.position"); position = getEntityData(client, "ag.position");
} }
if(client.getData("ag.heading")) { if(getEntityData(client, "ag.heading")) {
heading = client.getData("ag.heading"); heading = getEntityData(client, "ag.heading");
} }
if(client.getData("ag.session")) { if(getEntityData(client, "ag.session")) {
session = client.getData("ag.session"); session = getEntityData(client, "ag.session");
} }
if(client.console) { if(client.console) {
@@ -223,16 +223,16 @@ function submitBugReport(client, bugText) {
let session = 0; let session = 0;
let databaseId = 0; let databaseId = 0;
if(client.getData("ag.position")) { if(getEntityData(client, "ag.position")) {
position = client.getData("ag.position"); position = getEntityData(client, "ag.position");
} }
if(client.getData("ag.heading")) { if(getEntityData(client, "ag.heading")) {
heading = client.getData("ag.heading"); heading = getEntityData(client, "ag.heading");
} }
if(client.getData("ag.session")) { if(getEntityData(client, "ag.session")) {
session = client.getData("ag.session"); session = getEntityData(client, "ag.session");
} }
if(client.console) { if(client.console) {

View File

@@ -102,12 +102,12 @@ let busRoutes = [
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function getNextStopOnBusRoute(client) { function getNextStopOnBusRoute(client) {
if(client.getData("ag.busRoute") && client.getData("ag.lastBusStop")) { if(getEntityData(client, "ag.busRoute") && getEntityData(client, "ag.lastBusStop")) {
if(!isGoingToLastStopOnBusRoute(client)) { if(!isGoingToLastStopOnBusRoute(client)) {
return busRoutes[server.game][client.getData("ag.busRoute")][client.getData("ag.lastBusStop")+1]; return busRoutes[server.game][getEntityData(client, "ag.busRoute")][getEntityData(client, "ag.lastBusStop")+1];
} else { } else {
let slot = busRoutes[server.game][client.getData("ag.busRoute")].length-1; let slot = busRoutes[server.game][getEntityData(client, "ag.busRoute")].length-1;
return busRoutes[server.game][client.getData("ag.busRoute")][slot]; return busRoutes[server.game][getEntityData(client, "ag.busRoute")][slot];
} }
} }
} }
@@ -115,8 +115,8 @@ function getNextStopOnBusRoute(client) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function isGoingToLastStopOnBusRoute(client) { function isGoingToLastStopOnBusRoute(client) {
if(client.getData("ag.busRoute") && client.getData("ag.lastBusStop")) { if(getEntityData(client, "ag.busRoute") && getEntityData(client, "ag.lastBusStop")) {
if(client.getData("ag.lastBusStop")+1 == busRoutes[server.game][client.getData("ag.busRoute")].length-1) { if(getEntityData(client, "ag.lastBusStop")+1 == busRoutes[server.game][getEntityData(client, "ag.busRoute")].length-1) {
return true; return true;
} }
} }

View File

@@ -1681,7 +1681,7 @@ function processPlayerDeath(client) {
} else { } else {
spawnPlayer(client, closestHospital.position, closestHospital.heading, getClientCurrentSubAccount(client).skin); spawnPlayer(client, closestHospital.position, closestHospital.heading, getClientCurrentSubAccount(client).skin);
} }
client.getData("ag.spawned", true, true); getEntityData(client, "ag.spawned", true, true);
setTimeout(function() { setTimeout(function() {
triggerNetworkEvent("ag.fadeCamera", client, true, 1.0); triggerNetworkEvent("ag.fadeCamera", client, true, 1.0);
triggerNetworkEvent("ag.control", client, true); triggerNetworkEvent("ag.control", client, true);

View File

@@ -61,3 +61,31 @@ function isNull(val) {
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function getEntityData(entity, dataName) {
return entity.getData(dataName);
}
// ---------------------------------------------------------------------------
function setEntityData(entity, dataName, dataValue, syncToClients = true) {
if(!isNull(server)) {
return entity.setData(dataName, dataValue, syncToClients);
} else {
return entity.setData(dataName, dataValue);
}
}
// ---------------------------------------------------------------------------
function removeEntityData(entity, dataName) {
return entity.removeData(dataName);
}
// ---------------------------------------------------------------------------
function doesEntityDataExist(entity, dataName) {
return (entity.getData(dataName) != null);
}
// ---------------------------------------------------------------------------