Finished migration to TypeScript, temporary disabled char creator

This commit is contained in:
hydrant
2019-03-11 22:17:49 +01:00
parent 715cf3c1e6
commit 8ce3fd6f52
71 changed files with 4800 additions and 4627 deletions

View File

@@ -1,137 +0,0 @@
//This script will make vehicles have smoother acceleration.
//To disable the script call an event and set "GlobalDisable" to true.
//To disable individual sections, set "DisableAntiReverse" or "DisableSmoothThrottle" to true.
//This script includes an anti-reverse brake system with automatic brake lights.
//When you brake, while holding brake you will come to a complete stop and won't reverse until you
//release the brake button and press it again.
mp.events.add("SmoothThrottle_PlayerEnterVehicle", (entity, seat) =>
{
BrakeSystem = true;
});
mp.events.add("SmoothThrottle_PlayerExitVehicle", (entity) =>
{
BrakeSystem = false;
});
mp.events.add("SmoothThrottle_SetSmoothThrottle", (turnedOn) =>
{
DisableSmoothThrottle = !turnedOn;
});
mp.events.add("SmoothThrottle_SetAntiReverse", (turnedOn) =>
{
DisableAntiReverse = !turnedOn;
});
mp.events.add("SmoothThrottle_SetGlobal", (turnedOn) =>
{
GlobalDisable = !turnedOn;
});
let GlobalDisable = false;
let DisableAntiReverse = false;
let DisableSmoothThrottle = false;
let BrakeSystem = false;
let vehicleStopped = false;
let vehicleStoppedOnOwn = false;
let constantStart = 0.25; //starts at 0.25 and increases to 1
let constantStep = 0.135; //You can change this for a faster throttle response (Will cause more skidding)
let deltaAmount = constantStart;
let prevTime = mp.game.invoke('0x9CD27B0045628463');
let diffToggle = false;
mp.events.add("render", () =>
{
if(GlobalDisable)
return;
if(BrakeSystem)
{
if(mp.players.local.vehicle !== null)
{
if(!mp.players.local.vehicle.isSeatFree(-1)) //only do this if the vehicle has a driver (doesn't have to be the player who is rendering this)
{
//Optimize function calls to variables (probably doesn't make a difference)
let vehClass = mp.players.local.vehicle.getClass();
let isControl71Pressed = mp.game.controls.isControlPressed(0, 71); //accelerate
let isControl72Pressed = mp.game.controls.isControlPressed(0, 72); //brake
let isControl76Pressed = mp.game.controls.isControlPressed(0, 76); //handbrake
let speed = mp.players.local.vehicle.getSpeed();
//Only do it to car classes
if(!DisableSmoothThrottle && ((vehClass >= 0 && vehClass <= 12) || vehClass === 18 || vehClass === 19 || vehClass === 20))
{
if(isControl71Pressed || isControl72Pressed)
{
if(isControl76Pressed)
{
deltaAmount = 1.0; //If people are buffering their throttle up
}
mp.players.local.vehicle.setEngineTorqueMultiplier(deltaAmount);
//Calculate tick time and step every 250ms
if (mp.game.invoke('0x9CD27B0045628463') - prevTime > 250)
{
prevTime = mp.game.invoke('0x9CD27B0045628463');
deltaAmount += constantStep * speed; //Curve
if(deltaAmount > 1.0)
{
deltaAmount = 1.0;
}
}
}
else
{
deltaAmount = constantStart; //Reset when they let go of throttle
//mp.game.controls.setControlNormal(0, 71, amount);
}
}
//THIS IS THE BRAKE LIGHT SYSTEM WITH ANTI-REVERSE
if(DisableAntiReverse)
return;
if(speed < 1)
{
vehicleStopped = true;
}
else
{
vehicleStopped = false;
vehicleStoppedOnOwn = false;
diffToggle = false;
}
if((!isControl72Pressed && mp.game.controls.isControlEnabled(0, 72)) && !isControl76Pressed && vehicleStopped)
{
vehicleStoppedOnOwn = true;
mp.players.local.vehicle.setBrakeLights(true);
}
if(vehicleStopped && !vehicleStoppedOnOwn && !mp.players.local.vehicle.isInBurnout() && !diffToggle)
{
mp.players.local.vehicle.setBrakeLights(true);
mp.game.controls.disableControlAction(0, 72, true);
}
if((isControl71Pressed && !isControl72Pressed) || isControl76Pressed)
{
mp.players.local.vehicle.setBrakeLights(false);
}
if(mp.game.controls.isDisabledControlJustReleased(0, 72) && vehicleStopped)
{
mp.game.controls.enableControlAction(0, 72, true);
diffToggle = true;
}
}
}
}
});

