Skip to content

Commit

Permalink
Merge Reset \"can stand on top\" flag and map after disconnection in …
Browse files Browse the repository at this point in the history
…FiveM (pr-2393)

 - 16a085e tweak(extra-natives/five): use `getAndCheckVehicle` to avoid code duplication
 - 62a5960 fix(extra-natives/five): reset "can stand on vehicles" flag and map
  • Loading branch information
thorium-cfx committed Feb 21, 2024
2 parents 7b17b3e + 16a085e commit 179e4fd
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions code/components/extra-natives-five/src/VehicleExtraNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,35 +1375,37 @@ static HookFunction initFunction([]()

OnKillNetworkDone.Connect([]()
{
g_skipRepairVehicles.clear();
ResetFlyThroughWindscreenParams();

*g_trainsForceDoorsOpen = true;

g_skipRepairVehicles.clear();
g_canPedStandOnVehicles.clear();

g_overrideUseDefaultDriveByClipset = false;
g_overrideCanPedStandOnVehicle = false;
});

fx::ScriptEngine::RegisterNativeHandler("SET_VEHICLE_AUTO_REPAIR_DISABLED", [](fx::ScriptContext& context)
{
auto vehHandle = context.GetArgument<int>(0);
auto shouldDisable = context.GetArgument<bool>(1);

fwEntity* entity = rage::fwScriptGuid::GetBaseFromGuid(vehHandle);

if (shouldDisable)
{
g_skipRepairVehicles.insert(entity);
}
else
if (fwEntity* entity = getAndCheckVehicle(context, "SET_VEHICLE_AUTO_REPAIR_DISABLED"))
{
g_skipRepairVehicles.erase(entity);
auto shouldDisable = context.GetArgument<bool>(1);

if (shouldDisable)
{
g_skipRepairVehicles.insert(entity);
}
else
{
g_skipRepairVehicles.erase(entity);
}
}
});

fx::ScriptEngine::RegisterNativeHandler("ADD_VEHICLE_DELETION_TRACE", [](fx::ScriptContext& context)
{
auto vehHandle = context.GetArgument<int>(0);
fwEntity* entity = rage::fwScriptGuid::GetBaseFromGuid(vehHandle);

if (entity->IsOfType<CVehicle>())
if (fwEntity* entity = getAndCheckVehicle(context, "ADD_VEHICLE_DELETION_TRACE"))
{
g_deletionTraces.insert(entity);
g_deletionTraces2.insert(entity);
Expand All @@ -1412,10 +1414,7 @@ static HookFunction initFunction([]()

fx::ScriptEngine::RegisterNativeHandler("OVERRIDE_VEHICLE_PEDS_CAN_STAND_ON_TOP_FLAG", [](fx::ScriptContext& context)
{
auto vehHandle = context.GetArgument<int>(0);
fwEntity* entity = rage::fwScriptGuid::GetBaseFromGuid(vehHandle);

if (entity->IsOfType<CVehicle>())
if (fwEntity* entity = getAndCheckVehicle(context, "OVERRIDE_VEHICLE_PEDS_CAN_STAND_ON_TOP_FLAG"))
{
bool can = context.GetArgument<bool>(1);
SetCanPedStandOnVehicle(entity, can ? 1 : -1);
Expand All @@ -1424,10 +1423,7 @@ static HookFunction initFunction([]()

fx::ScriptEngine::RegisterNativeHandler("RESET_VEHICLE_PEDS_CAN_STAND_ON_TOP_FLAG", [](fx::ScriptContext& context)
{
auto vehHandle = context.GetArgument<int>(0);
fwEntity* entity = rage::fwScriptGuid::GetBaseFromGuid(vehHandle);

if (entity->IsOfType<CVehicle>())
if (fwEntity* entity = getAndCheckVehicle(context, "RESET_VEHICLE_PEDS_CAN_STAND_ON_TOP_FLAG"))
{
SetCanPedStandOnVehicle(entity, 0);
}
Expand Down

0 comments on commit 179e4fd

Please sign in to comment.