This commit is contained in:
Vortrex
2021-01-02 21:57:43 -06:00
14 changed files with 446 additions and 300 deletions

View File

@@ -8,20 +8,7 @@
// TYPE: Server (JavaScript) // TYPE: Server (JavaScript)
// =========================================================================== // ===========================================================================
let serverCommands = {}; let serverCommands = {
// ---------------------------------------------------------------------------
function initCommandScript() {
console.log("[Asshat.Command]: Initializing commands script ...");
serverCommands = loadCommandData();
console.log("[Asshat.Command]: Initialized commands script!");
}
// ---------------------------------------------------------------------------
function loadCommandData() {
let tempCommands = {
account: [ account: [
commandData("login", loginCommand, "<password>", getStaffFlagValue("none"), false, false), commandData("login", loginCommand, "<password>", getStaffFlagValue("none"), false, false),
commandData("register", registerCommand, "<password>", getStaffFlagValue("none"), false, false), commandData("register", registerCommand, "<password>", getStaffFlagValue("none"), false, false),
@@ -277,8 +264,13 @@ function loadCommandData() {
commandData("passenger", enterVehicleAsPassengerCommand, "", getStaffFlagValue("none"), true, true), commandData("passenger", enterVehicleAsPassengerCommand, "", getStaffFlagValue("none"), true, true),
], ],
} };
return tempCommands;
// ---------------------------------------------------------------------------
function initCommandScript() {
console.log("[Asshat.Command]: Initializing commands script ...");
console.log("[Asshat.Command]: Initialized commands script!");
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -422,14 +414,25 @@ function enableAllCommandsByType(command, params, client) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function onPlayerCommand(event, client, command, params) { function onPlayerCommand(event, client, command, params) {
let commandData = getCommand(command); processPlayerCommand(command, params, client)
}
addEventHandler("OnPlayerCommand", onPlayerCommand);
// ---------------------------------------------------------------------------
function processPlayerCommand(command, params, client) {
if(builtInCommands.indexOf(toLowerCase(command)) != -1) {
return true;
}
let commandData = getCommand(toLowerCase(command));
let paramsDisplay = params; let paramsDisplay = params;
if(areParamsEmpty(params)) { if(areParamsEmpty(params)) {
paramsDisplay = "" paramsDisplay = "";
} }
if(!commandData) { if(!doesCommandExist(toLowerCase(command))) {
console.warn(`[Asshat.Command] ${getPlayerDisplayForConsole(client)} attempted to use command, but failed (invalid command): /${command} ${paramsDisplay}`); console.warn(`[Asshat.Command] ${getPlayerDisplayForConsole(client)} attempted to use command, but failed (invalid command): /${command} ${paramsDisplay}`);
messagePlayerError(client, `The command [#AAAAAA]/${command} [#FFFFFF]does not exist! Use /help for commands and information.`); messagePlayerError(client, `The command [#AAAAAA]/${command} [#FFFFFF]does not exist! Use /help for commands and information.`);
return false; return false;
@@ -441,7 +444,7 @@ function onPlayerCommand(event, client, command, params) {
return false; return false;
} }
if(doesCommandRequireLogin(command)) { if(doesCommandRequireLogin(toLowerCase(command))) {
if(!isPlayerLoggedIn(client)) { if(!isPlayerLoggedIn(client)) {
console.warn(`[Asshat.Command] ${getPlayerDisplayForConsole(client)} attempted to use command, but failed (requires login first): /${command} ${paramsDisplay}`); console.warn(`[Asshat.Command] ${getPlayerDisplayForConsole(client)} attempted to use command, but failed (requires login first): /${command} ${paramsDisplay}`);
messagePlayerError(client, `You must be logged in to use the [#AAAAAA]/${command} [#FFFFFF]command!`); messagePlayerError(client, `You must be logged in to use the [#AAAAAA]/${command} [#FFFFFF]command!`);
@@ -457,16 +460,15 @@ function onPlayerCommand(event, client, command, params) {
// } // }
//} //}
if(!doesPlayerHaveStaffPermission(client, getCommandRequiredPermissions(command))) { if(!doesPlayerHaveStaffPermission(client, getCommandRequiredPermissions(toLowerCase(command)))) {
console.warn(`[Asshat.Command] ${getPlayerDisplayForConsole(client)} attempted to use command, but failed (no permission): /${command} ${paramsDisplay}`); console.warn(`[Asshat.Command] ${getPlayerDisplayForConsole(client)} attempted to use command, but failed (no permission): /${command} ${paramsDisplay}`);
messagePlayerError(client, `You do not have permission to use the [#AAAAAA]/${command} [#FFFFFF]command!`); messagePlayerError(client, `You do not have permission to use the [#AAAAAA]/${toLowerCase(command)} [#FFFFFF]command!`);
return false; return false;
} }
console.log(`[Asshat.Command] ${getPlayerDisplayForConsole(client)} used command: /${command} ${paramsDisplay}`); console.log(`[Asshat.Command] ${getPlayerDisplayForConsole(client)} used command: /${command} ${paramsDisplay}`);
commandData.handlerFunction(command, params, client); commandData.handlerFunction(toLowerCase(command), params, client);
} }
addEventHandler("OnPlayerCommand", onPlayerCommand);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -493,3 +495,13 @@ function listAllCommands() {
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function doesCommandExist(command) {
if(getCommandData(command)) {
return true;
}
return false;
}
// ---------------------------------------------------------------------------

View File

@@ -10,6 +10,13 @@
function initDeveloperScript() { function initDeveloperScript() {
console.log("[Asshat.Developer]: Initializing developer script ..."); console.log("[Asshat.Developer]: Initializing developer script ...");
// Use GTAC command handlers for these since they need to be available on console
addCommandHandler("sc", executeServerCodeCommand);
addCommandHandler("cc", executeServerCodeCommand);
addCommandHandler("docmd", simulateCommandForPlayer);
addCommandHandler("allcmd", simulateCommandForAllPlayers);
console.log("[Asshat.Developer]: Developer script initialized successfully!"); console.log("[Asshat.Developer]: Developer script initialized successfully!");
return true; return true;
} }

View File

@@ -8,6 +8,7 @@
// TYPE: Server (JavaScript) // TYPE: Server (JavaScript)
// =========================================================================== // ===========================================================================
/*
addEventHandler("OnDiscordCommand", function(command, params, discordUser) { addEventHandler("OnDiscordCommand", function(command, params, discordUser) {
let commandData = getCommand(command); let commandData = getCommand(command);
@@ -28,6 +29,7 @@ addEventHandler("OnDiscordCommand", function(command, params, discordUser) {
commandData.handlerFunction(command, params, discordUser); commandData.handlerFunction(command, params, discordUser);
}); });
*/
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@@ -253,7 +253,7 @@ function processPlayerDeath(client, position) {
function processPedSpawn(ped) { function processPedSpawn(ped) {
if(ped.type == ELEMENT_PLAYER) { if(ped.type == ELEMENT_PLAYER) {
setTimeout(processPlayerSpawn, 1000, ped); setTimeout(processPlayerSpawn, 500, ped);
} }
} }
@@ -272,7 +272,7 @@ function processPlayerSpawn(ped) {
return false; return false;
} }
if(!getPlayerData(client).switchingCharacter) { if(!isPlayerSwitchingCharacter(client)) {
return false; return false;
} }
@@ -289,9 +289,7 @@ function processPlayerSpawn(ped) {
setPlayerHeading(client, tempSubAccount.spawnHeading); setPlayerHeading(client, tempSubAccount.spawnHeading);
setPlayerInterior(client, tempSubAccount.interior); setPlayerInterior(client, tempSubAccount.interior);
setPlayerVirtualWorld(client, tempSubAccount.dimension); setPlayerVirtualWorld(client, tempSubAccount.dimension);
setTimeout(function() {
updatePlayerCash(client); updatePlayerCash(client);
}, 1000);
}, 500); }, 500);
updateAllPlayerNameTags(); updateAllPlayerNameTags();
@@ -301,3 +299,9 @@ function processPlayerSpawn(ped) {
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
addEventHandler("OnPedSpawn", function(event, ped) {
processPedSpawn(ped);
});
// ---------------------------------------------------------------------------

View File

@@ -13,6 +13,8 @@ function initHouseScript() {
getServerData().houses = loadHousesFromDatabase(); getServerData().houses = loadHousesFromDatabase();
createAllHousePickups(); createAllHousePickups();
createAllHouseBlips(); createAllHouseBlips();
setAllHouseIndexes();
console.log("[Asshat.House]: House script initialized successfully!"); console.log("[Asshat.House]: House script initialized successfully!");
return true; return true;
} }
@@ -698,3 +700,11 @@ function exitHouse(client) {
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function setAllHouseIndexes() {
for(let i in getServerData().houses) {
getServerData().houses[i].index = i;
}
}
// ---------------------------------------------------------------------------

View File

@@ -709,18 +709,19 @@ function takeJob(client, jobId) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function reloadAllJobsCommand(command, params, client) { function reloadAllJobsCommand(command, params, client) {
for(let i in getServerData().jobs) { forceAllPlayersToStopWorking();
for(let j in getServerData().jobs[i].locations) {
destroyElement(getServerData().jobs[i].locations[j].blip);
destroyElement(getServerData().jobs[i].locations[j].pickup);
}
}
//forceAllPlayersToStopWorking();
getServerData().jobs = null; getServerData().jobs = null;
getServerData().jobs = loadJobsFromDatabase(); getServerData().jobs = loadJobsFromDatabase();
createAllJobPickups();
createAllJobBlips(); for(let i in getServerData().jobs) {
for(let j in getServerData().jobs[i].locations) {
deleteJobLocationPickup(i, j);
deleteJobLocationBlip(i, j);
createJobLocationPickup(i, j);
createJobLocationBlip(i, j);
}
}
messageAdminAction(`All server jobs have been reloaded by an admin!`); messageAdminAction(`All server jobs have been reloaded by an admin!`);
} }
@@ -753,6 +754,7 @@ function deleteJobLocationCommand(command, params, client) {
messageAdmins(`[#AAAAAA]${client.name} [#FFFFFF]deleted location [#AAAAAA]${closestJobLocation.databaseId} [#FFFFFF]for the [#AAAAAA]${jobData.name} [#FFFFFF]job`); messageAdmins(`[#AAAAAA]${client.name} [#FFFFFF]deleted location [#AAAAAA]${closestJobLocation.databaseId} [#FFFFFF]for the [#AAAAAA]${jobData.name} [#FFFFFF]job`);
quickDatabaseQuery(`DELETE FROM job_loc WHERE job_loc_id = ${closestJobLocation.databaseId}`);
deleteJobLocation(closestJobLocation); deleteJobLocation(closestJobLocation);
getJobData(closestJobLocation.job).locations.splice(getClosestJobLocation.index, 1); getJobData(closestJobLocation.job).locations.splice(getClosestJobLocation.index, 1);
} }
@@ -1237,7 +1239,7 @@ function setAllJobDataIndexes() {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function createJobLocation(job, position, interior, dimension) { function createJobLocation(job, position, interior, dimension) {
let jobLocationData = serverClasses.jobLocationData(false); let jobLocationData = new serverClasses.jobLocationData(false);
jobLocationData.position = position; jobLocationData.position = position;
jobLocationData.job = job; jobLocationData.job = job;
jobLocationData.interior = interior; jobLocationData.interior = interior;
@@ -1417,3 +1419,60 @@ function saveAllJobsToDatabase() {
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function deleteJobLocationBlip(jobId, locationId) {
if(getJobData(jobId).locations[locationId].blip != null) {
removeFromWorld(getJobData(jobId).locations[locationId].blip);
destroyElement(getJobData(jobId).locations[locationId].blip);
getJobData(jobId).locations[locationId].blip = null;
}
}
// ---------------------------------------------------------------------------
function deleteJobLocationPickup(jobId, locationId) {
if(getJobData(jobId).locations[locationId].pickup != null) {
removeFromWorld(getJobData(jobId).locations[locationId].pickup);
destroyElement(getJobData(jobId).locations[locationId].pickup);
getJobData(jobId).locations[locationId].pickup = null;
}
}
// ---------------------------------------------------------------------------
function createJobLocationPickup(jobId, locationId) {
if(getJobData(jobId).pickupModel != -1) {
let pickupModelId = getGameConfig().pickupModels[getServerGame()].job;
if(getJobData(jobId).pickupModel != 0) {
pickupModelId = getJobData(jobId).pickupModel;
}
getJobData(jobId).locations[locationId].pickup = gta.createPickup(pickupModelId, getJobData(jobId).locations[locationId].position);
getJobData(jobId).locations[locationId].pickup.onAllDimensions = false;
getJobData(jobId).locations[locationId].pickup.dimension = getJobData(jobId).locations[locationId].dimension;
getJobData(jobId).locations[locationId].pickup.setData("ag.owner.type", AG_PICKUP_JOB, false);
getJobData(jobId).locations[locationId].pickup.setData("ag.owner.id", jobId, false);
getJobData(jobId).locations[locationId].pickup.setData("ag.label.type", AG_LABEL_JOB, true);
addToWorld(getJobData(jobId).locations[locationId].pickup);
}
}
// ---------------------------------------------------------------------------
function createJobLocationBlip(jobId, locationId) {
if(getJobData(jobId).blipModel != -1) {
let blipModelId = getGameConfig().blipSprites[getServerGame()].job;
if(getJobData(jobId).blipModel != 0) {
blipModelId = getJobData(jobId).blipModel;
}
getJobData(jobId).locations[locationId].blip = gta.createBlip(getJobData(jobId).locations[locationId].position, blipModelId, getColourByType("job"));
getJobData(jobId).locations[locationId].pickup.onAllDimensions = false;
getJobData(jobId).locations[locationId].pickup.dimension = getJobData(jobId).locations[locationId].dimension;
addToWorld(getJobData(jobId).locations[locationId].pickup);
}
}
// ---------------------------------------------------------------------------

View File

@@ -406,7 +406,9 @@ function showCurrentBusStop(client) {
function arrivedAtBusStop(client) { function arrivedAtBusStop(client) {
if(isLastStopOnBusRoute(getPlayerData(client).jobRouteIsland, getPlayerData(client).jobRoute, getPlayerData(client).jobRouteStop)) { if(isLastStopOnBusRoute(getPlayerData(client).jobRouteIsland, getPlayerData(client).jobRoute, getPlayerData(client).jobRouteStop)) {
respawnVehicle(getPlayerData(client).jobRouteVehicle); respawnVehicle(getPlayerData(client).jobRouteVehicle);
messagePlayerNormal(client, `You finished the ${getBusRouteData(getPlayerData(client).jobRouteIsland, getPlayerData(client).jobRoute).name} bus route! Your bus has been returned to the bus depot.`, getColourByName("yellow")); messagePlayerNormal(client, `You finished the ${getBusRouteData(getPlayerData(client).jobRouteIsland, getPlayerData(client).jobRoute).name} bus route! You earned $${getBusRouteData(getPlayerData(client).jobRouteIsland, getPlayerData(client).jobRoute).payout} and your bus has been returned to the bus depot.`, getColourByName("yellow"));
getPlayerCurrentSubAccount(client).cash += getBusRouteData(getPlayerData(client).jobRouteIsland, getPlayerData(client).jobRoute).payout;
updatePlayerCash(client);
getPlayerData(client).jobRouteVehicle = false; getPlayerData(client).jobRouteVehicle = false;
getPlayerData(client).jobRoute = 0; getPlayerData(client).jobRoute = 0;
getPlayerData(client).jobRouteStop = 0; getPlayerData(client).jobRouteStop = 0;

View File

@@ -116,7 +116,9 @@ function showCurrentGarbageStop(client) {
function arrivedAtGarbageStop(client) { function arrivedAtGarbageStop(client) {
if(isLastStopOnGarbageRoute(getPlayerData(client).jobRouteIsland, getPlayerData(client).jobRoute, getPlayerData(client).jobRouteStop)) { if(isLastStopOnGarbageRoute(getPlayerData(client).jobRouteIsland, getPlayerData(client).jobRoute, getPlayerData(client).jobRouteStop)) {
respawnVehicle(getPlayerData(client).jobRouteVehicle); respawnVehicle(getPlayerData(client).jobRouteVehicle);
messagePlayerNormal(client, `You finished the ${getGarbageRouteData(getPlayerData(client).jobRouteIsland, getPlayerData(client).jobRoute).name} garbage route! Your trashmaster has been returned to the garbage depot.`, getColourByName("yellow")); messagePlayerNormal(client, `You finished the ${getGarbageRouteData(getPlayerData(client).jobRouteIsland, getPlayerData(client).jobRoute).name} garbage route! You earned $${getGarbageRouteData(getPlayerData(client).jobRouteIsland, getPlayerData(client).jobRoute).payout} and your trashmaster has been returned to the garbage depot.`, getColourByName("yellow"));
getPlayerCurrentSubAccount(client).cash += getGarbageRouteData(getPlayerData(client).jobRouteIsland, getPlayerData(client).jobRoute).payout;
updatePlayerCash(client);
getPlayerData(client).jobRouteVehicle = false; getPlayerData(client).jobRouteVehicle = false;
getPlayerData(client).jobRoute = 0; getPlayerData(client).jobRoute = 0;
getPlayerData(client).jobRouteStop = 0; getPlayerData(client).jobRouteStop = 0;

View File

@@ -136,9 +136,14 @@ function enterExitPropertyCommand(command, params, client) {
setPlayerInterior(client, inHouse.entranceInterior); setPlayerInterior(client, inHouse.entranceInterior);
setTimeout(function() { setTimeout(function() {
fadeCamera(client, true, 1.0); fadeCamera(client, true, 1.0);
setTimeout(function() {
enableCityAmbienceForPlayer(client);
clearPlayerOwnedPeds(client);
}, 2000);
}, 1000); }, 1000);
}, 1100); }, 1100);
removeEntityData(client, "ag.inHouse"); removeEntityData(client, "ag.inHouse");
} }
return true; return true;
} }
@@ -159,9 +164,14 @@ function enterExitPropertyCommand(command, params, client) {
setPlayerInterior(client, inBusiness.entranceInterior); setPlayerInterior(client, inBusiness.entranceInterior);
setTimeout(function() { setTimeout(function() {
fadeCamera(client, true, 1.0); fadeCamera(client, true, 1.0);
setTimeout(function() {
enableCityAmbienceForPlayer(client);
clearPlayerOwnedPeds(client);
}, 2000);
}, 1000); }, 1000);
}, 1100); }, 1100);
removeEntityData(client, "ag.inBusiness"); removeEntityData(client, "ag.inBusiness");
console.log(`[Asshat.Misc] ${getPlayerDisplayForConsole(client)} entered business ${inBusiness.name}[${inBusiness.index}/${inBusiness.databaseId}]`);
} }
return true; return true;
} }
@@ -184,6 +194,7 @@ function enterExitPropertyCommand(command, params, client) {
meActionToNearbyPlayers(client, "opens the door and enters the business"); meActionToNearbyPlayers(client, "opens the door and enters the business");
fadeCamera(client, false, 1.0); fadeCamera(client, false, 1.0);
disableCityAmbienceForPlayer(client);
setTimeout(function() { setTimeout(function() {
setPlayerPosition(client, closestBusiness.exitPosition); setPlayerPosition(client, closestBusiness.exitPosition);
setPlayerHeading(client, closestBusiness.exitRotation); setPlayerHeading(client, closestBusiness.exitRotation);
@@ -218,6 +229,7 @@ function enterExitPropertyCommand(command, params, client) {
fadeCamera(client, false, 1.0); fadeCamera(client, false, 1.0);
disableCityAmbienceForPlayer(client);
setTimeout(function() { setTimeout(function() {
setPlayerPosition(client, closestHouse.exitPosition); setPlayerPosition(client, closestHouse.exitPosition);
setPlayerHeading(client, closestHouse.exitRotation); setPlayerHeading(client, closestHouse.exitRotation);
@@ -228,7 +240,6 @@ function enterExitPropertyCommand(command, params, client) {
}, 1000); }, 1000);
}, 1100); }, 1100);
setEntityData(client, "ag.inHouse", closestHouseId); setEntityData(client, "ag.inHouse", closestHouseId);
return true; return true;
} }
} }

View File

@@ -315,3 +315,9 @@ function getCharacterFullName(client) {
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function isPlayerSwitchingCharacter(client) {
return getPlayerData(client).switchingCharacter;
}
// ---------------------------------------------------------------------------

View File

@@ -37,6 +37,7 @@ function initTimers() {
serverTimers.updateTimeRuleTimer = setInterval(updateTimeRule, 1000); serverTimers.updateTimeRuleTimer = setInterval(updateTimeRule, 1000);
serverTimers.updatePingsTimer = setInterval(updatePings, 5000); serverTimers.updatePingsTimer = setInterval(updatePings, 5000);
serverTimers.vehicleRentTimer = setInterval(vehicleRentCheck, 60000); serverTimers.vehicleRentTimer = setInterval(vehicleRentCheck, 60000);
serverTimers.garbageCollectorTimer = setInterval(collectAllGarbage, 60000);
} }
} }

View File

@@ -1668,6 +1668,27 @@ function updatePlayerCash(client) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function setPlayerCash(client, amount) {
getPlayerCurrentSubAccount(client).cash = amount;
updatePlayerCash(client);
}
// ---------------------------------------------------------------------------
function givePlayerCash(client, amount) {
getPlayerCurrentSubAccount(client).cash += amount;
updatePlayerCash(client);
}
// ---------------------------------------------------------------------------
function takePlayerCash(client, amount) {
getPlayerCurrentSubAccount(client).cash -= amount;
updatePlayerCash(client);
}
// ---------------------------------------------------------------------------
function clearChatBox(client) { function clearChatBox(client) {
//gta.messages.clear(); //gta.messages.clear();
for(let i = 0; i <= 20; i++) { for(let i = 0; i <= 20; i++) {
@@ -1834,6 +1855,12 @@ async function waitUntil(condition) {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
function resetClientStuff(client) { function resetClientStuff(client) {
console.log(`[Asshat.Utilities] Resetting client data for ${getPlayerDisplayForConsole(client)}`);
if(!getPlayerData(client)) {
return false;
}
if(isPlayerOnJobRoute(client)) { if(isPlayerOnJobRoute(client)) {
stopJobRoute(client); stopJobRoute(client);
} }

View File

@@ -8,6 +8,9 @@
// TYPE: Shared (JavaScript) // TYPE: Shared (JavaScript)
// =========================================================================== // ===========================================================================
"use strict";
setErrorMode(RESOURCEERRORMODE_STRICT);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function toInteger(val) { function toInteger(val) {