Redesigned Persist Car to check if the player is already in the car they want to spawn, and just forward self::veh as if it was the vehicle spawned. (#2418)

This commit is contained in:
gir489 2023-11-16 08:15:21 -05:00 committed by GitHub
parent e56a6fd38f
commit bc58716118
2 changed files with 9 additions and 5 deletions

View File

@ -191,13 +191,17 @@ namespace big
Vehicle persist_car_service::spawn_vehicle_json(nlohmann::json vehicle_json, Ped ped, const std::optional<Vector3>& spawn_coords)
{
const Hash vehicle_hash = vehicle_json[vehicle_model_hash_key];
Vector3 spawn_location = spawn_coords.has_value() ? spawn_coords.value() : vehicle::get_spawn_location(g.persist_car.spawn_inside, vehicle_hash);
const Vector3& spawn_location = spawn_coords.has_value() ? spawn_coords.value() : vehicle::get_spawn_location(g.persist_car.spawn_inside, vehicle_hash);
const float spawn_heading = ENTITY::GET_ENTITY_HEADING(self::ped);
const auto vehicle = big::vehicle::spawn(vehicle_hash, spawn_location, spawn_heading);
Vehicle vehicle = self::veh;
if (spawn_coords.has_value() || (!spawn_coords.has_value() && ENTITY::GET_ENTITY_MODEL(vehicle) != vehicle_hash))
{
vehicle = big::vehicle::spawn(vehicle_hash, spawn_location, spawn_heading);
if (spawn_location.x + spawn_location.y + spawn_location.z != 0)
script::get_current()->yield(); //This is needed to wait for the engine to instantiate things like the radio station so it won't overwrite it on the next frame.
if (spawn_location.x + spawn_location.y + spawn_location.z != 0)
script::get_current()->yield(); //This is needed to wait for the engine to instantiate things like the radio station so it won't overwrite it on the next frame.
}
VEHICLE::SET_VEHICLE_DIRT_LEVEL(vehicle, 0.0f);
VEHICLE::SET_VEHICLE_MOD_KIT(vehicle, 0);

View File

@ -28,7 +28,7 @@ namespace big
{
g_notification_service->push_warning("PERSIST_CAR"_T.data(), "PERSIST_CAR_TO_MANY_SPAWNED"_T.data());
}
else if (g.persist_car.spawn_inside)
else if (g.persist_car.spawn_inside && self::veh != vehicle)
{
teleport::into_vehicle(vehicle);
}