View File

@@ -0,0 +1,119 @@
//This script will make vehicles have smoother acceleration.
//To disable the script call an event and set "GlobalDisable" to true.
//To disable individual sections, set "DisableAntiReverse" or "DisableSmoothThrottle" to true.
//This script includes an anti-reverse brake system with automatic brake lights.
//When you brake, while holding brake you will come to a complete stop and won't reverse until you
//release the brake button and press it again.
export default function smoothThrottle() {
let GlobalDisable = false;
let DisableAntiReverse = false;
let DisableSmoothThrottle = false;
let BrakeSystem = false;
let vehicleStopped = false;
let vehicleStoppedOnOwn = false;
let constantStart = 0.25; //starts at 0.25 and increases to 1
let constantStep = 0.135; //You can change this for a faster throttle response (Will cause more skidding)
let deltaAmount = constantStart;
let prevTime = mp.game.invoke('0x9CD27B0045628463');
let diffToggle = false;
mp.events.add("SmoothThrottle_PlayerEnterVehicle", (entity, seat) => {
BrakeSystem = true;
});
mp.events.add("SmoothThrottle_PlayerExitVehicle", (entity) => {
BrakeSystem = false;
});
mp.events.add("SmoothThrottle_SetSmoothThrottle", (turnedOn) => {
DisableSmoothThrottle = !turnedOn;
});
mp.events.add("SmoothThrottle_SetAntiReverse", (turnedOn) => {
DisableAntiReverse = !turnedOn;
});
mp.events.add("SmoothThrottle_SetGlobal", (turnedOn) => {
GlobalDisable = !turnedOn;
});
mp.events.add("render", () => {
if (GlobalDisable)
return;
if (BrakeSystem) {
if (mp.players.local.vehicle !== null) {
if (!mp.players.local.vehicle.isSeatFree(-1)) //only do this if the vehicle has a driver (doesn't have to be the player who is rendering this)
{
//Optimize function calls to variables (probably doesn't make a difference)
let vehClass = mp.players.local.vehicle.getClass();
let isControl71Pressed = mp.game.controls.isControlPressed(0, 71); //accelerate
let isControl72Pressed = mp.game.controls.isControlPressed(0, 72); //brake
let isControl76Pressed = mp.game.controls.isControlPressed(0, 76); //handbrake
let speed = mp.players.local.vehicle.getSpeed();
//Only do it to car classes
if (!DisableSmoothThrottle && ((vehClass >= 0 && vehClass <= 12) || vehClass === 18 || vehClass === 19 || vehClass === 20)) {
if (isControl71Pressed || isControl72Pressed) {
if (isControl76Pressed) {
deltaAmount = 1.0; //If people are buffering their throttle up
}
mp.players.local.vehicle.setEngineTorqueMultiplier(deltaAmount);
//Calculate tick time and step every 250ms
if (mp.game.invoke('0x9CD27B0045628463') - prevTime > 250) {
prevTime = mp.game.invoke('0x9CD27B0045628463');
deltaAmount += constantStep * speed; //Curve
if (deltaAmount > 1.0) {
deltaAmount = 1.0;
}
}
}
else {
deltaAmount = constantStart; //Reset when they let go of throttle
//mp.game.controls.setControlNormal(0, 71, amount);
}
}
//THIS IS THE BRAKE LIGHT SYSTEM WITH ANTI-REVERSE
if (DisableAntiReverse)
return;
if (speed < 1) {
vehicleStopped = true;
}
else {
vehicleStopped = false;
vehicleStoppedOnOwn = false;
diffToggle = false;
}
if ((!isControl72Pressed && mp.game.controls.isControlEnabled(0, 72)) && !isControl76Pressed && vehicleStopped) {
vehicleStoppedOnOwn = true;
mp.players.local.vehicle.setBrakeLights(true);
}
if (vehicleStopped && !vehicleStoppedOnOwn && !mp.players.local.vehicle.isInBurnout() && !diffToggle) {
mp.players.local.vehicle.setBrakeLights(true);
mp.game.controls.disableControlAction(0, 72, true);
}
if ((isControl71Pressed && !isControl72Pressed) || isControl76Pressed) {
mp.players.local.vehicle.setBrakeLights(false);
}
if (mp.game.controls.isDisabledControlJustReleased(0, 72) && vehicleStopped) {
mp.game.controls.enableControlAction(0, 72, true);
diffToggle = true;
}
}
}
}
});
}

