Added CS local player enter/exit veh events

This commit is contained in:
Vortrex
2020-12-16 07:53:26 -06:00
parent 5b55022eb9
commit cecabc7b65

View File

@@ -65,6 +65,8 @@ bindEventHandler("onResourceStart", thisResource, function(event, resource) {
addEvent("OnLocalPlayerEnterSphere", 1); addEvent("OnLocalPlayerEnterSphere", 1);
addEvent("OnLocalPlayerExitSphere", 1); addEvent("OnLocalPlayerExitSphere", 1);
addEvent("OnLocalPlayerEnterVehicle", 2);
addEvent("OnLocalPlayerExitVehicle", 2);
}); });
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -236,6 +238,7 @@ function initLocalPlayer(player) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function processEvent(event, deltaTime) { function processEvent(event, deltaTime) {
if(localPlayer != null) {
getElementsByType(ELEMENT_MARKER).forEach(function(sphere) { getElementsByType(ELEMENT_MARKER).forEach(function(sphere) {
if(localPlayer.position.distance(sphere.position) <= sphere.radius) { if(localPlayer.position.distance(sphere.position) <= sphere.radius) {
if(localPlayer.getData("ag.inSphere") == null) { if(localPlayer.getData("ag.inSphere") == null) {
@@ -245,12 +248,27 @@ function processEvent(event, deltaTime) {
} }
} else { } else {
if(localPlayer.getData("ag.inSphere") != null) { if(localPlayer.getData("ag.inSphere") != null) {
localPlayer.removeData("ag.inSphere", sphere); localPlayer.removeData("ag.inSphere");
triggerEvent("OnLocalPlayerExitSphere", sphere, sphere); triggerEvent("OnLocalPlayerExitSphere", sphere, sphere);
triggerNetworkEvent("ag.onPlayerExitSphere", sphere); triggerNetworkEvent("ag.onPlayerExitSphere", sphere);
} }
} }
}); });
if(localPlayer.vehicle != null) {
if(!inVehicle) {
inVehicle = localPlayer.vehicle;
triggerEvent("OnLocalPlayerEnterVehicle", inVehicle, inVehicle);
triggerNetworkEvent("ag.onPlayerEnterVehicle", inVehicle);
}
} else {
if(inVehicle) {
triggerEvent("OnLocalPlayerExitVehicle", inVehicle, inVehicle);
triggerNetworkEvent("ag.onPlayerExitVehicle", inVehicle);
inVehicle = false;
}
}
}
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -391,11 +409,16 @@ addEventHandler("OnPedWasted", function(event, wastedPed, killerPed, weapon, ped
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
addNetworkHandler("ag.showBusStop", function(position, colour) { addNetworkHandler("ag.showBusStop", function(position, colour) {
let busStopSphere = gta.createSphere(position, 3); busStopSphere = gta.createSphere(position, 3);
let busStopBlip = gta.createBlip(position, 0, 2, colour); busStopBlip = gta.createBlip(position, 0, 2, colour);
bindEventHandler("OnLocalPlayerEnterSphere", busStopSphere, function(event, sphere) { bindEventHandler("OnLocalPlayerEnterSphere", busStopSphere, function(event, sphere) {
triggerNetworkEvent("ag.arrivedAtBusStop"); triggerNetworkEvent("ag.arrivedAtBusStop");
unbindEventHandler("OnLocalPlayerEnterSphere", busStopSphere);
destroyElement(busStopSphere);
destroyElement(busStopBlip);
busStopSphere = null;
busStopBlip = null;
}); });
}); });