Skip to content
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

Adding function addVehicleSirens & removeVehicleSirens client-side #3704

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -105,7 +105,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 @@ -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<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 @@ -4359,4 +4385,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 @@ -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;
Proxy-99 marked this conversation as resolved.
Show resolved Hide resolved

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
Loading