Skip to content

Commit

Permalink
Added engine methods on scripting / netwokring
Browse files Browse the repository at this point in the history
  • Loading branch information
Segfaultd committed Feb 5, 2024
1 parent f3dd5e4 commit 251a627
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
7 changes: 7 additions & 0 deletions code/client/src/core/modules/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -326,6 +329,10 @@ namespace MafiaMP::Core::Modules {
updateData->dirt = dirt();
}

if (engineOn.HasValue()) {
updateData->engineOn = engineOn();
}

if (fuel.HasValue()) {
updateData->fuel = fuel();
}
Expand Down
21 changes: 18 additions & 3 deletions code/server/src/core/builtins/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Shared::Modules::VehicleSync::UpdateData>();
return syncData->engineOn;
}

void SetEngineOn(bool on) {
auto vehData = _ent.get_mut<Shared::Modules::VehicleSync::UpdateData>();
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;
Expand All @@ -239,27 +252,29 @@ namespace MafiaMP::Scripting {
v8pp::class_<Vehicle> cls(isolate);
cls.inherit<Framework::Integrations::Scripting::Entity>();

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);
cls.function("getRadioOn", &Vehicle::GetRadioOn);
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);
Expand Down
3 changes: 3 additions & 0 deletions code/shared/game_rpc/vehicle/vehicle_setprops.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace MafiaMP::Shared::RPC {
Framework::Utils::Optional<glm::vec4> rimColor;
Framework::Utils::Optional<float> rust;
Framework::Utils::Optional<bool> sirenOn;
Framework::Utils::Optional<bool> engineOn;
Framework::Utils::Optional<glm::vec4> tireColor;
Framework::Utils::Optional<glm::vec4> windowTint;

Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions code/shared/modules/vehicle_sync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down

0 comments on commit 251a627

Please sign in to comment.