From b63bf4b0e49ba58c70cd226dd19972f054653991 Mon Sep 17 00:00:00 2001 From: Yimura Date: Thu, 20 May 2021 18:57:53 +0200 Subject: [PATCH] feat(CustomWeapons): Added Cage and Delete guns --- BigBaseV2/src/backend/backend.cpp | 2 + BigBaseV2/src/backend/looped/looped.hpp | 2 + .../src/backend/looped/weapons/cage_gun.cpp | 38 ++++++++++++ .../src/backend/looped/weapons/delete_gun.cpp | 58 +++++++++++++++++++ BigBaseV2/src/core/data/custom_weapons.hpp | 2 + BigBaseV2/src/core/enums.hpp | 2 + BigBaseV2/src/util/entity.hpp | 11 ++++ 7 files changed, 115 insertions(+) create mode 100644 BigBaseV2/src/backend/looped/weapons/cage_gun.cpp create mode 100644 BigBaseV2/src/backend/looped/weapons/delete_gun.cpp diff --git a/BigBaseV2/src/backend/backend.cpp b/BigBaseV2/src/backend/backend.cpp index cd38f229..f0b0cf8e 100644 --- a/BigBaseV2/src/backend/backend.cpp +++ b/BigBaseV2/src/backend/backend.cpp @@ -21,6 +21,8 @@ namespace big QUEUE_JOB_BEGIN_CLAUSE() { + looped::weapons_cage_gun(); + looped::weapons_delete_gun(); looped::weapons_gravity_gun(); looped::weapons_repair_gun(); }QUEUE_JOB_END_CLAUSE diff --git a/BigBaseV2/src/backend/looped/looped.hpp b/BigBaseV2/src/backend/looped/looped.hpp index 63fcbbc1..3261a127 100644 --- a/BigBaseV2/src/backend/looped/looped.hpp +++ b/BigBaseV2/src/backend/looped/looped.hpp @@ -8,9 +8,11 @@ namespace big static void self_godmode(); static void self_noclip(); + static void weapons_cage_gun(); static void weapons_gravity_gun(); static void weapons_repair_gun(); static void vehicle_speedo_meter(); + static void weapons_delete_gun(); }; } \ No newline at end of file diff --git a/BigBaseV2/src/backend/looped/weapons/cage_gun.cpp b/BigBaseV2/src/backend/looped/weapons/cage_gun.cpp new file mode 100644 index 00000000..54210848 --- /dev/null +++ b/BigBaseV2/src/backend/looped/weapons/cage_gun.cpp @@ -0,0 +1,38 @@ +#include "backend/looped/looped.hpp" +#include "core/enums.hpp" +#include "util/entity.hpp" +#include "util/notify.hpp" + +namespace big +{ + static const int controls[] = { 14, 15, 24 }; + + void looped::weapons_cage_gun() + { + bool bCageGun = g.weapons.custom_weapon == CustomWeapon::CAGE_GUN; + + if (bCageGun) + { + if (PAD::IS_DISABLED_CONTROL_PRESSED(0, 25)) + { + PLAYER::DISABLE_PLAYER_FIRING(PLAYER::PLAYER_ID(), true); + for (int control : controls) + PAD::DISABLE_CONTROL_ACTION(0, control, true); + + if (PAD::IS_DISABLED_CONTROL_JUST_RELEASED(0, 24)) + { + Entity entity; + + if (entity::raycast(&entity)) + { + if (ENTITY::IS_ENTITY_A_PED(entity)) + { + entity::cage_ped(entity); + } + } + else notify::above_map("No entity found."); + } + } + } + } +} \ No newline at end of file diff --git a/BigBaseV2/src/backend/looped/weapons/delete_gun.cpp b/BigBaseV2/src/backend/looped/weapons/delete_gun.cpp new file mode 100644 index 00000000..a841881f --- /dev/null +++ b/BigBaseV2/src/backend/looped/weapons/delete_gun.cpp @@ -0,0 +1,58 @@ +#include "backend/looped/looped.hpp" +#include "core/enums.hpp" +#include "util/entity.hpp" +#include "util/math.hpp" +#include "util/notify.hpp" + +namespace big +{ + static const int controls[] = { 14, 15, 24 }; + + void looped::weapons_delete_gun() + { + bool bCageGun = g.weapons.custom_weapon == CustomWeapon::DELETE_GUN; + + if (bCageGun) + { + if (PAD::IS_DISABLED_CONTROL_PRESSED(0, 25)) + { + PLAYER::DISABLE_PLAYER_FIRING(PLAYER::PLAYER_ID(), true); + for (int control : controls) + PAD::DISABLE_CONTROL_ACTION(0, control, true); + + if (PAD::IS_DISABLED_CONTROL_JUST_RELEASED(0, 24)) + { + Entity entity; + + if (entity::raycast(&entity)) + { + if (ENTITY::IS_ENTITY_A_PED(entity) && PED::IS_PED_A_PLAYER(entity)) + { + notify::above_map("You can't delete player entities!"); + } + else + { + Vector3 player = ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), true); + Vector3 entLoc = ENTITY::GET_ENTITY_COORDS(entity, true); + double dist = math::distance_between_vectors(player, entLoc); + + if (dist > 500) + { + notify::above_map("Entity is too far."); + } + else + { + if (entity::take_control_of(entity)) + { + entity::delete_entity(entity); + } + else notify::above_map("~r~Failed to take control of entity."); + } + } + } + else notify::above_map("No entity found."); + } + } + } + } +} \ No newline at end of file diff --git a/BigBaseV2/src/core/data/custom_weapons.hpp b/BigBaseV2/src/core/data/custom_weapons.hpp index 1c4cba9e..9b8bc749 100644 --- a/BigBaseV2/src/core/data/custom_weapons.hpp +++ b/BigBaseV2/src/core/data/custom_weapons.hpp @@ -8,6 +8,8 @@ struct custom_weapon { const custom_weapon custom_weapons[] = { { big::CustomWeapon::NONE, "No weapon" }, + { big::CustomWeapon::CAGE_GUN, "Cage Gun" }, + { big::CustomWeapon::DELETE_GUN, "Delete Gun" }, { big::CustomWeapon::GRAVITY_GUN, "Gravity Gun" }, { big::CustomWeapon::REPAIR_GUN, "Repair Gun" } }; \ No newline at end of file diff --git a/BigBaseV2/src/core/enums.hpp b/BigBaseV2/src/core/enums.hpp index 65f53080..e3b8ccce 100644 --- a/BigBaseV2/src/core/enums.hpp +++ b/BigBaseV2/src/core/enums.hpp @@ -5,6 +5,8 @@ namespace big enum class CustomWeapon { NONE, + CAGE_GUN, + DELETE_GUN, GRAVITY_GUN, REPAIR_GUN }; diff --git a/BigBaseV2/src/util/entity.hpp b/BigBaseV2/src/util/entity.hpp index f63bf2c2..7155b888 100644 --- a/BigBaseV2/src/util/entity.hpp +++ b/BigBaseV2/src/util/entity.hpp @@ -14,6 +14,17 @@ namespace big::entity OBJECT::CREATE_OBJECT(hash, location.x, location.y, location.z - 1.f, true, false, false); } + inline void delete_entity(Entity ent) + { + ENTITY::DETACH_ENTITY(ent, 1, 1); + ENTITY::SET_ENTITY_VISIBLE(ent, false, false); + NETWORK::_NETWORK_SET_ENTITY_INVISIBLE_TO_NETWORK(ent, true); + ENTITY::SET_ENTITY_COORDS_NO_OFFSET(ent, 0, 0, 0, 0, 0, 0); + ENTITY::SET_ENTITY_AS_MISSION_ENTITY(ent, 1, 1); + ENTITY::SET_ENTITY_AS_NO_LONGER_NEEDED(&ent); + ENTITY::DELETE_ENTITY(&ent); + } + inline bool raycast(Entity* ent) { BOOL hit;