Use new process sync util

This commit is contained in:
Vortrex
2021-04-20 21:30:04 -05:00
parent fc0f7b1aa7
commit 2417af4b7d

View File

@@ -10,73 +10,79 @@
// =========================================================================== // ===========================================================================
addEventHandler("onProcess", function(event, deltaTime) { function processSync(event, deltaTime) {
if(localPlayer != null && isSpawned) { if(localPlayer != null) {
if(gta.game == GAME_GTA_IV) { if(gta.game == GAME_GTA_IV) {
triggerNetworkEvent("ag.player.position", localPlayer.position); triggerNetworkEvent("ag.player.position", localPlayer.position);
triggerNetworkEvent("ag.player.heading", localPlayer.heading); triggerNetworkEvent("ag.player.heading", localPlayer.heading);
} }
if(localPlayer.health <= 1) { if(localPlayer.health <= 0) {
logToConsole(LOG_DEBUG, `Local player died`);
localPlayer.clearWeapons(); localPlayer.clearWeapons();
triggerNetworkEvent("ag.player.death", localPlayer.position); triggerNetworkEvent("ag.playerDeath", localPlayer.position);
} }
} }
}); }
// =========================================================================== // ===========================================================================
addNetworkHandler("ag.veh.engine", function(vehicle, state) { function toggleVehicleEngine(vehicle, state) {
vehicle.engine = state; vehicle.engine = state;
}); }
// =========================================================================== // ===========================================================================
addNetworkHandler("ag.veh.lights", function(vehicle, state) { function toggleVehicleLights(vehicle, state) {
vehicle.lights = state; vehicle.lights = state;
}); }
// =========================================================================== // ===========================================================================
addNetworkHandler("ag.veh.repair", function(syncId) { function repairVehicle(syncId) {
getVehicleFromSyncId(syncId).fix(); getVehicleFromSyncId(syncId).fix();
}); }
// ===========================================================================
addNetworkHandler("ag.veh.sync", function(event, vehicle) {
if(vehicle != null) {
syncVehicleProperties(vehicle);
}
});
// ===========================================================================
addNetworkHandler("ag.civ.sync", function(event, civilian) {
if(civilian != null) {
syncCivilianProperties(civilian);
}
});
// ===========================================================================
addNetworkHandler("ag.player.sync", function(event, player) {
if(player != null) {
syncPlayerProperties(player);
}
});
// ===========================================================================
addNetworkHandler("ag.obj.sync", function(event, object) {
if(object != null) {
syncObjectProperties(object);
}
});
// =========================================================================== // ===========================================================================
function syncVehicleProperties(vehicle) { function syncVehicleProperties(vehicle) {
if(vehicle != null) {
syncVehicleProperties(vehicle);
}
}
// ===========================================================================
function syncCivilianProperties(civilian) {
if(civilian != null) {
syncCivilianProperties(civilian);
}
}
// ===========================================================================
function syncPlayerProperties(player) {
if(player != null) {
syncPlayerProperties(player);
}
}
// ===========================================================================
function syncObjectProperties(object) {
if(object != null) {
syncObjectProperties(object);
}
}
// ===========================================================================
function syncVehicleProperties(vehicle) {
if(doesEntityDataExist(vehicle, "ag.lights")) {
let lightStatus = getEntityData(vehicle, "ag.lights");
vehicle.lights = lightStatus;
}
if(doesEntityDataExist(vehicle, "ag.panelStatus")) { if(doesEntityDataExist(vehicle, "ag.panelStatus")) {
let panelsStatus = getEntityData(vehicle, "ag.panelStatus"); let panelsStatus = getEntityData(vehicle, "ag.panelStatus");
for(let i in panelsStatus) { for(let i in panelsStatus) {