Offload vehicle purchase logic to clientside

This commit is contained in:
Vortrex
2021-12-03 10:19:43 -06:00
parent 6b1063dc51
commit 4e39061c71
4 changed files with 37 additions and 0 deletions

View File

@@ -94,6 +94,7 @@ function onProcess(event, deltaTime) {
processWantedLevelReset();
processGameSpecifics();
processNearbyPickups();
processVehiclePurchasing();
}
// ===========================================================================

View File

@@ -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());

View File

@@ -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);

View File

@@ -820,3 +820,33 @@ function processGameSpecifics() {
}
// ===========================================================================
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;
}
// ===========================================================================