View File

@@ -1,33 +0,0 @@
var player = mp.players.local;
mp.keys.bind(0x64, true, function () {
if (!player.vehicle) return;
mp.events.callRemote("CLIENT:toggleLeftIndicator");
});
mp.keys.bind(0x66, true, function () {
if (!player.vehicle) return;
mp.events.callRemote("CLIENT:toggleRightIndicator");
});
mp.keys.bind(0x65, true, function () {
if (!player.vehicle) return;
mp.events.callRemote("CLIENT:toggleWarningIndicator");
});
mp.events.add("SERVER:setIndicatorStatus", (vehicle, left, right) => {
var veh = mp.vehicles.atRemoteId(vehicle);
veh.setIndicatorLights(0, right);
veh.setIndicatorLights(1, left);
});
mp.events.add("entityStreamIn", entity => {
if (entity === undefined || entity === null || !entity.isAVehicle()) return;
var data = entity.getVariable("indicatorData");
if (data) {
entity.setIndicatorLights(0, data.Right);
entity.setIndicatorLights(1, data.Left);
}
});

View File

@@ -0,0 +1,36 @@
const player = mp.players.local;
export default function vehicleIndicators() {
mp.keys.bind(0x64, true, function () {
if (!player.vehicle) return;
mp.events.callRemote("CLIENT:toggleLeftIndicator");
});
mp.keys.bind(0x66, true, function () {
if (!player.vehicle) return;
mp.events.callRemote("CLIENT:toggleRightIndicator");
});
mp.keys.bind(0x65, true, function () {
if (!player.vehicle) return;
mp.events.callRemote("CLIENT:toggleWarningIndicator");
});
mp.events.add("SERVER:setIndicatorStatus", (vehicle, left, right) => {
var veh = mp.vehicles.atRemoteId(vehicle);
veh.setIndicatorLights(0, right);
veh.setIndicatorLights(1, left);
});
mp.events.add("entityStreamIn", entity => {
if (entity === undefined || entity === null || !entity.isAVehicle()) return;
var data = entity.getVariable("indicatorData");
if (data) {
entity.setIndicatorLights(0, data.Right);
entity.setIndicatorLights(1, data.Left);
}
});
}

View File

