Added nearby entity deletion (#1476)

This commit is contained in:
DayibBaba 2023-06-21 10:01:00 +02:00 committed by GitHub
parent 5d3620a67c
commit 70c4b0c63b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 86 additions and 10 deletions

View File

@ -56,7 +56,8 @@ public:
std::vector<Entity> arr;
for (auto entity : *static_cast<T*>(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;

View File

@ -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<Entity> get_entities(bool vehicles, bool peds)
inline std::vector<Entity> get_entities(bool vehicles, bool peds, bool props = false, bool include_self_veh = false)
{
std::vector<Entity> 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;
}

View File

@ -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");

View File

@ -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<ImVec2(110, 0), ImVec4(0.02745f, 0.4745f, 0.10196f, 1.f)>("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<float>(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;
});
}
}
}