Lots of stuff in CS main.js
This commit is contained in:
@@ -8,8 +8,6 @@
|
||||
// TYPE: Client (JavaScript)
|
||||
// ===========================================================================
|
||||
|
||||
setErrorMode(RESOURCEERRORMODE_STRICT);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
let bigMessageFont = null;
|
||||
@@ -89,17 +87,41 @@ addNetworkHandler("ag.connectCamera", function(cameraPosition, cameraLookat) {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.restoreCamera", function() {
|
||||
console.log(`[Asshat.Main] Camera restored`);
|
||||
gta.restoreCamera(true);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.clearPeds", function() {
|
||||
console.log(`[Asshat.Main] Clearing all self-owned peds ...`);
|
||||
getElementsByType(ELEMENT_CIVILIAN).forEach(function(ped) {
|
||||
if(ped.isOwner) {
|
||||
destroyElement(ped);
|
||||
}
|
||||
});
|
||||
console.log(`[Asshat.Main] All self-owned peds cleared`);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.logo", function(state) {
|
||||
console.log(`[Asshat.Main] Server logo ${(state) ? "enabled" : "disabled"}`);
|
||||
showLogo = state;
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.ambience", function(state) {
|
||||
console.log(`[Asshat.Main] Ambient civilians and traffic ${(state) ? "enabled" : "disabled"}`);
|
||||
gta.setTrafficEnabled(state);
|
||||
if(gta.game != GAME_GTA_SA) {
|
||||
gta.setCiviliansEnabled(state);
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.runCode", function(code, returnTo) {
|
||||
let returnVal = "Nothing";
|
||||
try {
|
||||
@@ -111,17 +133,6 @@ addNetworkHandler("ag.runCode", function(code, returnTo) {
|
||||
triggerNetworkEvent("ag.runCodeSuccess", returnTo, returnVal, code);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addEventHandler("onPickupCollected", function(event, pickup, ped) {
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bindEventHandler("OnResourceStop", thisResource, function(event, resource) {
|
||||
|
||||
});
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function enterVehicleAsPassenger() {
|
||||
@@ -142,61 +153,18 @@ function getClosestVehicle(pos) {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.clearWeapons", function() {
|
||||
console.log(`[Asshat.Main] Clearing weapons`);
|
||||
localPlayer.clearWeapons();
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.giveWeapon", function(weaponId, ammo, active) {
|
||||
console.log(`[Asshat.Main] Giving weapon ${weaponId} with ${ammo} ammo`);
|
||||
localPlayer.giveWeapon(weaponId, ammo, active);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.showRegisterMessage", function() {
|
||||
showRegisterMessage = true;
|
||||
showLoginMessage = false;
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addNetworkHandler("ag.showLoginMessage", function() {
|
||||
showLoginMessage = true;
|
||||
showRegisterMessage = false;
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function syncVehicle(vehicle) {
|
||||
if(getEntityData(vehicle, "ag.lights") != null) {
|
||||
let lights = getEntityData(vehicle, "ag.lights");
|
||||
if(lights != vehicle.lights) {
|
||||
vehicle.lights = lights;
|
||||
}
|
||||
}
|
||||
|
||||
if(getEntityData(vehicle, "ag.engine") != null) {
|
||||
let engine = getEntityData(vehicle, "ag.engine");
|
||||
if(engine != vehicle.engine) {
|
||||
vehicle.engine = engine;
|
||||
}
|
||||
}
|
||||
|
||||
if(getEntityData(vehicle, "ag.siren") != null) {
|
||||
let siren = getEntityData(vehicle, "ag.siren");
|
||||
if(siren != vehicle.siren) {
|
||||
vehicle.siren = siren;
|
||||
}
|
||||
}
|
||||
}
|
||||
addNetworkHandler("ag.veh.sync", syncVehicle);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function syncCivilian(civilian) {
|
||||
|
||||
}
|
||||
addNetworkHandler("ag.civ.sync", syncCivilian);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -320,11 +288,19 @@ function initLocalPlayer(player) {
|
||||
|
||||
function processEvent(event, deltaTime) {
|
||||
if(localPlayer != null) {
|
||||
localPlayer.wantedLevel = 0;
|
||||
|
||||
let position = localPlayer.position;
|
||||
if(localPlayer.vehicle) {
|
||||
position = localPlayer.vehicle.position;
|
||||
}
|
||||
|
||||
getElementsByType(ELEMENT_PICKUP).forEach(function(pickup) {
|
||||
if(pickup.isOwner) {
|
||||
destroyElement(pickup);
|
||||
}
|
||||
});
|
||||
|
||||
getElementsByType(ELEMENT_MARKER).forEach(function(sphere) {
|
||||
if(position.distance(sphere.position) <= sphere.radius) {
|
||||
if(!inSphere) {
|
||||
@@ -341,12 +317,6 @@ function processEvent(event, deltaTime) {
|
||||
}
|
||||
});
|
||||
|
||||
getElementsByType(ELEMENT_PICKUP).forEach(function(pickup) {
|
||||
if(pickup.owner != -1) {
|
||||
destroyElement(pickup);
|
||||
}
|
||||
});
|
||||
|
||||
if(gta.game == GAME_GTA_SA) {
|
||||
if(jobRouteStopSphere != null) {
|
||||
if(position.distance(jobRouteStopSphere.position) <= 2.0) {
|
||||
@@ -357,9 +327,9 @@ function processEvent(event, deltaTime) {
|
||||
|
||||
if(localPlayer.vehicle) {
|
||||
if(!inVehicle) {
|
||||
inVehicle = localPlayer.vehicle;
|
||||
triggerEvent("OnLocalPlayerEnterVehicle", inVehicle, inVehicle);
|
||||
triggerNetworkEvent("ag.onPlayerEnterVehicle");
|
||||
inVehicle = localPlayer.vehicle;
|
||||
}
|
||||
} else {
|
||||
if(inVehicle) {
|
||||
@@ -368,16 +338,29 @@ function processEvent(event, deltaTime) {
|
||||
inVehicle = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Using vehicle.engine doesn't disable the vehicle. Need to find another way
|
||||
if(localPlayer.vehicle != null) {
|
||||
if(!localPlayer.vehicle.engine) {
|
||||
localPlayer.vehicle.velocity = toVector3(0.0, 0.0, 0.0);
|
||||
localPlayer.vehicle.turnVelocity = toVector3(0.0, 0.0, 0.0);
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addEventHandler("OnRender", function(event) {
|
||||
// OnProcess was allowing vehicles to slide slowly. This shouldn't.
|
||||
if(inVehicle) {
|
||||
if(!localPlayer.vehicle.engine) {
|
||||
localPlayer.vehicle.velocity = toVector3(0.0, 0.0, 0.0);
|
||||
localPlayer.vehicle.turnVelocity = toVector3(0.0, 0.0, 0.0);
|
||||
if(vehicleParkedPosition) {
|
||||
localPlayer.vehicle.position = parkedVehiclePosition;
|
||||
localPlayer.vehicle.heading = parkedVehicleHeading;
|
||||
}
|
||||
} else {
|
||||
if(vehicleParkedPosition) {
|
||||
parkedVehiclePosition = false;
|
||||
parkedVehicleHeading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -528,6 +511,16 @@ addEventHandler("OnLocalPlayerEnterSphere", function(event, sphere) {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
addEventHandler("OnLocalPlayerEnterVehicle", function(event, vehicle) {
|
||||
localPlayer.vehicle.engine = false;
|
||||
if(!localPlayer.vehicle.engine) {
|
||||
parkedVehiclePosition = vehicle.position;
|
||||
parkedVehicleHeading = vehicle.position;
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
//addEventHandler("OnPickupCollected", function(event, pickup, ped) {
|
||||
// if(localPlayer != null) {
|
||||
// if(ped == localPlayer) {
|
||||
|
||||
Reference in New Issue
Block a user