@@ -1,548 +0,0 @@
//Disapproved by the entire planet
//You don't need to worry about anything here
mp.events.add("VehStream_SetEngineStatus", (veh, status) => {
if (veh === undefined || veh === null || !veh.isAVehicle()) return;
if (veh !== undefined) {
if (veh.isSeatFree(-1)) //Turns engine on instantly if no driver, otherwise it will not turn on
{
veh.setEngineOn(status, true, false);
veh.setUndriveable(true);
}
else {
veh.setEngineOn(status, false, true);
veh.setUndriveable(!status);
}
}
});
mp.events.add("VehStream_SetLockStatus", (veh, status) => {
if (veh === undefined || veh === null || !veh.isAVehicle()) return;
if (veh !== undefined) {
if (status)
veh.setDoorsLocked(2);
else
veh.setDoorsLocked(1);
}
});
mp.events.add("VehStream_PlayerEnterVehicleAttempt", (entity, seat) => {
entity = mp.vehicles.atRemoteId(entity);
if (entity === undefined || entity === null || !entity.isAVehicle()) return;
if (typeof entity.getVariable("VehicleSyncData") !== 'undefined') {
var toggle = entity.getVariable("VehicleSyncData");
entity.setEngineOn(toggle.Engine, false, true);
entity.setUndriveable(!toggle.Engine);
}
});
mp.events.add("VehStream_PlayerExitVehicleAttempt", (entity) => {
if (entity === undefined || entity === null || !entity.isAVehicle()) return;
if (entity !== undefined) {
if (typeof entity.getVariable("VehicleSyncData") !== 'undefined') {
var toggle = entity.getVariable("VehicleSyncData");
entity.setEngineOn(toggle.Engine, true, false);
entity.setUndriveable(!toggle.Engine);
}
var level = entity.getDirtLevel();
mp.events.callRemote("VehStream_SetDirtLevel", entity, level);
}
});
mp.events.add("VehStream_PlayerExitVehicle", (entity) => {
entity = mp.vehicles.atRemoteId(entity);
if (entity === undefined || entity === null || !entity.isAVehicle()) {
return;
}
setTimeout(() => {
var Status = [];
let y = 0;
for (y = 0; y < 8; y++) {
if (entity.isDoorDamaged(y)) {
Status.push(2);
}
else if (entity.getDoorAngleRatio(y) > 0.15) {
Status.push(1);
}
else {
Status.push(0);
}
}
mp.events.callRemote("VehStream_SetDoorData", entity, Status[0], Status[1], Status[2], Status[3], Status[4], Status[5], Status[6], Status[7]);
Status = [];
if (entity.isWindowIntact(0)) {
if (entity.getBoneIndexByName("window_rf") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
if (entity.isWindowIntact(1)) {
if (entity.getBoneIndexByName("window_lf") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
if (entity.isWindowIntact(2)) {
if (entity.getBoneIndexByName("window_rr") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
if (entity.isWindowIntact(3)) {
if (entity.getBoneIndexByName("window_lr") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
mp.events.callRemote("VehStream_SetWindowData", entity, Status[0], Status[1], Status[2], Status[3]);
Status = [];
if (!entity.isTyreBurst(0, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(0, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(1, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(1, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(2, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(2, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(3, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(3, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(4, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(4, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(5, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(5, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(6, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(6, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(7, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(7, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(45, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(45, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(47, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(47, false)) {
Status.push(1);
}
else {
Status.push(2);
}
mp.events.callRemote("VehStream_SetWheelData", entity, Status[0], Status[1], Status[2], Status[3], Status[4], Status[5], Status[6], Status[7], Status[8], Status[9]);
}, 2500);
});
mp.events.add("VehStream_PlayerEnterVehicleAttempt", (entity, seat) => {
entity = mp.vehicles.atRemoteId(entity);
if (entity === undefined || entity === null || !entity.isAVehicle()) return;
setTimeout(() => {
var Status = [];
let y = 0;
for (y = 0; y < 8; y++) {
if (entity.isDoorDamaged(y)) {
Status.push(2);
}
else if (entity.getDoorAngleRatio(y) > 0.15) {
Status.push(1);
}
else {
Status.push(0);
}
}
//mp.events.callRemote("VehStream_SetDoorData", entity, Status[0], Status[1], Status[2], Status[3], Status[4], Status[5], Status[6], Status[7]);
Status = [];
if (entity.isWindowIntact(0)) {
if (entity.getBoneIndexByName("window_rf") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
if (entity.isWindowIntact(1)) {
if (entity.getBoneIndexByName("window_lf") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
if (entity.isWindowIntact(2)) {
if (entity.getBoneIndexByName("window_rr") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
if (entity.isWindowIntact(3)) {
if (entity.getBoneIndexByName("window_lr") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
mp.events.callRemote("VehStream_SetWindowData", entity, Status[0], Status[1], Status[2], Status[3]);
}, 3000);
});
mp.events.add("VehStream_SetVehicleDirtLevel", (entity, dirt) => {
if (entity === undefined || entity === null || !entity.isAVehicle()) return;
if (entity !== undefined) {
entity.setDirtLevel(dirt);
}
});
mp.events.add("VehStream_SetVehicleDoorStatus_Single", (veh, door, state) => {
if (veh === undefined || veh === null || !veh.isAVehicle()) return;
if (veh !== undefined) {
if (state === 0) {
veh.setDoorShut(door, false);
}
else if (state === 1) {
veh.setDoorOpen(door, false, false);
}
else {
veh.setDoorBroken(door, true);
}
}
});
mp.events.add("VehStream_SetVehicleDoorStatus", (...args) => {
if (args[0] !== undefined && args[0] !== null || !args[0].isAVehicle()) {
let y = 0;
for (y = 1; y < args.length; y++) {
if (args[y] === 0) {
args[0].setDoorShut(y - 1, false);
}
else if (args[y] === 1) {
args[0].setDoorOpen(y - 1, false, false);
}
else {
args[0].setDoorBroken(y - 1, true);
}
}
}
});
mp.events.add("VehStream_SetVehicleWindowStatus_Single", (veh, windw, state) => {
if (veh === undefined || veh === null || !veh.isAVehicle()) return;
if (veh !== undefined) {
if (state === 1) {
veh.rollDownWindow(windw);
}
else if (state === 0) {
veh.fixWindow(windw);
veh.rollUpWindow(windw);
}
else {
veh.smashWindow(windw);
}
}
});
mp.events.add("VehStream_SetVehicleWindowStatus", (...args) => {
if (args[0] !== undefined && args[0] !== null || !args[0].isAVehicle()) {
let y = 0;
for (y = 1; y < 4; y++) {
if (args[y] === 1) {
args[0].rollDownWindow(y - 1);
}
else if (args[y] === 0) {
args[0].fixWindow(y - 1);
args[0].rollUpWindow(y - 1);
}
else {
args[0].smashWindow(y - 1);
}
}
}
});
mp.events.add("VehStream_SetVehicleWheelStatus_Single", (veh, wheel, state) => {
if (veh === undefined || veh === null || !veh.isAVehicle()) return;
if (veh !== undefined) {
if (wheel === 9) {
if (state === 1) {
veh.setTyreBurst(45, false, 1000);
}
else if (state === 0) {
veh.setTyreFixed(45);
}
else {
veh.setTyreBurst(45, true, 1000);
}
}
else if (wheel === 10) {
if (state === 1) {
veh.setTyreBurst(47, false, 1000);
}
else if (state === 0) {
veh.setTyreFixed(47);
}
else {
veh.setTyreBurst(47, true, 1000);
}
}
else {
if (state === 1) {
veh.setTyreBurst(wheel, false, 1000);
}
else if (state === 0) {
veh.setTyreFixed(wheel);
}
else {
veh.setTyreBurst(wheel, true, 1000);
}
}
}
});
mp.events.add("VehStream_SetVehicleWheelStatus", (...args) => {
if (args[0] !== undefined && args[0] !== null || !args[0].isAVehicle()) {
let y = 0;
for (y = 1; y < args.length; y++) {
if (y === 9) {
if (args[y] === 1) {
args[0].setTyreBurst(45, false, 1000);
}
else if (args[y] === 0) {
args[0].setTyreFixed(45);
}
else {
args[0].setTyreBurst(45, true, 1000);
}
}
else if (y === 10) {
if (args[y] === 1) {
args[0].setTyreBurst(47, false, 1000);
}
else if (args[y] === 0) {
args[0].setTyreFixed(47);
}
else {
args[0].setTyreBurst(47, true, 1000);
}
}
else {
if (args[y] === 1) {
args[0].setTyreBurst(y - 1, false, 1000);
}
else if (args[y] === 0) {
args[0].setTyreFixed(y - 1);
}
else {
args[0].setTyreBurst(y - 1, true, 1000);
}
}
}
}
});
//Sync data on stream in
mp.events.add("entityStreamIn", (entity) => {
if (entity === undefined || entity === null || !entity.isAVehicle()) return;
if (entity.type === "vehicle") {
let typeor = typeof entity.getVariable('VehicleSyncData');
let actualData = entity.getVariable('VehicleSyncData');
//Needed to stop vehicles from freaking out
mp.game.streaming.requestCollisionAtCoord(entity.position.x, entity.position.y, entity.position.z);
//mp.game.invoke('0x199640F55E0F7596', entity.position.x, entity.position.y, entity.position.z);
entity.setLoadCollisionFlag(true);
entity.trackVisibility();
if (typeor !== 'undefined' && entity.isSeatFree(-1)) //Only if there is no driver
{
entity.position = actualData.Position;
entity.rotation = actualData.Rotation;
}
//Set doors unbreakable for a moment
let x = 0;
for (x = 0; x < 8; x++) {
entity.setDoorBreakable(x, false);
}
//Do it anyway
entity.setUndriveable(true);
if (typeor !== 'undefined') {
entity.setEngineOn(actualData.Engine, true, false);
entity.setUndriveable(true);
if (actualData.Locked)
entity.setDoorsLocked(2);
else
entity.setDoorsLocked(1);
entity.setDirtLevel(actualData.Dirt);
for (x = 0; x < 8; x++) {
if (actualData.Door[x] === 1)
entity.setDoorOpen(x, false, false);
else if (actualData.Door[x] === 0)
entity.setDoorShut(x, true);
else
entity.setDoorBroken(x, true);
}
for (x = 0; x < 4; x++) {
if (actualData.Window[x] === 0) {
entity.fixWindow(x);
}
else if (actualData.Window[x] === 1) {
entity.rollDownWindow(x);
}
else {
entity.smashWindow(x);
}
}
for (x = 0; x < 8; x++) {
if (actualData.Wheel[x] === 0) {
entity.setTyreFixed(x);
}
else if (actualData.Wheel[x] === 1) {
entity.setTyreBurst(x, false, 0);
}
else {
entity.setTyreBurst(x, true, 1000);
}
}
//For trailer mid wheels
if (actualData.Wheel[8] === 0) {
entity.setTyreFixed(45);
}
else if (actualData.Wheel[8] === 1) {
entity.setTyreBurst(45, false, 0);
}
else {
entity.setTyreBurst(45, true, 1000);
}
if (actualData.Wheel[9] === 0) {
entity.setTyreFixed(47);
}
else if (actualData.Wheel[9] === 1) {
entity.setTyreBurst(47, false, 0);
}
else {
entity.setTyreBurst(47, true, 1000);
}
}
//Make doors breakable again
setTimeout(() => {
for (x = 0; x < 8; x++) {
entity.setDoorBreakable(x, true);
}
}, 1500);
}
});

View File

@@ -0,0 +1,549 @@
//Disapproved by the entire planet
//You don't need to worry about anything here
export default function vehicleSync() {
mp.events.add("VehStream_SetEngineStatus", (veh, status) => {
if (veh === undefined || veh === null || !veh.isAVehicle()) return;
if (veh !== undefined) {
if (veh.isSeatFree(-1)) //Turns engine on instantly if no driver, otherwise it will not turn on
{
veh.setEngineOn(status, true, false);
veh.setUndriveable(true);
}
else {
veh.setEngineOn(status, false, true);
veh.setUndriveable(!status);
}
}
});
mp.events.add("VehStream_SetLockStatus", (veh, status) => {
if (veh === undefined || veh === null || !veh.isAVehicle()) return;
if (veh !== undefined) {
if (status)
veh.setDoorsLocked(2);
else
veh.setDoorsLocked(1);
}
});
mp.events.add("VehStream_PlayerEnterVehicleAttempt", (entity, seat) => {
entity = mp.vehicles.atRemoteId(entity);
if (entity === undefined || entity === null || !entity.isAVehicle()) return;
if (typeof entity.getVariable("VehicleSyncData") !== 'undefined') {
var toggle = entity.getVariable("VehicleSyncData");
entity.setEngineOn(toggle.Engine, false, true);
entity.setUndriveable(!toggle.Engine);
}
});
mp.events.add("VehStream_PlayerExitVehicleAttempt", (entity) => {
if (entity === undefined || entity === null || !entity.isAVehicle()) return;
if (entity !== undefined) {
if (typeof entity.getVariable("VehicleSyncData") !== 'undefined') {
var toggle = entity.getVariable("VehicleSyncData");
entity.setEngineOn(toggle.Engine, true, false);
entity.setUndriveable(!toggle.Engine);
}
var level = entity.getDirtLevel();
mp.events.callRemote("VehStream_SetDirtLevel", entity, level);
}
});
mp.events.add("VehStream_PlayerExitVehicle", (entity) => {
entity = mp.vehicles.atRemoteId(entity);
if (entity === undefined || entity === null || !entity.isAVehicle()) {
return;
}
setTimeout(() => {
var Status = [];
let y = 0;
for (y = 0; y < 8; y++) {
if (entity.isDoorDamaged(y)) {
Status.push(2);
}
else if (entity.getDoorAngleRatio(y) > 0.15) {
Status.push(1);
}
else {
Status.push(0);
}
}
mp.events.callRemote("VehStream_SetDoorData", entity, Status[0], Status[1], Status[2], Status[3], Status[4], Status[5], Status[6], Status[7]);
Status = [];
if (entity.isWindowIntact(0)) {
if (entity.getBoneIndexByName("window_rf") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
if (entity.isWindowIntact(1)) {
if (entity.getBoneIndexByName("window_lf") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
if (entity.isWindowIntact(2)) {
if (entity.getBoneIndexByName("window_rr") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
if (entity.isWindowIntact(3)) {
if (entity.getBoneIndexByName("window_lr") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
mp.events.callRemote("VehStream_SetWindowData", entity, Status[0], Status[1], Status[2], Status[3]);
Status = [];
if (!entity.isTyreBurst(0, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(0, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(1, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(1, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(2, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(2, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(3, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(3, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(4, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(4, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(5, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(5, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(6, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(6, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(7, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(7, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(45, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(45, false)) {
Status.push(1);
}
else {
Status.push(2);
}
if (!entity.isTyreBurst(47, false)) {
Status.push(0);
}
else if (entity.isTyreBurst(47, false)) {
Status.push(1);
}
else {
Status.push(2);
}
mp.events.callRemote("VehStream_SetWheelData", entity, Status[0], Status[1], Status[2], Status[3], Status[4], Status[5], Status[6], Status[7], Status[8], Status[9]);
}, 2500);
});
mp.events.add("VehStream_PlayerEnterVehicleAttempt", (entity, seat) => {
entity = mp.vehicles.atRemoteId(entity);
if (entity === undefined || entity === null || !entity.isAVehicle()) return;
setTimeout(() => {
var Status = [];
let y = 0;
for (y = 0; y < 8; y++) {
if (entity.isDoorDamaged(y)) {
Status.push(2);
}
else if (entity.getDoorAngleRatio(y) > 0.15) {
Status.push(1);
}
else {
Status.push(0);
}
}
//mp.events.callRemote("VehStream_SetDoorData", entity, Status[0], Status[1], Status[2], Status[3], Status[4], Status[5], Status[6], Status[7]);
Status = [];
if (entity.isWindowIntact(0)) {
if (entity.getBoneIndexByName("window_rf") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
if (entity.isWindowIntact(1)) {
if (entity.getBoneIndexByName("window_lf") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
if (entity.isWindowIntact(2)) {
if (entity.getBoneIndexByName("window_rr") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
if (entity.isWindowIntact(3)) {
if (entity.getBoneIndexByName("window_lr") === -1) {
Status.push(1);
}
else {
Status.push(0);
}
}
else {
Status.push(2);
}
mp.events.callRemote("VehStream_SetWindowData", entity, Status[0], Status[1], Status[2], Status[3]);
}, 3000);
});
mp.events.add("VehStream_SetVehicleDirtLevel", (entity, dirt) => {
if (entity === undefined || entity === null || !entity.isAVehicle()) return;
if (entity !== undefined) {
entity.setDirtLevel(dirt);
}
});
mp.events.add("VehStream_SetVehicleDoorStatus_Single", (veh, door, state) => {
if (veh === undefined || veh === null || !veh.isAVehicle()) return;
if (veh !== undefined) {
if (state === 0) {
veh.setDoorShut(door, false);
}
else if (state === 1) {
veh.setDoorOpen(door, false, false);
}
else {
veh.setDoorBroken(door, true);
}
}
});
mp.events.add("VehStream_SetVehicleDoorStatus", (...args) => {
if (args[0] !== undefined && args[0] !== null || !args[0].isAVehicle()) {
let y = 0;
for (y = 1; y < args.length; y++) {
if (args[y] === 0) {
args[0].setDoorShut(y - 1, false);
}
else if (args[y] === 1) {
args[0].setDoorOpen(y - 1, false, false);
}
else {
args[0].setDoorBroken(y - 1, true);
}
}
}
});
mp.events.add("VehStream_SetVehicleWindowStatus_Single", (veh, windw, state) => {
if (veh === undefined || veh === null || !veh.isAVehicle()) return;
if (veh !== undefined) {
if (state === 1) {
veh.rollDownWindow(windw);
}
else if (state === 0) {
veh.fixWindow(windw);
veh.rollUpWindow(windw);
}
else {
veh.smashWindow(windw);
}
}
});
mp.events.add("VehStream_SetVehicleWindowStatus", (...args) => {
if (args[0] !== undefined && args[0] !== null || !args[0].isAVehicle()) {
let y = 0;
for (y = 1; y < 4; y++) {
if (args[y] === 1) {
args[0].rollDownWindow(y - 1);
}
else if (args[y] === 0) {
args[0].fixWindow(y - 1);
args[0].rollUpWindow(y - 1);
}
else {
args[0].smashWindow(y - 1);
}
}
}
});
mp.events.add("VehStream_SetVehicleWheelStatus_Single", (veh, wheel, state) => {
if (veh === undefined || veh === null || !veh.isAVehicle()) return;
if (veh !== undefined) {
if (wheel === 9) {
if (state === 1) {
veh.setTyreBurst(45, false, 1000);
}
else if (state === 0) {
veh.setTyreFixed(45);
}
else {
veh.setTyreBurst(45, true, 1000);
}
}
else if (wheel === 10) {
if (state === 1) {
veh.setTyreBurst(47, false, 1000);
}
else if (state === 0) {
veh.setTyreFixed(47);
}
else {
veh.setTyreBurst(47, true, 1000);
}
}
else {
if (state === 1) {
veh.setTyreBurst(wheel, false, 1000);
}
else if (state === 0) {
veh.setTyreFixed(wheel);
}
else {
veh.setTyreBurst(wheel, true, 1000);
}
}
}
});
mp.events.add("VehStream_SetVehicleWheelStatus", (...args) => {
if (args[0] !== undefined && args[0] !== null || !args[0].isAVehicle()) {
let y = 0;
for (y = 1; y < args.length; y++) {
if (y === 9) {
if (args[y] === 1) {
args[0].setTyreBurst(45, false, 1000);
}
else if (args[y] === 0) {
args[0].setTyreFixed(45);
}
else {
args[0].setTyreBurst(45, true, 1000);
}
}
else if (y === 10) {
if (args[y] === 1) {
args[0].setTyreBurst(47, false, 1000);
}
else if (args[y] === 0) {
args[0].setTyreFixed(47);
}
else {
args[0].setTyreBurst(47, true, 1000);
}
}
else {
if (args[y] === 1) {
args[0].setTyreBurst(y - 1, false, 1000);
}
else if (args[y] === 0) {
args[0].setTyreFixed(y - 1);
}
else {
args[0].setTyreBurst(y - 1, true, 1000);
}
}
}
}
});
//Sync data on stream in
mp.events.add("entityStreamIn", (entity) => {
if (entity === undefined || entity === null || !entity.isAVehicle()) return;
if (entity.type === "vehicle") {
let typeor = typeof entity.getVariable('VehicleSyncData');
let actualData = entity.getVariable('VehicleSyncData');
//Needed to stop vehicles from freaking out
mp.game.streaming.requestCollisionAtCoord(entity.position.x, entity.position.y, entity.position.z);
//mp.game.invoke('0x199640F55E0F7596', entity.position.x, entity.position.y, entity.position.z);
entity.setLoadCollisionFlag(true);
entity.trackVisibility();
if (typeor !== 'undefined' && entity.isSeatFree(-1)) //Only if there is no driver
{
entity.position = actualData.Position;
entity.rotation = actualData.Rotation;
}
//Set doors unbreakable for a moment
let x = 0;
for (x = 0; x < 8; x++) {
entity.setDoorBreakable(x, false);
}
//Do it anyway
entity.setUndriveable(true);
if (typeor !== 'undefined') {
entity.setEngineOn(actualData.Engine, true, false);
entity.setUndriveable(true);
if (actualData.Locked)
entity.setDoorsLocked(2);
else
entity.setDoorsLocked(1);
entity.setDirtLevel(actualData.Dirt);
for (x = 0; x < 8; x++) {
if (actualData.Door[x] === 1)
entity.setDoorOpen(x, false, false);
else if (actualData.Door[x] === 0)
entity.setDoorShut(x, true);
else
entity.setDoorBroken(x, true);
}
for (x = 0; x < 4; x++) {
if (actualData.Window[x] === 0) {
entity.fixWindow(x);
}
else if (actualData.Window[x] === 1) {
entity.rollDownWindow(x);
}
else {
entity.smashWindow(x);
}
}
for (x = 0; x < 8; x++) {
if (actualData.Wheel[x] === 0) {
entity.setTyreFixed(x);
}
else if (actualData.Wheel[x] === 1) {
entity.setTyreBurst(x, false, 0);
}
else {
entity.setTyreBurst(x, true, 1000);
}
}
//For trailer mid wheels
if (actualData.Wheel[8] === 0) {
entity.setTyreFixed(45);
}
else if (actualData.Wheel[8] === 1) {
entity.setTyreBurst(45, false, 0);
}
else {
entity.setTyreBurst(45, true, 1000);
}
if (actualData.Wheel[9] === 0) {
entity.setTyreFixed(47);
}
else if (actualData.Wheel[9] === 1) {
entity.setTyreBurst(47, false, 0);
}
else {
entity.setTyreBurst(47, true, 1000);
}
}
//Make doors breakable again
setTimeout(() => {
for (x = 0; x < 8; x++) {
entity.setDoorBreakable(x, true);
}
}, 1500);
}
});
}