2021-05-19 14:35:05 +02:00
|
|
|
#pragma once
|
2021-05-19 15:31:02 +02:00
|
|
|
#include "gta/joaat.hpp"
|
2022-07-12 22:42:07 +08:00
|
|
|
#include "gta/replay.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "gta_util.hpp"
|
|
|
|
#include "math.hpp"
|
2021-05-19 14:35:05 +02:00
|
|
|
#include "natives.hpp"
|
|
|
|
#include "script.hpp"
|
|
|
|
|
|
|
|
namespace big::entity
|
|
|
|
{
|
2021-05-19 15:31:02 +02:00
|
|
|
inline void cage_ped(Ped ped)
|
|
|
|
{
|
|
|
|
Hash hash = RAGE_JOAAT("prop_gold_cont_01");
|
|
|
|
|
|
|
|
Vector3 location = ENTITY::GET_ENTITY_COORDS(ped, true);
|
|
|
|
OBJECT::CREATE_OBJECT(hash, location.x, location.y, location.z - 1.f, true, false, false);
|
|
|
|
}
|
|
|
|
|
2022-03-02 08:48:53 -05:00
|
|
|
inline void clean_ped(Ped ped)
|
|
|
|
{
|
2022-05-23 06:38:45 +08:00
|
|
|
Ped player_ped = self::ped;
|
|
|
|
|
|
|
|
PED::CLEAR_PED_BLOOD_DAMAGE(player_ped);
|
|
|
|
PED::CLEAR_PED_WETNESS(player_ped);
|
|
|
|
PED::CLEAR_PED_ENV_DIRT(player_ped);
|
|
|
|
PED::RESET_PED_VISIBLE_DAMAGE(player_ped);
|
2022-03-02 08:48:53 -05:00
|
|
|
}
|
|
|
|
|
2021-05-20 18:57:53 +02:00
|
|
|
inline void delete_entity(Entity ent)
|
|
|
|
{
|
|
|
|
ENTITY::DETACH_ENTITY(ent, 1, 1);
|
|
|
|
ENTITY::SET_ENTITY_VISIBLE(ent, false, false);
|
2022-09-20 14:03:19 +01:00
|
|
|
NETWORK::NETWORK_SET_ENTITY_ONLY_EXISTS_FOR_PARTICIPANTS(ent, true);
|
2021-05-20 18:57:53 +02:00
|
|
|
ENTITY::SET_ENTITY_COORDS_NO_OFFSET(ent, 0, 0, 0, 0, 0, 0);
|
|
|
|
ENTITY::SET_ENTITY_AS_MISSION_ENTITY(ent, 1, 1);
|
|
|
|
ENTITY::DELETE_ENTITY(&ent);
|
|
|
|
}
|
|
|
|
|
2021-05-19 15:31:02 +02:00
|
|
|
inline bool raycast(Entity* ent)
|
|
|
|
{
|
|
|
|
BOOL hit;
|
|
|
|
Vector3 endCoords;
|
|
|
|
Vector3 surfaceNormal;
|
|
|
|
|
|
|
|
Vector3 camCoords = CAM::GET_GAMEPLAY_CAM_COORD();
|
2023-03-01 21:27:15 +00:00
|
|
|
Vector3 rot = CAM::GET_GAMEPLAY_CAM_ROT(2);
|
|
|
|
Vector3 dir = math::rotation_to_direction(rot);
|
2021-05-19 15:31:02 +02:00
|
|
|
Vector3 farCoords;
|
|
|
|
|
|
|
|
farCoords.x = camCoords.x + dir.x * 1000;
|
|
|
|
farCoords.y = camCoords.y + dir.y * 1000;
|
|
|
|
farCoords.z = camCoords.z + dir.z * 1000;
|
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
int ray = SHAPETEST::START_EXPENSIVE_SYNCHRONOUS_SHAPE_TEST_LOS_PROBE(camCoords.x,
|
|
|
|
camCoords.y,
|
|
|
|
camCoords.z,
|
|
|
|
farCoords.x,
|
|
|
|
farCoords.y,
|
|
|
|
farCoords.z,
|
|
|
|
-1,
|
|
|
|
0,
|
|
|
|
7);
|
2021-05-19 15:31:02 +02:00
|
|
|
SHAPETEST::GET_SHAPE_TEST_RESULT(ray, &hit, &endCoords, &surfaceNormal, ent);
|
|
|
|
|
|
|
|
return (bool)hit;
|
|
|
|
}
|
|
|
|
|
2023-02-09 05:46:08 +08:00
|
|
|
inline bool network_has_control_of_entity(rage::netObject* net_object)
|
2021-05-19 14:35:05 +02:00
|
|
|
{
|
2023-02-11 05:33:47 +08:00
|
|
|
return !net_object || !net_object->m_next_owner_id && (net_object->m_control_id == -1);
|
2023-02-09 05:46:08 +08:00
|
|
|
}
|
2022-11-21 15:42:12 +00:00
|
|
|
|
2023-02-09 05:46:08 +08:00
|
|
|
inline bool take_control_of(Entity ent, int timeout = 300)
|
|
|
|
{
|
2023-04-14 18:54:07 +02:00
|
|
|
auto hnd = g_pointers->m_gta.m_handle_to_ptr(ent);
|
2023-04-12 20:10:56 +02:00
|
|
|
|
2023-04-14 18:54:07 +02:00
|
|
|
if (!hnd || !hnd->m_net_object || !*g_pointers->m_gta.m_is_session_started)
|
2023-03-10 22:41:46 +00:00
|
|
|
return false;
|
2023-04-12 20:10:56 +02:00
|
|
|
|
|
|
|
if (network_has_control_of_entity(hnd->m_net_object))
|
|
|
|
return true;
|
2023-03-10 22:41:46 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < timeout; i++)
|
|
|
|
{
|
2023-04-14 18:54:07 +02:00
|
|
|
g_pointers->m_gta.m_request_control(hnd->m_net_object);
|
2023-03-10 22:41:46 +00:00
|
|
|
|
2023-04-12 20:10:56 +02:00
|
|
|
if (network_has_control_of_entity(hnd->m_net_object))
|
|
|
|
return true;
|
2023-03-10 22:41:46 +00:00
|
|
|
|
|
|
|
if (timeout != 0)
|
|
|
|
script::get_current()->yield();
|
2023-03-01 21:27:15 +00:00
|
|
|
}
|
2023-03-10 22:41:46 +00:00
|
|
|
|
2023-04-12 20:10:56 +02:00
|
|
|
return false;
|
2021-05-19 14:35:05 +02:00
|
|
|
}
|
Feature Additions, GUI Tweaks, Fixes (#975)
* Added view nearby to view header, moved get_entities function to entities and refactored some code. Also implemented a sphere scale to the blackhole as it can get big
* added delete and kill nearby peds and updated ped header
* added some nearby ped looped commands, and some changes to extend the buttons
* add vehicle options to nearby
* add most ciritcal feature kill enemies
* changes to ignore peds based off of some of maybegreat's suggestions, same with ped_rain, removed loose comment. Updated vehicle.hpp, changed size of vehicle buttons and inlined kill enemies
* fixed a problem where the vehicle options crashed + added color
* updated colors and added on disable for ped_rush
* finished and added vehicle rain feature
* added aimbot and triggerbot, added templating to buttons
* update vehicle rain desc
* added vdistance check, player check, police check, enemy check. Added even more commenting... sue me. 3 toggles added for the checks and slider for dist. Will tweak more later
* switched to goto statements instead of continue, should be done now
* removed delete nearby vehicles
* there was no check in get_entities for our local vehicle
2023-02-25 13:33:16 -07:00
|
|
|
|
|
|
|
inline std::vector<Entity> get_entities(bool vehicles, bool peds)
|
|
|
|
{
|
|
|
|
std::vector<Entity> target_entities;
|
|
|
|
target_entities.clear();
|
2023-04-14 18:54:07 +02:00
|
|
|
const auto replay_interface = *g_pointers->m_gta.m_replay_interface;
|
Feature Additions, GUI Tweaks, Fixes (#975)
* Added view nearby to view header, moved get_entities function to entities and refactored some code. Also implemented a sphere scale to the blackhole as it can get big
* added delete and kill nearby peds and updated ped header
* added some nearby ped looped commands, and some changes to extend the buttons
* add vehicle options to nearby
* add most ciritcal feature kill enemies
* changes to ignore peds based off of some of maybegreat's suggestions, same with ped_rain, removed loose comment. Updated vehicle.hpp, changed size of vehicle buttons and inlined kill enemies
* fixed a problem where the vehicle options crashed + added color
* updated colors and added on disable for ped_rush
* finished and added vehicle rain feature
* added aimbot and triggerbot, added templating to buttons
* update vehicle rain desc
* added vdistance check, player check, police check, enemy check. Added even more commenting... sue me. 3 toggles added for the checks and slider for dist. Will tweak more later
* switched to goto statements instead of continue, should be done now
* removed delete nearby vehicles
* there was no check in get_entities for our local vehicle
2023-02-25 13:33:16 -07:00
|
|
|
if (!replay_interface)
|
|
|
|
return target_entities;
|
|
|
|
|
|
|
|
if (vehicles)
|
|
|
|
{
|
|
|
|
const auto vehicle_interface = replay_interface->m_vehicle_interface;
|
|
|
|
for (int i = 0; i < vehicle_interface->m_max_vehicles; i++)
|
|
|
|
{
|
|
|
|
const auto vehicle_ptr = vehicle_interface->get_vehicle(i);
|
|
|
|
if (!vehicle_ptr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (vehicle_ptr == gta_util::get_local_vehicle())
|
|
|
|
continue;
|
|
|
|
|
2023-04-14 18:54:07 +02:00
|
|
|
const auto veh = g_pointers->m_gta.m_ptr_to_handle(vehicle_ptr);
|
Feature Additions, GUI Tweaks, Fixes (#975)
* Added view nearby to view header, moved get_entities function to entities and refactored some code. Also implemented a sphere scale to the blackhole as it can get big
* added delete and kill nearby peds and updated ped header
* added some nearby ped looped commands, and some changes to extend the buttons
* add vehicle options to nearby
* add most ciritcal feature kill enemies
* changes to ignore peds based off of some of maybegreat's suggestions, same with ped_rain, removed loose comment. Updated vehicle.hpp, changed size of vehicle buttons and inlined kill enemies
* fixed a problem where the vehicle options crashed + added color
* updated colors and added on disable for ped_rush
* finished and added vehicle rain feature
* added aimbot and triggerbot, added templating to buttons
* update vehicle rain desc
* added vdistance check, player check, police check, enemy check. Added even more commenting... sue me. 3 toggles added for the checks and slider for dist. Will tweak more later
* switched to goto statements instead of continue, should be done now
* removed delete nearby vehicles
* there was no check in get_entities for our local vehicle
2023-02-25 13:33:16 -07:00
|
|
|
if (!veh)
|
|
|
|
break;
|
|
|
|
|
|
|
|
target_entities.push_back(veh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (peds)
|
|
|
|
{
|
|
|
|
const auto ped_interface = replay_interface->m_ped_interface;
|
|
|
|
for (int i = 0; i < ped_interface->m_max_peds; i++)
|
|
|
|
{
|
|
|
|
const auto ped_ptr = ped_interface->get_ped(i);
|
|
|
|
if (!ped_ptr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//make sure to don't include ourselves
|
|
|
|
if (ped_ptr == gta_util::get_local_ped())
|
|
|
|
continue;
|
|
|
|
|
2023-04-14 18:54:07 +02:00
|
|
|
const auto ped = g_pointers->m_gta.m_ptr_to_handle(ped_ptr);
|
Feature Additions, GUI Tweaks, Fixes (#975)
* Added view nearby to view header, moved get_entities function to entities and refactored some code. Also implemented a sphere scale to the blackhole as it can get big
* added delete and kill nearby peds and updated ped header
* added some nearby ped looped commands, and some changes to extend the buttons
* add vehicle options to nearby
* add most ciritcal feature kill enemies
* changes to ignore peds based off of some of maybegreat's suggestions, same with ped_rain, removed loose comment. Updated vehicle.hpp, changed size of vehicle buttons and inlined kill enemies
* fixed a problem where the vehicle options crashed + added color
* updated colors and added on disable for ped_rush
* finished and added vehicle rain feature
* added aimbot and triggerbot, added templating to buttons
* update vehicle rain desc
* added vdistance check, player check, police check, enemy check. Added even more commenting... sue me. 3 toggles added for the checks and slider for dist. Will tweak more later
* switched to goto statements instead of continue, should be done now
* removed delete nearby vehicles
* there was no check in get_entities for our local vehicle
2023-02-25 13:33:16 -07:00
|
|
|
if (!ped)
|
|
|
|
break;
|
|
|
|
|
|
|
|
target_entities.push_back(ped);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return target_entities;
|
|
|
|
}
|
2023-03-09 12:23:01 +00:00
|
|
|
|
|
|
|
inline bool load_ground_at_3dcoord(Vector3& location)
|
|
|
|
{
|
|
|
|
float groundZ;
|
|
|
|
const uint8_t attempts = 10;
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < attempts; i++)
|
|
|
|
{
|
|
|
|
// Only request a collision after the first try failed because the location might already be loaded on first attempt.
|
|
|
|
for (uint16_t z = 0; i && z < 1000; z += 100)
|
|
|
|
{
|
|
|
|
STREAMING::REQUEST_COLLISION_AT_COORD(location.x, location.y, (float)z);
|
|
|
|
|
|
|
|
script::get_current()->yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MISC::GET_GROUND_Z_FOR_3D_COORD(location.x, location.y, 1000.f, &groundZ, false, false))
|
|
|
|
{
|
|
|
|
location.z = groundZ + 1.f;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
script::get_current()->yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
location.z = 1000.f;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2023-03-30 00:37:10 +02:00
|
|
|
|
|
|
|
inline double distance_to_middle_of_screen(const rage::fvector2& screen_pos)
|
|
|
|
{
|
|
|
|
double cumulative_distance{};
|
|
|
|
|
|
|
|
if (screen_pos.x > 0.5)
|
|
|
|
cumulative_distance += screen_pos.x - 0.5;
|
|
|
|
else
|
|
|
|
cumulative_distance += 0.5 - screen_pos.x;
|
|
|
|
|
|
|
|
if (screen_pos.y > 0.5)
|
|
|
|
cumulative_distance += screen_pos.y - 0.5;
|
|
|
|
else
|
|
|
|
cumulative_distance += 0.5 - screen_pos.y;
|
|
|
|
|
|
|
|
return cumulative_distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Entity get_entity_closest_to_middle_of_screen()
|
|
|
|
{
|
|
|
|
Entity closest_entity{};
|
|
|
|
float distance = 1;
|
|
|
|
|
2023-04-14 18:54:07 +02:00
|
|
|
auto replayInterface = *g_pointers->m_gta.m_replay_interface;
|
2023-03-30 00:37:10 +02:00
|
|
|
auto vehicleInterface = replayInterface->m_vehicle_interface;
|
|
|
|
auto pedInterface = replayInterface->m_ped_interface;
|
|
|
|
|
2023-04-02 01:30:51 +02:00
|
|
|
for (const auto veh : (*vehicleInterface->m_vehicle_list))
|
2023-03-30 00:37:10 +02:00
|
|
|
{
|
|
|
|
if (veh.m_entity_ptr)
|
|
|
|
{
|
2023-04-14 18:54:07 +02:00
|
|
|
Vehicle handle = g_pointers->m_gta.m_ptr_to_handle(veh.m_entity_ptr);
|
2023-03-30 00:37:10 +02:00
|
|
|
Vector3 pos = ENTITY::GET_ENTITY_COORDS(handle, 1);
|
|
|
|
rage::fvector2 screenpos;
|
|
|
|
HUD::GET_HUD_SCREEN_POSITION_FROM_WORLD_POSITION(pos.x, pos.y, pos.z, &screenpos.x, &screenpos.y);
|
|
|
|
|
|
|
|
if (distance_to_middle_of_screen(screenpos) < distance && ENTITY::HAS_ENTITY_CLEAR_LOS_TO_ENTITY(PLAYER::PLAYER_PED_ID(), handle, 17))
|
|
|
|
{
|
|
|
|
closest_entity = handle;
|
|
|
|
distance = distance_to_middle_of_screen(screenpos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-02 01:30:51 +02:00
|
|
|
for (auto ped : *pedInterface->m_ped_list)
|
2023-03-30 00:37:10 +02:00
|
|
|
{
|
|
|
|
if (ped.m_entity_ptr)
|
|
|
|
{
|
2023-04-14 18:54:07 +02:00
|
|
|
Vehicle handle = g_pointers->m_gta.m_ptr_to_handle(ped.m_entity_ptr);
|
2023-03-30 00:37:10 +02:00
|
|
|
Vector3 pos = ENTITY::GET_ENTITY_COORDS(handle, 1);
|
|
|
|
rage::fvector2 screenpos;
|
|
|
|
HUD::GET_HUD_SCREEN_POSITION_FROM_WORLD_POSITION(pos.x, pos.y, pos.z, &screenpos.x, &screenpos.y);
|
|
|
|
|
|
|
|
if (distance_to_middle_of_screen(screenpos) < distance && ENTITY::HAS_ENTITY_CLEAR_LOS_TO_ENTITY(PLAYER::PLAYER_PED_ID(), handle, 17) && handle != PLAYER::PLAYER_PED_ID())
|
|
|
|
{
|
|
|
|
closest_entity = handle;
|
|
|
|
distance = distance_to_middle_of_screen(screenpos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return closest_entity;
|
|
|
|
}
|
2021-05-19 14:35:05 +02:00
|
|
|
}
|