Skip to content

Add nitro vehicle functions server side #3951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CNetAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,9 @@ void CNetAPI::WriteVehiclePuresync(CClientPed* pPlayerModel, CClientVehicle* pVe

// Write the sent position to the interpolator
AddInterpolation(vecPosition);

if (BitStream.Can(eBitStreamVersion::IsVehicleNitroActivated_Serverside))
BitStream.Write(pVehicle->GetNitroLevel());
}

bool CNetAPI::ReadSmallKeysync(CControllerState& ControllerState, NetBitStreamInterface& BitStream)
Expand Down
5 changes: 5 additions & 0 deletions Server/mods/deathmatch/logic/CVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ class CVehicle final : public CElement
bool IsOnFire() const noexcept override { return m_onFire; }
void SetOnFire(bool onFire) noexcept override { m_onFire = onFire; }

void SetNitroLevel(float level) noexcept { m_nitroLevel = level; }
float GetNitroLevel() const noexcept { return m_nitroLevel; }
bool IsNitroActivated() const noexcept { return m_nitroLevel < 0; }

void StopIdleTimer();
void RestartIdleTimer();
bool IsIdleTimerRunning();
Expand Down Expand Up @@ -495,6 +499,7 @@ class CVehicle final : public CElement
unsigned char m_ucVariant2;

bool m_onFire;
float m_nitroLevel;

CTickCount m_LastPushedTime;
CVector m_vecStationaryCheckPosition;
Expand Down
21 changes: 20 additions & 1 deletion Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ void CLuaVehicleDefs::LoadFunctions()
{"getVehicleSirenParams", GetVehicleSirenParams},
{"setVehiclePlateText", SetVehiclePlateText},
{"setVehicleNitroActivated", ArgumentParser<SetVehicleNitroActivated>},
{"isVehicleNitroActivated", ArgumentParser<IsVehicleNitroActivated>},
{"getVehicleNitroLevel", ArgumentParser<GetVehicleNitroLevel>},
};

// Add functions
Expand Down Expand Up @@ -3059,4 +3061,21 @@ bool CLuaVehicleDefs::SetVehicleNitroActivated(CVehicle* vehicle, bool state) no

m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(vehicle, SET_VEHICLE_NITRO_ACTIVATED, *BitStream.pBitStream));
return true;
}
}

bool CLuaVehicleDefs::IsVehicleNitroActivated(CVehicle* vehicle) noexcept
{
return vehicle->IsNitroActivated();
}

float CLuaVehicleDefs::GetVehicleNitroLevel(CVehicle* vehicle) noexcept
{
float fLevel;
fLevel = vehicle->GetNitroLevel();

if (fLevel < 0)
fLevel = 1 + fLevel;

return fLevel;

}
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,6 @@ class CLuaVehicleDefs : public CLuaDefs

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;
static bool IsVehicleNitroActivated(CVehicle* vehicle) noexcept;
static float GetVehicleNitroLevel(CVehicle* vehicle) noexcept;
};
14 changes: 14 additions & 0 deletions Server/mods/deathmatch/logic/net/CSimVehiclePuresyncPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ bool CSimVehiclePuresyncPacket::Read(NetBitStreamInterface& BitStream)
if (BitStream.Can(eBitStreamVersion::SetElementOnFire))
m_Cache.isOnFire = BitStream.ReadBit();

if (BitStream.Can(eBitStreamVersion::IsVehicleNitroActivated_Serverside))
{
float vehicleNitro;
if (!BitStream.Read(vehicleNitro))
return false;

m_Cache.VehNitroLevel = vehicleNitro;
}


// Success
return true;
}
Expand Down Expand Up @@ -424,6 +434,10 @@ bool CSimVehiclePuresyncPacket::Write(NetBitStreamInterface& BitStream) const
if (BitStream.Can(eBitStreamVersion::SetElementOnFire))
BitStream.WriteBit(m_Cache.isOnFire);


if (BitStream.Can(eBitStreamVersion::IsVehicleNitroActivated_Serverside))
BitStream.Write(m_Cache.VehNitroLevel);

// Success
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class CSimVehiclePuresyncPacket : public CSimPacket
CVector VehTurnSpeed;

float fVehHealth;
float VehNitroLevel;

std::vector<STrailerInfo> TrailerList;

Expand Down
13 changes: 13 additions & 0 deletions Server/mods/deathmatch/logic/packets/CVehiclePuresyncPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,16 @@ bool CVehiclePuresyncPacket::Read(NetBitStreamInterface& BitStream)
if (BitStream.Can(eBitStreamVersion::SetElementOnFire))
pVehicle->SetOnFire(BitStream.ReadBit());

if (BitStream.Can(eBitStreamVersion::IsVehicleNitroActivated_Serverside))
{
float vehicleNitro;
if (!BitStream.Read(vehicleNitro))
return false;

pVehicle->SetNitroLevel(vehicleNitro);

}

// Success
return true;
}
Expand Down Expand Up @@ -682,6 +692,9 @@ bool CVehiclePuresyncPacket::Write(NetBitStreamInterface& BitStream) const
if (BitStream.Can(eBitStreamVersion::SetElementOnFire))
BitStream.WriteBit(pVehicle->IsOnFire());

if (BitStream.Can(eBitStreamVersion::IsVehicleNitroActivated_Serverside))
BitStream.Write(pVehicle->GetNitroLevel());

// Success
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions Shared/sdk/net/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ enum class eBitStreamVersion : unsigned short
// 2025-01-10
WorldSpecialProperty_FlyingComponents,

IsVehicleNitroActivated_Serverside,

// This allows us to automatically increment the BitStreamVersion when things are added to this enum.
// Make sure you only add things above this comment.
Next,
Expand Down
Loading