Skip to content

Commit

Permalink
Adding setVehicleNitroActivated server-side (PR #3706)
Browse files Browse the repository at this point in the history
  • Loading branch information
Proxy-99 authored Dec 30, 2024
1 parent ad68386 commit e9e5819
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
24 changes: 24 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -667,3 +668,26 @@ void CVehicleRPCs::SpawnVehicleFlyingComponent(CClientEntity* const sourceEntity
if (bitStream.Read(nodeIndex) && bitStream.Read(collisionType) && bitStream.Read(removalTime))
vehicle->SpawnFlyingComponent(static_cast<eCarNodes>(nodeIndex), static_cast<eCarComponentCollisionTypes>(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);
}

1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/rpc/CVehicleRPCs.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ class CVehicleRPCs : public CRPCFunctions
DECLARE_ELEMENT_RPC(SetVehicleSirens);
DECLARE_ELEMENT_RPC(SetVehiclePlateText);
DECLARE_ELEMENT_RPC(SpawnVehicleFlyingComponent);
DECLARE_ELEMENT_RPC(SetVehicleNitroActivated);
};
10 changes: 10 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void CLuaVehicleDefs::LoadFunctions()
{"getVehicleSirens", GetVehicleSirens},
{"getVehicleSirenParams", GetVehicleSirenParams},
{"setVehiclePlateText", SetVehiclePlateText},
{"setVehicleNitroActivated", ArgumentParser<SetVehicleNitroActivated>},
};

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

return CStaticFunctionDefinitions::SpawnVehicleFlyingComponent(vehicle, nodeIndex, static_cast<std::uint8_t>(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;
}
3 changes: 2 additions & 1 deletion Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t> componentCollisionType, std::optional<std::uint32_t> removalTime);
static bool SetVehicleNitroActivated(CVehicle* vehicle, bool state) noexcept;
};
6 changes: 3 additions & 3 deletions Shared/sdk/net/rpc_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

0 comments on commit e9e5819

Please sign in to comment.