Add vehicles, util funcs. Fix jobs

This commit is contained in:
VortrexFTW
2020-09-05 02:30:39 -05:00
parent c536fcd6ef
commit 29e273bf60
9 changed files with 155 additions and 81 deletions

View File

@@ -10,48 +10,53 @@
function initVehicleScript() {
console.log("[Asshat.Clan]: Initializing vehicle script ...");
dd console.log("[Asshat.Vehicle]: Initializing vehicle script ...");
serverData.vehicles = loadVehiclesFromDatabase();
spawnAllVehicles();
addVehicleCommandHandlers();
console.log("[Asshat.Clan]: Vehicle script initialized successfully!");
console.log("[Asshat.Vehicle]: Vehicle script initialized successfully!");
return true;
}
// ---------------------------------------------------------------------------
function addVehicleCommandHandlers() {
console.log("[Asshat.Clan]: Adding vehicle command handlers ...");
let vehicleCommands = vehicleCommands.clan;
console.log("[Asshat.Vehicle]: Adding vehicle command handlers ...");
let vehicleCommands = serverCommands.vehicle;
for(let i in vehicleCommands) {
addCommandHandler(vehicleCommands[i].command, vehicleCommands[i].handlerFunction);
}
console.log("[Asshat.Clan]: Vehicle command handlers added successfully!");
console.log("[Asshat.Vehicle]: Vehicle command handlers added successfully!");
return true;
}
function loadVehiclesFromDatabase() {
let dbConnection = connectToDatabase();
if(dbConnection) {
accountName = dbConnection.escapeString(accountName);
let dbQueryString = format("SELECT * FROM `veh_main` WHERE `veh_game` = %d", serverGame);
let dbQuery = dbConnection.query(dbQueryString);
if(dbQuery) {
while(dbAssoc = dbQuery.fetchAssoc()) {
let vehicleData = new vehicleData(dbAssoc);
serverData.vehicles.push(vehicleData);
}
}
disconnectFromDatabase(dbConnection);
}
return false;
}
// ---------------------------------------------------------------------------
function saveVehiclesToDatabase() {
function loadVehiclesFromDatabase() {
console.log("[Asshat.Vehicle]: Loading vehicles from database ...");
let dbConnection = connectToDatabase();
let tempVehicles = [];
let dbAssoc;
if(dbConnection) {
let dbQueryString = `SELECT * FROM veh_main WHERE veh_server = ${serverId}`;
let dbQuery = dbConnection.query(dbQueryString);
if(dbQuery) {
while(dbAssoc = dbQuery.fetchAssoc()) {
let tempVehicleData = new serverClasses.vehicleData(dbAssoc);
tempVehicles.push(tempVehicleData);
}
dbQuery.free();
}
disconnectFromDatabase(dbConnection);
}
console.log("[Asshat.Vehicle]: " + tempVehicles.length + " vehicles loaded from database successfully!");
return tempVehicles;
}
// ---------------------------------------------------------------------------
function saveAllVehiclesToDatabase() {
let vehicles = serverData.vehicles;
for(let i in vehicles) {
saveVehicleToDatabase(vehicles[i]);
@@ -72,7 +77,7 @@ function saveVehicleToDatabase(vehicleData) {
// dbQueryColourFields = "`veh_col1_rgba`, `veh_col2_rgba`, `veh_col3_rgba`, `veh_col4_rgba`";
// dbQueryColourValues = vehicleData.colour1Red, `veh_col1_g`, `veh_col1_b`, `veh_col1_a`, `veh_col2_r`, `veh_col2_g`, `veh_col2_b`, `veh_col2_a`, `veh_col3_r`, `veh_col3_g`, `veh_col3_b`, `veh_col3_a`, `veh_col4_r`, `veh_col4_g`, `veh_col4_b`, `veh_col4_a`,";
//}
let dbQueryString = "INSERT INTO `veh_main` (`veh_model`, `veh_pos_x`, `veh_pos_y`, `veh_pos_z`, veh_owner_type`, `veh_owner_id`) VALUES (" + vehicleData.modelId + ", " + vehicleData.spawnPosition.x + ", " + vehicleData.spawnPosition.y + ", " + vehicleData.spawnPosition.z + ", " + vehicleData.spawnRotation.z + ", " + vehicleData.ownerType + ", " + vehicleData.ownerId + ");";
let dbQueryString = "INSERT INTO `veh_main` (`veh_model`, `veh_pos_x`, `veh_pos_y`, `veh_pos_z`, veh_owner_type`, `veh_owner_id`) VALUES (" + vehicleData.model + ", " + vehicleData.spawnPosition.x + ", " + vehicleData.spawnPosition.y + ", " + vehicleData.spawnPosition.z + ", " + vehicleData.spawnRotation.z + ", " + vehicleData.ownerType + ", " + vehicleData.ownerId + ");";
let dbQuery = dbConnection.query(dbQueryString);
getVehicleData(vehicleData.vehicle).databaseId = dbConnection.insertId;
} else {
@@ -90,8 +95,9 @@ function saveVehicleToDatabase(vehicleData) {
function spawnAllVehicles() {
for(let i in serverData.vehicles) {
let vehicle = gta.createVehicle(serverData.vehicles[i].modelId, serverData.vehicles[i].spawnPosition, serverData.vehicles[i].spawnHeading);
vehicle.locked = serverData.vehicles[i].locked;
console.log(serverData.vehicles[i].spawnRotation);
let vehicle = gta.createVehicle(serverData.vehicles[i].model, serverData.vehicles[i].spawnPosition, serverData.vehicles[i].spawnRotation);
addToWorld(vehicle);
if(serverData.vehicles[i].colour1IsRGBA && serverData.vehicles[i].colour2IsRGBA) {
vehicle.setRGBColours(serverData.vehicles[i].colour1RGBA, serverData.vehicles[i].colour2RGBA);
@@ -102,11 +108,14 @@ function spawnAllVehicles() {
vehicle.colour4 = serverData.vehicles[i].colour4;
}
vehicle.engine = serverData.vehicles[i].engine;
vehicle.lights = serverData.vehicles[i].engine;
vehicle.engine = intToBool(serverData.vehicles[i].engine);
//vehicle.lights = intToBool(serverData.vehicles[i].lights);
//vehicle.health = serverData.vehicles[i].health;
//vehicle.position = serverData.vehicles[i].spawnPosition;
vehicle.heading = serverData.vehicles[i].spawnRotation;
addToWorld(vehicle);
vehicle.locked = intToBool(serverData.vehicles[i].locked);
serverData.vehicles[i].vehicle = vehicle;
vehicle.setData("ag.dataSlot", i, false);
@@ -122,8 +131,41 @@ function getVehicleData(vehicle) {
// ---------------------------------------------------------------------------
function saveAllVehiclesToDatabase() {
function vehicleLockCommand(command, params, client) {
if(getCommand(command).requireLogin) {
if(!isClientLoggedIn(client)) {
messageClientError(client, "You must be logged in to use this command!");
return false;
}
}
if(isClientFromDiscord(client)) {
if(!isCommandAllowedOnDiscord(command)) {
messageClientError(client, "That command isn't available on discord!");
return false;
}
}
if(!doesClientHaveStaffPermission(client, getCommandRequiredPermissions(command))) {
messageClientError(client, "You do not have permission to use this command!");
return false;
}
let closestVehicle = getClosestVehicle();
if((!client.player.vehicle && doesClientHaveVehicleKeys(client, closestVehicle) && closestVehicle.position.distance(client.player.position) <= 5) || client.player.vehicle) {
if(getVehicleData(closestVehicle).locked) {
closestVehicle.locked = false;
getVehicleData(closestVehicles).locked = false;
} else {
closestVehicle.locked = true;
getVehicleData(closestVehicles).locked = true;
}
}
if(areParamsEmpty(params)) {
messageClientSyntax(client, getCommandSyntaxText(command));
return false;
}
}
// ---------------------------------------------------------------------------