Skip to content

Commit

Permalink
Adding client functions addVehicleSirens & removeVehicleSirens (PR #3704
Browse files Browse the repository at this point in the history
, Fixes #3215)
  • Loading branch information
Proxy-99 authored Dec 30, 2024
1 parent e9e5819 commit 682cdca
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 31 deletions.
27 changes: 26 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ void CLuaVehicleDefs::LoadFunctions()
{"setVehicleDoorsUndamageable", SetVehicleDoorsUndamageable},
{"setVehicleSirensOn", SetVehicleSirensOn},
{"addVehicleUpgrade", AddVehicleUpgrade},
{"addVehicleSirens", ArgumentParser<AddVehicleSirens>},
{"removeVehicleUpgrade", RemoveVehicleUpgrade},
{"removeVehicleSirens", ArgumentParser<RemoveVehicleSirens>},
{"setVehicleDoorState", SetVehicleDoorState},
{"setVehicleWheelStates", SetVehicleWheelStates},
{"setVehicleLightState", SetVehicleLightState},
Expand Down Expand Up @@ -4358,6 +4360,30 @@ bool CLuaVehicleDefs::SpawnVehicleFlyingComponent(CClientVehicle* const vehicle,
return vehicle->SpawnFlyingComponent(partNodeIndex, collisionType, removalTime.value_or(-1));
}

bool CLuaVehicleDefs::AddVehicleSirens(CClientVehicle* vehicle, std::uint8_t sirenType, std::uint8_t sirenCount, std::optional<bool> enable360, std::optional<bool> enableLOSCheck, std::optional<bool> enableRandomiser, std::optional<bool> enableSilent) noexcept
{
eClientVehicleType vehicleType = vehicle->GetVehicleType();

if (vehicleType != CLIENTVEHICLE_CAR && vehicleType != CLIENTVEHICLE_MONSTERTRUCK && vehicleType != CLIENTVEHICLE_QUADBIKE)
return false;

if (sirenType < 1 || sirenType > 6)
return false;

if (sirenCount < 0 || sirenCount > SIREN_COUNT_MAX)
return false;

vehicle->GiveVehicleSirens(sirenType, sirenCount);
vehicle->SetVehicleFlags(enable360.value_or(false), enableRandomiser.value_or(true), enableLOSCheck.value_or(true), enableSilent.value_or(false));
return true;
}

bool CLuaVehicleDefs::RemoveVehicleSirens(CClientVehicle* vehicle) noexcept
{
vehicle->RemoveVehicleSirens();
return true;
}

bool CLuaVehicleDefs::SetSmokeTrailEnabled(CClientVehicle* vehicle, bool state)
{
std::uint16_t model = vehicle->GetModel();
Expand All @@ -4372,4 +4398,3 @@ bool CLuaVehicleDefs::IsSmokeTrailEnabled(CClientVehicle* vehicle) noexcept
{
return vehicle->IsSmokeTrailEnabled();
}

3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ class CLuaVehicleDefs : public CLuaDefs
static bool SetVehicleModelWheelSize(const unsigned short usModel, const eResizableVehicleWheelGroup eWheelGroup, const float fWheelSize);
static int GetVehicleWheelFrictionState(CClientVehicle* pVehicle, unsigned char wheel);

static bool AddVehicleSirens(CClientVehicle* vehicle, std::uint8_t sirenType, std::uint8_t sirenCount, std::optional<bool> enable360, std::optional<bool> enableLOSCheck, std::optional<bool> enableRandomiser, std::optional<bool> enableSilent) noexcept;
static bool RemoveVehicleSirens(CClientVehicle* vehicle) noexcept;

// Components
LUA_DECLARE(SetVehicleComponentPosition);
LUA_DECLARE_OOP(GetVehicleComponentPosition);
Expand Down
58 changes: 28 additions & 30 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4938,40 +4938,38 @@ bool CStaticFunctionDefinitions::GiveVehicleSirens(CVehicle* pVehicle, unsigned
assert(pVehicle);
eVehicleType vehicleType = CVehicleManager::GetVehicleType(pVehicle->GetModel());
// Won't work with below.
if (vehicleType != VEHICLE_PLANE && vehicleType != VEHICLE_BOAT && vehicleType != VEHICLE_TRAILER && vehicleType != VEHICLE_HELI &&
vehicleType != VEHICLE_BIKE && vehicleType != VEHICLE_BMX)
{
if (ucSirenType >= 1 && ucSirenType <= 6)
{
if (ucSirenCount <= SIREN_COUNT_MAX)
{
pVehicle->m_tSirenBeaconInfo.m_bOverrideSirens = true;
if (vehicleType != VEHICLE_CAR && vehicleType != VEHICLE_MONSTERTRUCK && vehicleType != VEHICLE_QUADBIKE)
return false;

pVehicle->m_tSirenBeaconInfo.m_ucSirenCount = ucSirenCount;
pVehicle->m_tSirenBeaconInfo.m_ucSirenType = ucSirenType;
if (ucSirenType < 1 || ucSirenType > 6)
return false;

pVehicle->m_tSirenBeaconInfo.m_b360Flag = tSirenInfo.m_b360Flag;
pVehicle->m_tSirenBeaconInfo.m_bDoLOSCheck = tSirenInfo.m_bDoLOSCheck;
pVehicle->m_tSirenBeaconInfo.m_bUseRandomiser = tSirenInfo.m_bUseRandomiser;
pVehicle->m_tSirenBeaconInfo.m_bSirenSilent = tSirenInfo.m_bSirenSilent;
if (ucSirenCount > SIREN_COUNT_MAX)
return false;

SVehicleSirenAddSync tSirenSync;
tSirenSync.data.m_bOverrideSirens = pVehicle->m_tSirenBeaconInfo.m_bOverrideSirens;
tSirenSync.data.m_b360Flag = pVehicle->m_tSirenBeaconInfo.m_b360Flag;
tSirenSync.data.m_bDoLOSCheck = pVehicle->m_tSirenBeaconInfo.m_bDoLOSCheck;
tSirenSync.data.m_bEnableSilent = pVehicle->m_tSirenBeaconInfo.m_bSirenSilent;
tSirenSync.data.m_bUseRandomiser = pVehicle->m_tSirenBeaconInfo.m_bUseRandomiser;
tSirenSync.data.m_ucSirenCount = pVehicle->m_tSirenBeaconInfo.m_ucSirenCount;
tSirenSync.data.m_ucSirenType = pVehicle->m_tSirenBeaconInfo.m_ucSirenType;
pVehicle->m_tSirenBeaconInfo.m_bOverrideSirens = true;

CBitStream BitStream;
BitStream.pBitStream->Write(&tSirenSync);
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pVehicle, GIVE_VEHICLE_SIRENS, *BitStream.pBitStream));
return true;
}
}
}
return false;
pVehicle->m_tSirenBeaconInfo.m_ucSirenCount = ucSirenCount;
pVehicle->m_tSirenBeaconInfo.m_ucSirenType = ucSirenType;

pVehicle->m_tSirenBeaconInfo.m_b360Flag = tSirenInfo.m_b360Flag;
pVehicle->m_tSirenBeaconInfo.m_bDoLOSCheck = tSirenInfo.m_bDoLOSCheck;
pVehicle->m_tSirenBeaconInfo.m_bUseRandomiser = tSirenInfo.m_bUseRandomiser;
pVehicle->m_tSirenBeaconInfo.m_bSirenSilent = tSirenInfo.m_bSirenSilent;

SVehicleSirenAddSync tSirenSync;
tSirenSync.data.m_bOverrideSirens = pVehicle->m_tSirenBeaconInfo.m_bOverrideSirens;
tSirenSync.data.m_b360Flag = pVehicle->m_tSirenBeaconInfo.m_b360Flag;
tSirenSync.data.m_bDoLOSCheck = pVehicle->m_tSirenBeaconInfo.m_bDoLOSCheck;
tSirenSync.data.m_bEnableSilent = pVehicle->m_tSirenBeaconInfo.m_bSirenSilent;
tSirenSync.data.m_bUseRandomiser = pVehicle->m_tSirenBeaconInfo.m_bUseRandomiser;
tSirenSync.data.m_ucSirenCount = pVehicle->m_tSirenBeaconInfo.m_ucSirenCount;
tSirenSync.data.m_ucSirenType = pVehicle->m_tSirenBeaconInfo.m_ucSirenType;

CBitStream BitStream;
BitStream.pBitStream->Write(&tSirenSync);
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pVehicle, GIVE_VEHICLE_SIRENS, *BitStream.pBitStream));
return true;
}

bool CStaticFunctionDefinitions::SetVehicleSirens(CVehicle* pVehicle, unsigned char ucSirenID, SSirenInfo tSirenInfo)
Expand Down

0 comments on commit 682cdca

Please sign in to comment.