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 setVehicleNitroActivated server-side #3706

Merged
merged 12 commits into from
Dec 30, 2024
24 changes: 24 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CVehicleRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void CVehicleRPCs::LoadFunctions()
AddHandler(REMOVE_VEHICLE_SIRENS, RemoveVehicleSirens, "removeVehicleSirens");
AddHandler(SET_VEHICLE_SIRENS, SetVehicleSirens, "setVehicleSirens");
AddHandler(SET_VEHICLE_PLATE_TEXT, SetVehiclePlateText, "setVehiclePlateText");
AddHandler(SET_VEHICLE_NITRO_ACTIVATED, SetVehicleNitroActivated, "SetVehicleNitroActivated");
}

void CVehicleRPCs::DestroyAllVehicles(NetBitStreamInterface& bitStream)
Expand Down Expand Up @@ -653,3 +654,26 @@ void CVehicleRPCs::SetVehiclePlateText(CClientEntity* pSourceEntity, NetBitStrea
}
}
}


void CVehicleRPCs::SetVehicleNitroActivated(CClientEntity* pSourceEntity, NetBitStreamInterface& bitStream)
{
bool state = bitStream.ReadBit();

CClientVehicle* vehicle = m_pVehicleManager->Get(pSourceEntity->GetID());
if (!vehicle)
return;

if (!vehicle->IsNitroInstalled())
return;

// If nitro level < 0, nitro is activated. (until nitro level reaches -1, at that point it will become 0 and increase instead of decrease)
if ((vehicle->GetNitroLevel() < 0.0f) == state)
return;

// Apply nitro level change
if (state)
vehicle->SetNitroLevel(vehicle->GetNitroLevel() - 1.0001f);
else
vehicle->SetNitroLevel(vehicle->GetNitroLevel() + 1.0001f);
}
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/rpc/CVehicleRPCs.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ class CVehicleRPCs : public CRPCFunctions
DECLARE_ELEMENT_RPC(RemoveVehicleSirens);
DECLARE_ELEMENT_RPC(SetVehicleSirens);
DECLARE_ELEMENT_RPC(SetVehiclePlateText);
DECLARE_ELEMENT_RPC(SetVehicleNitroActivated);
};
10 changes: 10 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void CLuaVehicleDefs::LoadFunctions()
{"getVehicleSirens", GetVehicleSirens},
{"getVehicleSirenParams", GetVehicleSirenParams},
{"setVehiclePlateText", SetVehiclePlateText},
{"setVehicleNitroActivated", ArgumentParser<SetVehicleNitroActivated>},
};

// Add functions
Expand Down Expand Up @@ -2982,3 +2983,12 @@ int CLuaVehicleDefs::SetVehiclePlateText(lua_State* luaVM)
lua_pushboolean(luaVM, false);
return 1;
}

bool CLuaVehicleDefs::SetVehicleNitroActivated(CVehicle* vehicle, bool state) noexcept
{
CBitStream BitStream;
BitStream.pBitStream->WriteBit(state);

m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(vehicle, SET_VEHICLE_NITRO_ACTIVATED, *BitStream.pBitStream));
return true;
}
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 @@ -125,4 +125,6 @@ class CLuaVehicleDefs : public CLuaDefs
LUA_DECLARE(GetVehicleSirens);
LUA_DECLARE(GetVehicleSirenParams);
LUA_DECLARE(SetVehiclePlateText);

static bool SetVehicleNitroActivated(CVehicle* vehicle, bool state) noexcept;
};
4 changes: 3 additions & 1 deletion Shared/sdk/net/rpc_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@ enum eElementRPCFunctions

RESPAWN_OBJECT,
TOGGLE_OBJECT_RESPAWN,

RESET_WORLD_PROPERTIES,

SET_VEHICLE_NITRO_ACTIVATED,

NUM_RPC_FUNCS // Add above this line
};
Loading