diff --git a/src/gta/pools.hpp b/src/gta/pools.hpp index 908bb977..16f117e9 100644 --- a/src/gta/pools.hpp +++ b/src/gta/pools.hpp @@ -56,7 +56,8 @@ public: std::vector arr; for (auto entity : *static_cast(this)) { - arr.push_back(big::g_pointers->m_gta.m_ptr_to_handle(entity)); + if(entity) + arr.push_back(big::g_pointers->m_gta.m_ptr_to_handle(entity)); } return arr; diff --git a/src/util/entity.hpp b/src/util/entity.hpp index 15ad4d30..a2ac00e7 100644 --- a/src/util/entity.hpp +++ b/src/util/entity.hpp @@ -30,6 +30,9 @@ namespace big::entity inline void delete_entity(Entity ent) { + if (!ENTITY::DOES_ENTITY_EXIST(ent)) + return; + ENTITY::DETACH_ENTITY(ent, 1, 1); ENTITY::SET_ENTITY_VISIBLE(ent, false, false); NETWORK::NETWORK_SET_ENTITY_ONLY_EXISTS_FOR_PARTICIPANTS(ent, true); @@ -99,16 +102,15 @@ namespace big::entity return false; } - inline std::vector get_entities(bool vehicles, bool peds) + inline std::vector get_entities(bool vehicles, bool peds, bool props = false, bool include_self_veh = false) { std::vector target_entities; - target_entities.clear(); if (vehicles) { for (auto vehicle : pools::get_all_vehicles()) { - if (vehicle == gta_util::get_local_vehicle()) + if (!include_self_veh && vehicle == gta_util::get_local_vehicle()) continue; target_entities.push_back(g_pointers->m_gta.m_ptr_to_handle(vehicle)); @@ -119,13 +121,17 @@ namespace big::entity { for (auto ped : pools::get_all_peds()) { - // make sure to not include ourselves - if (ped == gta_util::get_local_ped()) - continue; - target_entities.push_back(g_pointers->m_gta.m_ptr_to_handle(ped)); } } + + if (props) + { + for (auto prop : pools::get_all_props()) + { + target_entities.push_back(g_pointers->m_gta.m_ptr_to_handle(prop)); + } + } return target_entities; } diff --git a/src/util/notify.hpp b/src/util/notify.hpp index a412c041..828ed70b 100644 --- a/src/util/notify.hpp +++ b/src/util/notify.hpp @@ -54,6 +54,13 @@ namespace big::notify HUD::BUSYSPINNER_OFF(); } + inline void show_subtitle(std::string_view text, int ms = 2000) + { + HUD::BEGIN_TEXT_COMMAND_PRINT("STRING"); + HUD::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(text.data()); + HUD::END_TEXT_COMMAND_PRINT(ms, 1); + } + inline void display_help_text(std::string_view text) { HUD::BEGIN_TEXT_COMMAND_DISPLAY_HELP("STRING"); diff --git a/src/views/world/view_nearby.cpp b/src/views/world/view_nearby.cpp index 4c920356..1f2af2a7 100644 --- a/src/views/world/view_nearby.cpp +++ b/src/views/world/view_nearby.cpp @@ -1,5 +1,6 @@ #include "util/entity.hpp" #include "util/local_player.hpp" +#include "util/notify.hpp" #include "util/ped.hpp" #include "util/vehicle.hpp" #include "views/view.hpp" @@ -43,13 +44,12 @@ namespace big ImGui::SameLine(140.f); components::command_checkbox<"pedrush">(); components::command_checkbox<"autodisarm">(); - components::options_modal("Auto Disarm", []{ + components::options_modal("Auto Disarm", [] { ImGui::Checkbox("Neutralize", &g.world.nearby.auto_disarm.neutralize); }); ImGui::Separator(); components::sub_title("Vehicles"); - // Nearby Vehicle Actions components::button("Max Upgrade", [] { for (auto vehs : entity::get_entities(true, false)) @@ -75,5 +75,67 @@ namespace big }); components::command_checkbox<"vehiclerain">(); + + ImGui::Separator(); + components::sub_title("All"); + + static bool included_entity_types[3]; + static bool own_vehicle, deleting; + static int quantity, remaining; + + ImGui::Text("Include:"); + ImGui::Checkbox("Vehicles", &included_entity_types[0]); + ImGui::SameLine(); + ImGui::Checkbox("Peds", &included_entity_types[1]); + ImGui::SameLine(); + ImGui::Checkbox("Props", &included_entity_types[2]); + + if (included_entity_types[0]) + ImGui::Checkbox("Self vehicle", &own_vehicle); + + if (deleting) + { + float progress = 1 - static_cast(remaining) / quantity; + ImGui::ProgressBar(progress, ImVec2(200, 25)); + } + else + { + components::button("Delete all", [&] { + auto list = entity::get_entities(included_entity_types[0], included_entity_types[1], included_entity_types[2], own_vehicle); + + quantity = list.size(); + remaining = quantity; + g_notification_service->push("Entity deletion", std::format("Deleting {} entities", quantity)); + deleting = true; + int failed = 0; + for (auto ent : list) + { + if (ent == self::ped) + continue; + + if (ENTITY::DOES_ENTITY_EXIST(ent)) + { + if (ENTITY::IS_ENTITY_A_VEHICLE(ent)) + if (ent == self::veh && own_vehicle) + TASK::CLEAR_PED_TASKS_IMMEDIATELY(self::ped); + + if (entity::take_control_of(ent, 25)) + entity::delete_entity(ent); + } + + script::get_current()->yield(5ms); + + if (ENTITY::DOES_ENTITY_EXIST(ent)) + failed++; + else + remaining--; + } + + if (failed > 0) + g_notification_service->push_warning("Entity deletion", std::format("Failed deleting {} entities", failed)); + + deleting = false; + }); + } } }