Skip to content

Commit e9e5819

Browse files
authored
Adding setVehicleNitroActivated server-side (PR #3706)
1 parent ad68386 commit e9e5819

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void CVehicleRPCs::LoadFunctions()
5353
AddHandler(SET_VEHICLE_SIRENS, SetVehicleSirens, "setVehicleSirens");
5454
AddHandler(SET_VEHICLE_PLATE_TEXT, SetVehiclePlateText, "setVehiclePlateText");
5555
AddHandler(SPAWN_VEHICLE_FLYING_COMPONENT, SpawnVehicleFlyingComponent, "spawnVehicleFlyingComponent");
56+
AddHandler(SET_VEHICLE_NITRO_ACTIVATED, SetVehicleNitroActivated, "SetVehicleNitroActivated");
5657
}
5758

5859
void CVehicleRPCs::DestroyAllVehicles(NetBitStreamInterface& bitStream)
@@ -667,3 +668,26 @@ void CVehicleRPCs::SpawnVehicleFlyingComponent(CClientEntity* const sourceEntity
667668
if (bitStream.Read(nodeIndex) && bitStream.Read(collisionType) && bitStream.Read(removalTime))
668669
vehicle->SpawnFlyingComponent(static_cast<eCarNodes>(nodeIndex), static_cast<eCarComponentCollisionTypes>(collisionType), removalTime);
669670
}
671+
672+
void CVehicleRPCs::SetVehicleNitroActivated(CClientEntity* pSourceEntity, NetBitStreamInterface& bitStream)
673+
{
674+
bool state = bitStream.ReadBit();
675+
676+
CClientVehicle* vehicle = m_pVehicleManager->Get(pSourceEntity->GetID());
677+
if (!vehicle)
678+
return;
679+
680+
if (!vehicle->IsNitroInstalled())
681+
return;
682+
683+
// If nitro level < 0, nitro is activated. (until nitro level reaches -1, at that point it will become 0 and increase instead of decrease)
684+
if ((vehicle->GetNitroLevel() < 0.0f) == state)
685+
return;
686+
687+
// Apply nitro level change
688+
if (state)
689+
vehicle->SetNitroLevel(vehicle->GetNitroLevel() - 1.0001f);
690+
else
691+
vehicle->SetNitroLevel(vehicle->GetNitroLevel() + 1.0001f);
692+
}
693+

Client/mods/deathmatch/logic/rpc/CVehicleRPCs.h

+1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ class CVehicleRPCs : public CRPCFunctions
5858
DECLARE_ELEMENT_RPC(SetVehicleSirens);
5959
DECLARE_ELEMENT_RPC(SetVehiclePlateText);
6060
DECLARE_ELEMENT_RPC(SpawnVehicleFlyingComponent);
61+
DECLARE_ELEMENT_RPC(SetVehicleNitroActivated);
6162
};

Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ void CLuaVehicleDefs::LoadFunctions()
127127
{"getVehicleSirens", GetVehicleSirens},
128128
{"getVehicleSirenParams", GetVehicleSirenParams},
129129
{"setVehiclePlateText", SetVehiclePlateText},
130+
{"setVehicleNitroActivated", ArgumentParser<SetVehicleNitroActivated>},
130131
};
131132

132133
// Add functions
@@ -3046,3 +3047,12 @@ bool CLuaVehicleDefs::SpawnVehicleFlyingComponent(CVehicle* const vehicle, std::
30463047

30473048
return CStaticFunctionDefinitions::SpawnVehicleFlyingComponent(vehicle, nodeIndex, static_cast<std::uint8_t>(collisionType), removalTime.value_or(-1));
30483049
}
3050+
3051+
bool CLuaVehicleDefs::SetVehicleNitroActivated(CVehicle* vehicle, bool state) noexcept
3052+
{
3053+
CBitStream BitStream;
3054+
BitStream.pBitStream->WriteBit(state);
3055+
3056+
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(vehicle, SET_VEHICLE_NITRO_ACTIVATED, *BitStream.pBitStream));
3057+
return true;
3058+
}

Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class CLuaVehicleDefs : public CLuaDefs
125125
LUA_DECLARE(GetVehicleSirens);
126126
LUA_DECLARE(GetVehicleSirenParams);
127127
LUA_DECLARE(SetVehiclePlateText);
128-
128+
129129
static bool SpawnVehicleFlyingComponent(CVehicle* const vehicle, std::uint8_t nodeIndex, std::optional<std::uint8_t> componentCollisionType, std::optional<std::uint32_t> removalTime);
130+
static bool SetVehicleNitroActivated(CVehicle* vehicle, bool state) noexcept;
130131
};

Shared/sdk/net/rpc_enums.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,10 @@ enum eElementRPCFunctions
285285

286286
RESPAWN_OBJECT,
287287
TOGGLE_OBJECT_RESPAWN,
288-
289288
RESET_WORLD_PROPERTIES,
290-
289+
291290
SPAWN_VEHICLE_FLYING_COMPONENT,
292-
291+
SET_VEHICLE_NITRO_ACTIVATED,
292+
293293
NUM_RPC_FUNCS // Add above this line
294294
};

0 commit comments

Comments
 (0)