Use new native util functions
This commit is contained in:
@@ -123,16 +123,16 @@ function updateNametags(element) {
|
||||
let colour = COLOUR_WHITE;
|
||||
let afk = false;
|
||||
|
||||
if(client.getData("ag.name") != null) {
|
||||
name = client.getData("ag.name");
|
||||
if(getEntityData(client, "ag.name") != null) {
|
||||
name = getEntityData(client, "ag.name");
|
||||
}
|
||||
|
||||
if(client.getData("ag.afk") != null) {
|
||||
if(getEntityData(client, "ag.afk") != null) {
|
||||
afk = true;
|
||||
}
|
||||
|
||||
if(client.getData("ag.colour") != null) {
|
||||
colour = client.getData("ag.colour");
|
||||
if(getEntityData(client, "ag.colour") != null) {
|
||||
colour = getEntityData(client, "ag.colour");
|
||||
}
|
||||
|
||||
drawNametag(screenPos[0], screenPos[1], health, armour, name, 0, 1.0-distance/nametagDistance, distance, colour, afk, element.skin);
|
||||
|
||||
@@ -442,7 +442,7 @@ function loginSuccess(client) {
|
||||
if(getClientData(client).subAccounts.length == 0) {
|
||||
if(getServerConfig().useGUI) {
|
||||
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 {
|
||||
messageClientAlert(client, `You have no characters. Use /newchar to make one.`);
|
||||
}
|
||||
@@ -492,7 +492,7 @@ function createAccount(name, password, email = "") {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function checkLogin(client, password) {
|
||||
let loginAttemptsRemaining = client.getData("ag.loginAttemptsRemaining")-1;
|
||||
let loginAttemptsRemaining = getEntityData(client, "ag.loginAttemptsRemaining")-1;
|
||||
|
||||
if(isClientLoggedIn(client)) {
|
||||
if(getServerConfig().useGUI) {
|
||||
@@ -629,7 +629,7 @@ function checkRegistration(client, password, confirmPassword = "", emailAddress
|
||||
if(getServerConfig().useGUI) {
|
||||
triggerNetworkEvent("ag.registrationSuccess", client);
|
||||
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 {
|
||||
messageClientAlert(client, `You have no characters. Use /newchar to make one.`);
|
||||
}
|
||||
@@ -686,7 +686,7 @@ function initClient(client) {
|
||||
|
||||
setTimeout(function() {
|
||||
let sessionId = saveSessionToDatabase(client);
|
||||
client.setData("ag.session", sessionId, false);
|
||||
setEntityData(client, "ag.session", sessionId, false);
|
||||
|
||||
clearChatBox(client);
|
||||
let tempAccountData = loadAccountFromName(client.name);
|
||||
|
||||
@@ -553,8 +553,8 @@ function getClosestBusinessEntrance(position) {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isPlayerInAnyBusiness(player) {
|
||||
if(player.getData("ag.inBusiness")) {
|
||||
function isPlayerInAnyBusiness(client) {
|
||||
if(doesEntityDataExist(client, "ag.inBusiness")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -563,9 +563,9 @@ function isPlayerInAnyBusiness(player) {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getPlayerBusiness(player) {
|
||||
if(player.getData("ag.inBusiness")) {
|
||||
return player.getData("ag.inBusiness");
|
||||
function getPlayerBusiness(client) {
|
||||
if(doesEntityDataExist(client, "ag.inBusiness")) {
|
||||
return getEntityData(client, "ag.inBusiness");
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -658,8 +658,8 @@ function deleteBusiness(businessId) {
|
||||
|
||||
function removePlayersFromBusiness(businessId) {
|
||||
getClients().forEach(function(client) {
|
||||
if(client.getData("ag.inBusiness")) {
|
||||
if(client.getData("ag.inBusiness") == businessId) {
|
||||
if(doesEntityDataExist(client, "ag.inBusiness")) {
|
||||
if(getEntityData(client, "ag.inBusiness") == businessId) {
|
||||
exitBusiness(client);
|
||||
}
|
||||
}
|
||||
@@ -669,8 +669,8 @@ function removePlayersFromBusiness(businessId) {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function exitBusiness(client) {
|
||||
let businessId = client.getData("ag.inBusiness");
|
||||
if(client.player) {
|
||||
let businessId = getEntityData(client, "ag.inBusiness");
|
||||
if(isPlayerSpawned(client)) {
|
||||
triggerNetworkEvent("ag.interior", client, getServerData().businesses[businessId].entranceInterior);
|
||||
triggerNetworkEvent("ag.dimension", client, getServerData().businesses[businessId].entranceDimension);
|
||||
triggerNetworkEvent("ag.position", client, getServerData().businesses[businessId].entrancePosition);
|
||||
|
||||
@@ -35,11 +35,11 @@ addNetworkHandler("ag.onPlayerExitSphere", function(client, sphere) {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.promptAnswerNo", function(client) {
|
||||
if(!client.getData("ag.prompt")) {
|
||||
if(!getEntityData(client, "ag.prompt")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(client.getData("ag.prompt")) {
|
||||
switch(getEntityData(client, "ag.prompt")) {
|
||||
case AG_PROMPT_CREATEFIRSTCHAR:
|
||||
triggerNetworkEvent("ag.showError", client, "You don't have a character to play. Goodbye!", "No Characters");
|
||||
setTimeout(function() { client.disconnect(); }, 5000);
|
||||
@@ -55,11 +55,11 @@ addNetworkHandler("ag.promptAnswerNo", function(client) {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.promptAnswerYes", function(client) {
|
||||
if(!client.getData("ag.prompt")) {
|
||||
if(!getEntityData(client, "ag.prompt")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(client.getData("ag.prompt")) {
|
||||
switch(getEntityData(client, "ag.prompt")) {
|
||||
case AG_PROMPT_CREATEFIRSTCHAR:
|
||||
triggerNetworkEvent("ag.showNewCharacter", client);
|
||||
break;
|
||||
@@ -92,7 +92,7 @@ addNetworkHandler("ag.onPlayerEnterSphere", function(client, sphere) {
|
||||
|
||||
addNetworkHandler("ag.afk", function(client, afkState) {
|
||||
if(afkState) {
|
||||
client.setData("ag.afk", true, true);
|
||||
setEntityData(client, "ag.afk", true, true);
|
||||
} else {
|
||||
client.removeData("ag.afk");
|
||||
}
|
||||
@@ -125,16 +125,16 @@ addNetworkHandler("ag.heldKey", function(client, key) {
|
||||
|
||||
addNetworkHandler("ag.player.sync", function(client, position, heading) {
|
||||
//console.log(`POS: ${position}, X: ${position.x}, Y: ${position.y}, Z: ${position.z}`);
|
||||
client.setData("ag.position", position, true);
|
||||
client.setData("ag.heading", heading, true);
|
||||
setEntityData(client, "ag.position", position, true);
|
||||
setEntityData(client, "ag.heading", heading, true);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.player.death", function(client, position, heading) {
|
||||
//console.log(`POS: ${position}, X: ${position.x}, Y: ${position.y}, Z: ${position.z}`);
|
||||
client.setData("ag.position", position, true);
|
||||
client.setData("ag.heading", heading, true);
|
||||
setEntityData(client, "ag.position", position, true);
|
||||
setEntityData(client, "ag.heading", heading, true);
|
||||
processPlayerDeath(client);
|
||||
});
|
||||
|
||||
@@ -146,16 +146,15 @@ addNetworkHandler("ag.veh.sync", function(client, syncId, position, heading) {
|
||||
vehicleData.syncPosition = position;
|
||||
vehicleData.syncHeading = heading;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.iv.veh", function(client, syncId) {
|
||||
addNetworkHandler("ag.player.vehicle", function(client, syncId) {
|
||||
if(syncId == -1) {
|
||||
client.removeData("ag.vehicle");
|
||||
} else {
|
||||
client.setData("ag.vehicle", syncId, true);
|
||||
setEntityData(client, "ag.vehicle", syncId, true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -343,10 +343,14 @@ function setSnowingCommand(command, params, client) {
|
||||
}
|
||||
|
||||
let splitParams = params.split();
|
||||
let fallingSnow = toInteger(splitParams[0]) || 0;
|
||||
let groundSnow = toInteger(splitParams[1]) || 0;
|
||||
let fallingSnow = splitParams[0] || 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))}`);
|
||||
updateServerRules();
|
||||
|
||||
@@ -190,16 +190,16 @@ function submitIdea(client, ideaText) {
|
||||
let session = 0;
|
||||
let databaseId = 0;
|
||||
|
||||
if(client.getData("ag.position")) {
|
||||
position = client.getData("ag.position");
|
||||
if(getEntityData(client, "ag.position")) {
|
||||
position = getEntityData(client, "ag.position");
|
||||
}
|
||||
|
||||
if(client.getData("ag.heading")) {
|
||||
heading = client.getData("ag.heading");
|
||||
if(getEntityData(client, "ag.heading")) {
|
||||
heading = getEntityData(client, "ag.heading");
|
||||
}
|
||||
|
||||
if(client.getData("ag.session")) {
|
||||
session = client.getData("ag.session");
|
||||
if(getEntityData(client, "ag.session")) {
|
||||
session = getEntityData(client, "ag.session");
|
||||
}
|
||||
|
||||
if(client.console) {
|
||||
@@ -223,16 +223,16 @@ function submitBugReport(client, bugText) {
|
||||
let session = 0;
|
||||
let databaseId = 0;
|
||||
|
||||
if(client.getData("ag.position")) {
|
||||
position = client.getData("ag.position");
|
||||
if(getEntityData(client, "ag.position")) {
|
||||
position = getEntityData(client, "ag.position");
|
||||
}
|
||||
|
||||
if(client.getData("ag.heading")) {
|
||||
heading = client.getData("ag.heading");
|
||||
if(getEntityData(client, "ag.heading")) {
|
||||
heading = getEntityData(client, "ag.heading");
|
||||
}
|
||||
|
||||
if(client.getData("ag.session")) {
|
||||
session = client.getData("ag.session");
|
||||
if(getEntityData(client, "ag.session")) {
|
||||
session = getEntityData(client, "ag.session");
|
||||
}
|
||||
|
||||
if(client.console) {
|
||||
|
||||
@@ -102,12 +102,12 @@ let busRoutes = [
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getNextStopOnBusRoute(client) {
|
||||
if(client.getData("ag.busRoute") && client.getData("ag.lastBusStop")) {
|
||||
if(getEntityData(client, "ag.busRoute") && getEntityData(client, "ag.lastBusStop")) {
|
||||
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 {
|
||||
let slot = busRoutes[server.game][client.getData("ag.busRoute")].length-1;
|
||||
return busRoutes[server.game][client.getData("ag.busRoute")][slot];
|
||||
let slot = busRoutes[server.game][getEntityData(client, "ag.busRoute")].length-1;
|
||||
return busRoutes[server.game][getEntityData(client, "ag.busRoute")][slot];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,8 +115,8 @@ function getNextStopOnBusRoute(client) {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function isGoingToLastStopOnBusRoute(client) {
|
||||
if(client.getData("ag.busRoute") && client.getData("ag.lastBusStop")) {
|
||||
if(client.getData("ag.lastBusStop")+1 == busRoutes[server.game][client.getData("ag.busRoute")].length-1) {
|
||||
if(getEntityData(client, "ag.busRoute") && getEntityData(client, "ag.lastBusStop")) {
|
||||
if(getEntityData(client, "ag.lastBusStop")+1 == busRoutes[server.game][getEntityData(client, "ag.busRoute")].length-1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1681,7 +1681,7 @@ function processPlayerDeath(client) {
|
||||
} else {
|
||||
spawnPlayer(client, closestHospital.position, closestHospital.heading, getClientCurrentSubAccount(client).skin);
|
||||
}
|
||||
client.getData("ag.spawned", true, true);
|
||||
getEntityData(client, "ag.spawned", true, true);
|
||||
setTimeout(function() {
|
||||
triggerNetworkEvent("ag.fadeCamera", client, true, 1.0);
|
||||
triggerNetworkEvent("ag.control", client, true);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user