Skip to content

Commit 682cdca

Browse files
authored
Adding client functions addVehicleSirens & removeVehicleSirens (PR #3704, Fixes #3215)
1 parent e9e5819 commit 682cdca

File tree

3 files changed

+57
-31
lines changed

3 files changed

+57
-31
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ void CLuaVehicleDefs::LoadFunctions()
106106
{"setVehicleDoorsUndamageable", SetVehicleDoorsUndamageable},
107107
{"setVehicleSirensOn", SetVehicleSirensOn},
108108
{"addVehicleUpgrade", AddVehicleUpgrade},
109+
{"addVehicleSirens", ArgumentParser<AddVehicleSirens>},
109110
{"removeVehicleUpgrade", RemoveVehicleUpgrade},
111+
{"removeVehicleSirens", ArgumentParser<RemoveVehicleSirens>},
110112
{"setVehicleDoorState", SetVehicleDoorState},
111113
{"setVehicleWheelStates", SetVehicleWheelStates},
112114
{"setVehicleLightState", SetVehicleLightState},
@@ -4358,6 +4360,30 @@ bool CLuaVehicleDefs::SpawnVehicleFlyingComponent(CClientVehicle* const vehicle,
43584360
return vehicle->SpawnFlyingComponent(partNodeIndex, collisionType, removalTime.value_or(-1));
43594361
}
43604362

4363+
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
4364+
{
4365+
eClientVehicleType vehicleType = vehicle->GetVehicleType();
4366+
4367+
if (vehicleType != CLIENTVEHICLE_CAR && vehicleType != CLIENTVEHICLE_MONSTERTRUCK && vehicleType != CLIENTVEHICLE_QUADBIKE)
4368+
return false;
4369+
4370+
if (sirenType < 1 || sirenType > 6)
4371+
return false;
4372+
4373+
if (sirenCount < 0 || sirenCount > SIREN_COUNT_MAX)
4374+
return false;
4375+
4376+
vehicle->GiveVehicleSirens(sirenType, sirenCount);
4377+
vehicle->SetVehicleFlags(enable360.value_or(false), enableRandomiser.value_or(true), enableLOSCheck.value_or(true), enableSilent.value_or(false));
4378+
return true;
4379+
}
4380+
4381+
bool CLuaVehicleDefs::RemoveVehicleSirens(CClientVehicle* vehicle) noexcept
4382+
{
4383+
vehicle->RemoveVehicleSirens();
4384+
return true;
4385+
}
4386+
43614387
bool CLuaVehicleDefs::SetSmokeTrailEnabled(CClientVehicle* vehicle, bool state)
43624388
{
43634389
std::uint16_t model = vehicle->GetModel();
@@ -4372,4 +4398,3 @@ bool CLuaVehicleDefs::IsSmokeTrailEnabled(CClientVehicle* vehicle) noexcept
43724398
{
43734399
return vehicle->IsSmokeTrailEnabled();
43744400
}
4375-

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ class CLuaVehicleDefs : public CLuaDefs
166166
static bool SetVehicleModelWheelSize(const unsigned short usModel, const eResizableVehicleWheelGroup eWheelGroup, const float fWheelSize);
167167
static int GetVehicleWheelFrictionState(CClientVehicle* pVehicle, unsigned char wheel);
168168

169+
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;
170+
static bool RemoveVehicleSirens(CClientVehicle* vehicle) noexcept;
171+
169172
// Components
170173
LUA_DECLARE(SetVehicleComponentPosition);
171174
LUA_DECLARE_OOP(GetVehicleComponentPosition);

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4938,40 +4938,38 @@ bool CStaticFunctionDefinitions::GiveVehicleSirens(CVehicle* pVehicle, unsigned
49384938
assert(pVehicle);
49394939
eVehicleType vehicleType = CVehicleManager::GetVehicleType(pVehicle->GetModel());
49404940
// Won't work with below.
4941-
if (vehicleType != VEHICLE_PLANE && vehicleType != VEHICLE_BOAT && vehicleType != VEHICLE_TRAILER && vehicleType != VEHICLE_HELI &&
4942-
vehicleType != VEHICLE_BIKE && vehicleType != VEHICLE_BMX)
4943-
{
4944-
if (ucSirenType >= 1 && ucSirenType <= 6)
4945-
{
4946-
if (ucSirenCount <= SIREN_COUNT_MAX)
4947-
{
4948-
pVehicle->m_tSirenBeaconInfo.m_bOverrideSirens = true;
4941+
if (vehicleType != VEHICLE_CAR && vehicleType != VEHICLE_MONSTERTRUCK && vehicleType != VEHICLE_QUADBIKE)
4942+
return false;
49494943

4950-
pVehicle->m_tSirenBeaconInfo.m_ucSirenCount = ucSirenCount;
4951-
pVehicle->m_tSirenBeaconInfo.m_ucSirenType = ucSirenType;
4944+
if (ucSirenType < 1 || ucSirenType > 6)
4945+
return false;
49524946

4953-
pVehicle->m_tSirenBeaconInfo.m_b360Flag = tSirenInfo.m_b360Flag;
4954-
pVehicle->m_tSirenBeaconInfo.m_bDoLOSCheck = tSirenInfo.m_bDoLOSCheck;
4955-
pVehicle->m_tSirenBeaconInfo.m_bUseRandomiser = tSirenInfo.m_bUseRandomiser;
4956-
pVehicle->m_tSirenBeaconInfo.m_bSirenSilent = tSirenInfo.m_bSirenSilent;
4947+
if (ucSirenCount > SIREN_COUNT_MAX)
4948+
return false;
49574949

4958-
SVehicleSirenAddSync tSirenSync;
4959-
tSirenSync.data.m_bOverrideSirens = pVehicle->m_tSirenBeaconInfo.m_bOverrideSirens;
4960-
tSirenSync.data.m_b360Flag = pVehicle->m_tSirenBeaconInfo.m_b360Flag;
4961-
tSirenSync.data.m_bDoLOSCheck = pVehicle->m_tSirenBeaconInfo.m_bDoLOSCheck;
4962-
tSirenSync.data.m_bEnableSilent = pVehicle->m_tSirenBeaconInfo.m_bSirenSilent;
4963-
tSirenSync.data.m_bUseRandomiser = pVehicle->m_tSirenBeaconInfo.m_bUseRandomiser;
4964-
tSirenSync.data.m_ucSirenCount = pVehicle->m_tSirenBeaconInfo.m_ucSirenCount;
4965-
tSirenSync.data.m_ucSirenType = pVehicle->m_tSirenBeaconInfo.m_ucSirenType;
4950+
pVehicle->m_tSirenBeaconInfo.m_bOverrideSirens = true;
49664951

4967-
CBitStream BitStream;
4968-
BitStream.pBitStream->Write(&tSirenSync);
4969-
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pVehicle, GIVE_VEHICLE_SIRENS, *BitStream.pBitStream));
4970-
return true;
4971-
}
4972-
}
4973-
}
4974-
return false;
4952+
pVehicle->m_tSirenBeaconInfo.m_ucSirenCount = ucSirenCount;
4953+
pVehicle->m_tSirenBeaconInfo.m_ucSirenType = ucSirenType;
4954+
4955+
pVehicle->m_tSirenBeaconInfo.m_b360Flag = tSirenInfo.m_b360Flag;
4956+
pVehicle->m_tSirenBeaconInfo.m_bDoLOSCheck = tSirenInfo.m_bDoLOSCheck;
4957+
pVehicle->m_tSirenBeaconInfo.m_bUseRandomiser = tSirenInfo.m_bUseRandomiser;
4958+
pVehicle->m_tSirenBeaconInfo.m_bSirenSilent = tSirenInfo.m_bSirenSilent;
4959+
4960+
SVehicleSirenAddSync tSirenSync;
4961+
tSirenSync.data.m_bOverrideSirens = pVehicle->m_tSirenBeaconInfo.m_bOverrideSirens;
4962+
tSirenSync.data.m_b360Flag = pVehicle->m_tSirenBeaconInfo.m_b360Flag;
4963+
tSirenSync.data.m_bDoLOSCheck = pVehicle->m_tSirenBeaconInfo.m_bDoLOSCheck;
4964+
tSirenSync.data.m_bEnableSilent = pVehicle->m_tSirenBeaconInfo.m_bSirenSilent;
4965+
tSirenSync.data.m_bUseRandomiser = pVehicle->m_tSirenBeaconInfo.m_bUseRandomiser;
4966+
tSirenSync.data.m_ucSirenCount = pVehicle->m_tSirenBeaconInfo.m_ucSirenCount;
4967+
tSirenSync.data.m_ucSirenType = pVehicle->m_tSirenBeaconInfo.m_ucSirenType;
4968+
4969+
CBitStream BitStream;
4970+
BitStream.pBitStream->Write(&tSirenSync);
4971+
m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pVehicle, GIVE_VEHICLE_SIRENS, *BitStream.pBitStream));
4972+
return true;
49754973
}
49764974

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

0 commit comments

Comments
 (0)