From 251a627d86e9701869fd706a8c1913d424459998 Mon Sep 17 00:00:00 2001 From: Segfault <5221072+Segfaultd@users.noreply.github.com> Date: Mon, 5 Feb 2024 22:06:47 +0100 Subject: [PATCH] Added engine methods on scripting / netwokring --- code/client/src/core/modules/vehicle.cpp | 7 +++++++ code/server/src/core/builtins/vehicle.h | 21 ++++++++++++++++--- .../game_rpc/vehicle/vehicle_setprops.h | 3 +++ code/shared/modules/vehicle_sync.hpp | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/code/client/src/core/modules/vehicle.cpp b/code/client/src/core/modules/vehicle.cpp index 13131c67..5c75af60 100644 --- a/code/client/src/core/modules/vehicle.cpp +++ b/code/client/src/core/modules/vehicle.cpp @@ -72,6 +72,7 @@ namespace MafiaMP::Core::Modules { metadata.rimColor = {rimColor.r, rimColor.g, rimColor.b, rimColor.a}; metadata.rust = vehicle->GetVehicleRust(); metadata.sirenOn = vehicle->IsSiren(); + metadata.engineOn = car->IsEngineOn(); metadata.steer = vehicle->GetSteer(); metadata.tireColor = {tireColor.r, tireColor.g, tireColor.b, tireColor.a}; metadata.velocity = {vehicleVelocity.x, vehicleVelocity.y, vehicleVelocity.z}; @@ -204,6 +205,7 @@ namespace MafiaMP::Core::Modules { vehicle->SetVehicleColor(&colorPrimary, &colorSecondary, false); car->SetVehicleDirty(updateData->dirt); // We have to use the car to set the dirt otherwise the value is reset car->SetActualFuel(updateData->fuel); + vehicle->SetEngineOn(updateData->engineOn, updateData->engineOn); vehicle->SetGear(updateData->gear); vehicle->SetHandbrake(updateData->handbrake, false); vehicle->SetHorn(updateData->hornOn); @@ -299,6 +301,7 @@ namespace MafiaMP::Core::Modules { const auto colorPrimary = msg->colorPrimary; const auto colorSecondary = msg->colorSecondary; const auto dirt = msg->dirt; + const auto engineOn = msg->engineOn; const auto fuel = msg->fuel; const auto licensePlate = msg->licensePlate; const auto lockState = msg->lockState; @@ -326,6 +329,10 @@ namespace MafiaMP::Core::Modules { updateData->dirt = dirt(); } + if (engineOn.HasValue()) { + updateData->engineOn = engineOn(); + } + if (fuel.HasValue()) { updateData->fuel = fuel(); } diff --git a/code/server/src/core/builtins/vehicle.h b/code/server/src/core/builtins/vehicle.h index 83b14576..39f17fb3 100644 --- a/code/server/src/core/builtins/vehicle.h +++ b/code/server/src/core/builtins/vehicle.h @@ -231,6 +231,19 @@ namespace MafiaMP::Scripting { FW_SEND_SERVER_COMPONENT_GAME_RPC(Shared::RPC::VehicleSetProps, _ent, msg); } + bool GetEngineOn() { + auto syncData = _ent.get_mut(); + return syncData->engineOn; + } + + void SetEngineOn(bool on) { + auto vehData = _ent.get_mut(); + vehData->engineOn = on; + MafiaMP::Shared::RPC::VehicleSetProps msg {}; + msg.engineOn = on; + FW_SEND_SERVER_COMPONENT_GAME_RPC(Shared::RPC::VehicleSetProps, _ent, msg); + } + static void Register(v8::Isolate *isolate, v8pp::module *rootModule) { if (!rootModule) { return; @@ -239,10 +252,11 @@ namespace MafiaMP::Scripting { v8pp::class_ cls(isolate); cls.inherit(); - cls.function("getBeaconLightsOn", &Vehicle::GetBeaconLightsOn); // TODO: doesn't work yet + cls.function("getBeaconLightsOn", &Vehicle::GetBeaconLightsOn); cls.function("getColorPrimary", &Vehicle::GetColorPrimary); cls.function("getColorSecondary", &Vehicle::GetColorSecondary); cls.function("getDirt", &Vehicle::GetDirt); + cls.function("getEngineOn", &Vehicle::GetEngineOn); cls.function("getFuel", &Vehicle::GetFuel); cls.function("getLicensePlate", &Vehicle::GetLicensePlate); cls.function("getLockState", &Vehicle::GetLockState); @@ -250,16 +264,17 @@ namespace MafiaMP::Scripting { cls.function("getRadioStationId", &Vehicle::GetRadioStationId); cls.function("getRimColor", &Vehicle::GetRimColor); cls.function("getRust", &Vehicle::GetRust); - cls.function("getSirenOn", &Vehicle::GetSirenOn); // TODO: doesn't work yet + cls.function("getSirenOn", &Vehicle::GetSirenOn); cls.function("getTireColor", &Vehicle::GetTireColor); cls.function("getWindowTint", &Vehicle::GetWindowTint); cls.function("setBeaconLightsOn", &Vehicle::SetBeaconLightsOn); cls.function("setColorPrimary", &Vehicle::SetColorPrimary); cls.function("setColorSecondary", &Vehicle::SetColorSecondary); cls.function("setDirt", &Vehicle::SetDirt); + cls.function("setEngineOn", &Vehicle::SetEngineOn); cls.function("setFuel", &Vehicle::SetFuel); cls.function("setLicensePlate", &Vehicle::SetLicensePlate); - cls.function("setLockState", &Vehicle::SetLockState); // TODO: doesn't work yet + cls.function("setLockState", &Vehicle::SetLockState); cls.function("setRadioOn", &Vehicle::SetRadioOn); cls.function("setRadioStationId", &Vehicle::SetRadioStationId); cls.function("setRimColor", &Vehicle::SetRimColor); diff --git a/code/shared/game_rpc/vehicle/vehicle_setprops.h b/code/shared/game_rpc/vehicle/vehicle_setprops.h index 4dea6ca2..dffcd458 100644 --- a/code/shared/game_rpc/vehicle/vehicle_setprops.h +++ b/code/shared/game_rpc/vehicle/vehicle_setprops.h @@ -19,6 +19,7 @@ namespace MafiaMP::Shared::RPC { Framework::Utils::Optional rimColor; Framework::Utils::Optional rust; Framework::Utils::Optional sirenOn; + Framework::Utils::Optional engineOn; Framework::Utils::Optional tireColor; Framework::Utils::Optional windowTint; @@ -35,6 +36,7 @@ namespace MafiaMP::Shared::RPC { this->rimColor = props.rimColor; this->rust = props.rust; this->sirenOn = props.sirenOn; + this->engineOn = props.engineOn; this->tireColor = props.tireColor; this->windowTint = props.windowTint; } @@ -52,6 +54,7 @@ namespace MafiaMP::Shared::RPC { rimColor.Serialize(bs, write); rust.Serialize(bs, write); sirenOn.Serialize(bs, write); + engineOn.Serialize(bs, write); tireColor.Serialize(bs, write); windowTint.Serialize(bs, write); } diff --git a/code/shared/modules/vehicle_sync.hpp b/code/shared/modules/vehicle_sync.hpp index 48ed9737..e8b0d9af 100644 --- a/code/shared/modules/vehicle_sync.hpp +++ b/code/shared/modules/vehicle_sync.hpp @@ -33,6 +33,7 @@ namespace MafiaMP::Shared::Modules { glm::vec4 rimColor {1.0f, 1.0f, 1.0f, 1.0f}; float rust = 0.0f; bool sirenOn = false; + bool engineOn = false; float steer = 0.0f; glm::vec4 tireColor {1.0f, 1.0f, 1.0f, 1.0f}; glm::vec3 velocity {};