diff --git a/scripts/client/event.js b/scripts/client/event.js index 8c7cfc66..cd1c6e42 100644 --- a/scripts/client/event.js +++ b/scripts/client/event.js @@ -94,6 +94,7 @@ function onProcess(event, deltaTime) { processWantedLevelReset(); processGameSpecifics(); processNearbyPickups(); + processVehiclePurchasing(); } // =========================================================================== diff --git a/scripts/client/main.js b/scripts/client/main.js index 8d9b4642..d2e8d37f 100644 --- a/scripts/client/main.js +++ b/scripts/client/main.js @@ -59,6 +59,10 @@ let mouseCameraEnabled = false; let currentPickup = false; +let vehiclePurchaseState = VRR_VEHBUYSTATE_NONE; +let vehiclePurchasing = null; +let vehiclePurchasePosition = null; + // Pre-cache all allowed skins let allowedSkins = getAllowedSkins(getGame()); diff --git a/scripts/client/server.js b/scripts/client/server.js index 8a6148af..fb39d8be 100644 --- a/scripts/client/server.js +++ b/scripts/client/server.js @@ -89,6 +89,8 @@ function addAllNetworkHandlers() { addNetworkHandler("vrr.elementPosition", setElementPosition); addNetworkHandler("vrr.elementCollisions", setElementCollisionsEnabled); + addNetworkHandler("vrr.vehBuyState", setVehiclePurchaseState); + addNetworkHandler("vrr.showRegistration", showRegistrationGUI); addNetworkHandler("vrr.showNewCharacter", showNewCharacterGUI); addNetworkHandler("vrr.showLogin", showLoginGUI); diff --git a/scripts/client/utilities.js b/scripts/client/utilities.js index aa631645..4522ae3e 100644 --- a/scripts/client/utilities.js +++ b/scripts/client/utilities.js @@ -819,4 +819,34 @@ function processGameSpecifics() { destroyAutoCreatedPickups(); } +// =========================================================================== + +function processVehiclePurchasing() { + if(vehiclePurchaseState == VRR_VEHBUYSTATE_TESTDRIVE) { + if(inVehicle == false) { + vehiclePurchaseState = VRR_VEHBUYSTATE_EXITEDVEH; + triggerNetworkEvent("vrr.vehBuyState", VRR_VEHBUYSTATE_EXITEDVEH); + return false; + } else { + if(vehiclePurchasing.id == inVehicle) { + if(getDistance(inVehicle.position, vehiclePurchasePosition) >= 25) { + vehiclePurchaseState = VRR_VEHBUYSTATE_FARENOUGH; + triggerNetworkEvent("vrr.vehBuyState", VRR_VEHBUYSTATE_FARENOUGH); + } + } else { + vehiclePurchaseState = VRR_VEHBUYSTATE_WRONGVEH; + triggerNetworkEvent("vrr.vehBuyState", VRR_VEHBUYSTATE_WRONGVEH); + } + } + } +} + +// =========================================================================== + +function setVehiclePurchaseState(state, vehicle, position) { + vehiclePurchaseState = state; + vehiclePurchasePosition = position; + vehiclePurchasing = vehicle; +} + // =========================================================================== \ No newline at end of file