Improved auto drive (#196)

* Improved logic to handle changes mid drive. Changed default styles. Split to waypoint and wander into two separate files for readability

* Fixed type to remove the hideous warnings

* Fixes

* wfvaenhiuefcsnhiojmfhnevioshnuefvsihnoijmefmvschnfvecshnfevSC

* iNcLuDeS aLpHaBeTiCaLlY
This commit is contained in:
Maddy 2022-05-24 15:59:25 -04:00 committed by GitHub
parent 5dd5470959
commit a9dbfdd138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 193 additions and 138 deletions

View File

@ -16,9 +16,9 @@ namespace big
if (g_local_player != nullptr && !api::util::signed_in())
{
g_thread_pool->push([]
{
looped::api_login_session();
});
{
looped::api_login_session();
});
}
}
}

View File

@ -56,7 +56,8 @@ namespace big
LOG(INFO) << "Starting script: Vehicles";
while (g_running) {
looped::vehicle_auto_drive();
looped::vehicle_auto_drive_to_waypoint();
looped::vehicle_auto_drive_wander();
looped::vehicle_despawn_bypass();
looped::vehicle_drive_on_water();
looped::vehicle_god_mode();
@ -66,7 +67,7 @@ namespace big
looped::vehicle_rainbow_paint();
looped::vehicle_seatbelt();
looped::vehicle_speedo_meter();
script::get_current()->yield();
}
@ -105,7 +106,7 @@ namespace big
LOG(INFO) << "Starting script: Miscellaneous";
while (g_running) {
looped::hud_transition_state();
looped::tunables_disable_phone();
looped::tunables_no_idle_kick();
@ -170,4 +171,4 @@ namespace big
}
};
}
}

View File

@ -36,7 +36,8 @@ namespace big
static void system_self_globals();
static void system_update_pointers();
static void vehicle_auto_drive();
static void vehicle_auto_drive_to_waypoint();
static void vehicle_auto_drive_wander();
static void vehicle_despawn_bypass();
static void vehicle_drive_on_water();
static void vehicle_fly();

View File

@ -1,115 +0,0 @@
#include "backend/looped/looped.hpp"
#include "natives.hpp"
#include "util/blip.hpp"
#include "util/entity.hpp"
#include "gta/enums.hpp"
namespace big
{
void looped::vehicle_auto_drive()
{
Vehicle vehicle = self::veh;
Ped ped = self::ped;
static Vector3 location;
static bool running = true;
static bool wandering = true;
static bool ran_once = false;
if (g->vehicle.auto_drive_to_waypoint)
{
running = false;
ran_once = true;
if (!blip::get_blip_location(location, (int)BlipIcons::Waypoint))
{
g_notification_service->push_warning("Warning", "No Waypoint found please set one first.");
g->vehicle.auto_drive_to_waypoint = false;
}
else if (!vehicle)
{
g_notification_service->push_warning("Warning", "Please be in a car first then try again.");
}
else
{
blip::get_blip_location(location, (int)BlipIcons::Waypoint);
g_notification_service->push_warning("Auto Drive", "Starting Route To Destination");
g_notification_service->push_warning("Auto Drive", "Start driving or leave car to take back control.");
TASK::CLEAR_VEHICLE_TASKS_(vehicle);
TASK::TASK_VEHICLE_DRIVE_TO_COORD(ped, vehicle, location.x, location.y, location.z,
static_cast<float>(g->vehicle.auto_drive_speed), 5, ENTITY::GET_ENTITY_MODEL(vehicle), g->vehicle.driving_style_flags, 20, true);
g->vehicle.auto_drive_to_waypoint = false;
running = true;
}
}
if (g->vehicle.auto_drive_wander)
{
ran_once = true;
wandering = false;
if (!vehicle)
{
g_notification_service->push_warning("Warning", "Please be in a car first then try again.");
g->vehicle.auto_drive_wander = false;
TASK::CLEAR_VEHICLE_TASKS_(vehicle);
}
else
{
g->vehicle.auto_drive_wander = false;
TASK::CLEAR_VEHICLE_TASKS_(vehicle);
TASK::CLEAR_PED_TASKS(ped);
TASK::TASK_VEHICLE_DRIVE_WANDER(ped, vehicle, static_cast<float>(g->vehicle.auto_drive_speed), g->vehicle.driving_style_flags);
wandering = true;
g_notification_service->push_warning("Starting Wondering", "Start driving or leave car to take back control.");
}
}
if (wandering && ran_once)
{
if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_ACCELERATE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_BRAKE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_EXIT) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HANDBRAKE))
{
TASK::CLEAR_VEHICLE_TASKS_(vehicle);
TASK::CLEAR_PED_TASKS(ped);
g_notification_service->push_warning("Warning", "Wandering Stopped");
g->vehicle.auto_drive_wander = false;
wandering = false;
}
}
if (running)
{
if (!blip::get_blip_location(location, (int)BlipIcons::Waypoint) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_ACCELERATE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_BRAKE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_EXIT) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HANDBRAKE))
{
if (!blip::get_blip_location(location, (int)BlipIcons::Waypoint))
{
VEHICLE::SET_VEHICLE_FORWARD_SPEED(vehicle, 8);
}
g->vehicle.auto_drive_to_waypoint = false;
if (ran_once)
{
g_notification_service->push_warning("Warning", "Autodrive Stopped");
}
TASK::CLEAR_VEHICLE_TASKS_(vehicle);
TASK::CLEAR_PED_TASKS(ped);
running = false;
}
}
}
}

