diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index fabdf76f16..b1ee40ea94 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -105,7 +105,9 @@ void CLuaVehicleDefs::LoadFunctions() {"setVehicleDoorsUndamageable", SetVehicleDoorsUndamageable}, {"setVehicleSirensOn", SetVehicleSirensOn}, {"addVehicleUpgrade", AddVehicleUpgrade}, + {"addVehicleSirens", ArgumentParser}, {"removeVehicleUpgrade", RemoveVehicleUpgrade}, + {"removeVehicleSirens", ArgumentParser}, {"setVehicleDoorState", SetVehicleDoorState}, {"setVehicleWheelStates", SetVehicleWheelStates}, {"setVehicleLightState", SetVehicleLightState}, @@ -4345,6 +4347,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 enable360, std::optional enableLOSCheck, std::optional enableRandomiser, std::optional 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(); @@ -4359,4 +4385,3 @@ bool CLuaVehicleDefs::IsSmokeTrailEnabled(CClientVehicle* vehicle) noexcept { return vehicle->IsSmokeTrailEnabled(); } - diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h index 5e4695e850..7cc5177f04 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h @@ -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 enable360, std::optional enableLOSCheck, std::optional enableRandomiser, std::optional enableSilent) noexcept; + static bool RemoveVehicleSirens(CClientVehicle* vehicle) noexcept; + // Components LUA_DECLARE(SetVehicleComponentPosition); LUA_DECLARE_OOP(GetVehicleComponentPosition); diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 24c9ff6edc..17f97a2522 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -4936,40 +4936,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)