diff --git a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp index 7915c2c7d41..50d5028caf8 100644 --- a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp @@ -53,6 +53,7 @@ void CVehicleRPCs::LoadFunctions() AddHandler(SET_VEHICLE_SIRENS, SetVehicleSirens, "setVehicleSirens"); AddHandler(SET_VEHICLE_PLATE_TEXT, SetVehiclePlateText, "setVehiclePlateText"); AddHandler(SPAWN_VEHICLE_FLYING_COMPONENT, SpawnVehicleFlyingComponent, "spawnVehicleFlyingComponent"); + AddHandler(SET_VEHICLE_NITRO_ACTIVATED, SetVehicleNitroActivated, "SetVehicleNitroActivated"); } void CVehicleRPCs::DestroyAllVehicles(NetBitStreamInterface& bitStream) @@ -667,3 +668,26 @@ void CVehicleRPCs::SpawnVehicleFlyingComponent(CClientEntity* const sourceEntity if (bitStream.Read(nodeIndex) && bitStream.Read(collisionType) && bitStream.Read(removalTime)) vehicle->SpawnFlyingComponent(static_cast(nodeIndex), static_cast(collisionType), removalTime); } + +void CVehicleRPCs::SetVehicleNitroActivated(CClientEntity* pSourceEntity, NetBitStreamInterface& bitStream) +{ + bool state = bitStream.ReadBit(); + + CClientVehicle* vehicle = m_pVehicleManager->Get(pSourceEntity->GetID()); + if (!vehicle) + return; + + if (!vehicle->IsNitroInstalled()) + return; + + // If nitro level < 0, nitro is activated. (until nitro level reaches -1, at that point it will become 0 and increase instead of decrease) + if ((vehicle->GetNitroLevel() < 0.0f) == state) + return; + + // Apply nitro level change + if (state) + vehicle->SetNitroLevel(vehicle->GetNitroLevel() - 1.0001f); + else + vehicle->SetNitroLevel(vehicle->GetNitroLevel() + 1.0001f); +} + diff --git a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.h b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.h index 6d4e9f5d197..4107c03f51a 100644 --- a/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.h +++ b/Client/mods/deathmatch/logic/rpc/CVehicleRPCs.h @@ -58,4 +58,5 @@ class CVehicleRPCs : public CRPCFunctions DECLARE_ELEMENT_RPC(SetVehicleSirens); DECLARE_ELEMENT_RPC(SetVehiclePlateText); DECLARE_ELEMENT_RPC(SpawnVehicleFlyingComponent); + DECLARE_ELEMENT_RPC(SetVehicleNitroActivated); }; diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index d34d8fe579f..55ab0e06312 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -127,6 +127,7 @@ void CLuaVehicleDefs::LoadFunctions() {"getVehicleSirens", GetVehicleSirens}, {"getVehicleSirenParams", GetVehicleSirenParams}, {"setVehiclePlateText", SetVehiclePlateText}, + {"setVehicleNitroActivated", ArgumentParser}, }; // Add functions @@ -3046,3 +3047,12 @@ bool CLuaVehicleDefs::SpawnVehicleFlyingComponent(CVehicle* const vehicle, std:: return CStaticFunctionDefinitions::SpawnVehicleFlyingComponent(vehicle, nodeIndex, static_cast(collisionType), removalTime.value_or(-1)); } + +bool CLuaVehicleDefs::SetVehicleNitroActivated(CVehicle* vehicle, bool state) noexcept +{ + CBitStream BitStream; + BitStream.pBitStream->WriteBit(state); + + m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(vehicle, SET_VEHICLE_NITRO_ACTIVATED, *BitStream.pBitStream)); + return true; +} \ No newline at end of file diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h index b3497361138..11b23691dcb 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h @@ -125,6 +125,7 @@ class CLuaVehicleDefs : public CLuaDefs LUA_DECLARE(GetVehicleSirens); LUA_DECLARE(GetVehicleSirenParams); LUA_DECLARE(SetVehiclePlateText); - + static bool SpawnVehicleFlyingComponent(CVehicle* const vehicle, std::uint8_t nodeIndex, std::optional componentCollisionType, std::optional removalTime); + static bool SetVehicleNitroActivated(CVehicle* vehicle, bool state) noexcept; }; diff --git a/Shared/sdk/net/rpc_enums.h b/Shared/sdk/net/rpc_enums.h index 2318908f4e2..08e18eb0772 100644 --- a/Shared/sdk/net/rpc_enums.h +++ b/Shared/sdk/net/rpc_enums.h @@ -285,10 +285,10 @@ enum eElementRPCFunctions RESPAWN_OBJECT, TOGGLE_OBJECT_RESPAWN, - RESET_WORLD_PROPERTIES, - + SPAWN_VEHICLE_FLYING_COMPONENT, - + SET_VEHICLE_NITRO_ACTIVATED, + NUM_RPC_FUNCS // Add above this line };