View File

@ -0,0 +1,95 @@
#include "backend/looped/looped.hpp"
#include "gta/enums.hpp"
#include "natives.hpp"
#include "util/blip.hpp"
#include "util/entity.hpp"
#include "util/vehicle.hpp"
namespace big
{
void looped::vehicle_auto_drive_to_waypoint()
{
static Vector3 location;
static bool driving_to_wp = true;
static bool ran_once = false;
static int changing_driving_styles = false;
static int current_driving_style = false;
static int current_speed;
if (g->vehicle.auto_drive_to_waypoint)
{
ran_once = true;
driving_to_wp = false;
if (!blip::get_blip_location(location, (int)BlipIcons::Waypoint))
{
g_notification_service->push_warning("Warning", "No Waypoint found please set one first.");
g->vehicle.auto_drive_to_waypoint = false;
}
else if (!self::veh)
{
g_notification_service->push_warning("Warning", "Please be in a car first then try again.");
g->vehicle.auto_drive_to_waypoint = false;
}
else
{
blip::get_blip_location(location, (int)BlipIcons::Waypoint);
if (!changing_driving_styles)
{
g_notification_service->push_warning("Auto Drive", "Starting Route To Destination");
g_notification_service->push_warning("Auto Drive", "Start driving or leave car to take back control.");
}
TASK::CLEAR_VEHICLE_TASKS_(self::veh);
TASK::CLEAR_PED_TASKS(self::ped);
TASK::TASK_VEHICLE_DRIVE_TO_COORD(self::ped, self::veh, location.x, location.y, location.z, static_cast<float>(g->vehicle.auto_drive_speed), 5, ENTITY::GET_ENTITY_MODEL(self::veh), g->vehicle.driving_style_flags, 20, true);
current_driving_style = g->vehicle.driving_style_flags;
current_speed = g->vehicle.auto_drive_speed;
g->vehicle.auto_drive_to_waypoint = false;
driving_to_wp = true;
}
}
if (driving_to_wp)
{
if (!blip::get_blip_location(location, (int)BlipIcons::Waypoint) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_ACCELERATE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_BRAKE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_EXIT) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HANDBRAKE))
{
if (!blip::get_blip_location(location, (int)BlipIcons::Waypoint))
{
VEHICLE::SET_VEHICLE_FORWARD_SPEED(self::veh, 8);
}
g->vehicle.auto_drive_to_waypoint = false;
if (ran_once)
{
g_notification_service->push_warning("Warning", "Autodrive Stopped");
}
TASK::CLEAR_VEHICLE_TASKS_(self::veh);
TASK::CLEAR_PED_TASKS(self::ped);
driving_to_wp = false;
}
if (!ran_once)
{
TASK::CLEAR_VEHICLE_TASKS_(self::veh);
TASK::CLEAR_PED_TASKS(self::ped);
driving_to_wp = false;
}
else
{
if ((current_driving_style != g->vehicle.driving_style_flags) || (current_speed != g->vehicle.auto_drive_speed))
{
changing_driving_styles = true;
g->vehicle.auto_drive_to_waypoint = true;
}
}
}
}
}

View File

@ -0,0 +1,70 @@
#include "backend/looped/looped.hpp"
#include "gta/enums.hpp"
#include "natives.hpp"
#include "util/blip.hpp"
#include "util/entity.hpp"
#include "util/vehicle.hpp"
namespace big
{
void looped::vehicle_auto_drive_wander()
{
static Vector3 location;
static bool wandering = true;
static bool ran_once = false;
static int changing_driving_styles = false;
static int current_driving_style = false;
static int current_speed;
if (g->vehicle.auto_drive_wander)
{
ran_once = true;
wandering = false;
if (!self::veh)
{
g_notification_service->push_warning("Warning", "Please be in a car first then try again.");
g->vehicle.auto_drive_wander = false;
TASK::CLEAR_VEHICLE_TASKS_(self::veh);
}
else
{
g->vehicle.auto_drive_wander = false;
TASK::CLEAR_VEHICLE_TASKS_(self::veh);
TASK::CLEAR_PED_TASKS(self::ped);
TASK::TASK_VEHICLE_DRIVE_WANDER(self::ped, self::veh, static_cast<float>(g->vehicle.auto_drive_speed), g->vehicle.driving_style_flags);
current_driving_style = g->vehicle.driving_style_flags;
current_speed = g->vehicle.auto_drive_speed;
wandering = true;
if (!changing_driving_styles)
{
g_notification_service->push_warning("Starting Wondering", "Start driving or leave car to take back control.");
}
}
}
if (wandering && ran_once)
{
if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_LEFT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_MOVE_RIGHT_ONLY) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_ACCELERATE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_BRAKE) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_EXIT) || PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_VEH_HANDBRAKE))
{
TASK::CLEAR_VEHICLE_TASKS_(self::veh);
TASK::CLEAR_PED_TASKS(self::ped);
g_notification_service->push_warning("Warning", "Wandering Stopped");
g->vehicle.auto_drive_wander = false;
wandering = false;
}
if ((current_driving_style != g->vehicle.driving_style_flags) || (current_speed != g->vehicle.auto_drive_speed))
{
changing_driving_styles = true;
g->vehicle.auto_drive_wander = true;
}
}
}
}

View File

@ -218,7 +218,7 @@ namespace big
bool seatbelt = false;
bool turn_signals = false;
int auto_drive_speed = 1;
int driving_style_flags = 525116;
int driving_style_flags = 443;
int driving_style_id = 0;
int rainbow_paint = 0;
speedo_meter speedo_meter{};

View File

@ -114,6 +114,6 @@ namespace big::vehicle
static constexpr char const* rgb_types[] = { "Off", "Fade", "Spasm" };
static constexpr int driving_styles[] = { 444, 525116, 787260 };
static constexpr char const* driving_style_names[] = { "Safe-ish", "Normal", "Hit Everything" };
}
static constexpr int driving_styles[] = { 443, 524861 };
static constexpr char const* driving_style_names[] = { "Law-Abiding", "The Road Is Yours" };
}

View File

@ -24,13 +24,13 @@ namespace big
components::button("Repair", [] {
vehicle::repair(self::veh);
});
});
components::button("Instant in personal vehicle", [] {
if (!*g_pointers->m_is_session_started) return g_notification_service->push_warning("WARNING", "Go into GTA V Online to use this option");
vehicle::go_into_personal_vehicle();
});
});
if (ImGui::TreeNode("Paint"))
{
@ -58,24 +58,27 @@ namespace big
components::small_text("Auto Drive");
components::button("Drive To Waypoint", [] {
g->vehicle.auto_drive_to_waypoint = true;
});
});
components::button("Wander", [] {
g->vehicle.auto_drive_wander = true;
});
});
ImGui::SliderInt("Top Speed", &g->vehicle.auto_drive_speed, 1, 200);
components::button("E-Stop", [] {
g->vehicle.auto_drive_to_waypoint = false;
g->vehicle.auto_drive_wander = false;
VEHICLE::SET_VEHICLE_FORWARD_SPEED(self::veh, 0);
TASK::CLEAR_VEHICLE_TASKS_(self::veh);
TASK::CLEAR_PED_TASKS(self::ped);
});
if (ImGui::ListBox("Driving Style", &g->vehicle.driving_style_id, vehicle::driving_style_names, 3))
g->vehicle.auto_drive_to_waypoint = false;
g->vehicle.auto_drive_wander = false;
VEHICLE::SET_VEHICLE_FORWARD_SPEED(self::veh, 0);
TASK::CLEAR_VEHICLE_TASKS_(self::veh);
TASK::CLEAR_PED_TASKS(self::ped);
});
if (ImGui::ListBox("Driving Style", &g->vehicle.driving_style_id, vehicle::driving_style_names, 2))
{
g->vehicle.driving_style_flags = vehicle::driving_styles[g->vehicle.driving_style_id];
g_notification_service->push_warning("Auto Drive", fmt::format("Driving style set to {}.", vehicle::driving_style_names[g->vehicle.driving_style_id]));