From eea400073802a9feb83e60c592d6bdcb45401612 Mon Sep 17 00:00:00 2001 From: Yimura Date: Thu, 31 Dec 2020 01:46:39 +0100 Subject: [PATCH] feat(PlayerWindow & TabVehicle): Updated some strings, updated teleport options --- BigBaseV2/src/features/teleport.cpp | 146 ++++++++++++++-------- BigBaseV2/src/features/teleport.hpp | 5 +- BigBaseV2/src/gui/player_window.cpp | 21 ++-- BigBaseV2/src/gui/tab_bar/tab_vehicle.cpp | 2 +- 4 files changed, 113 insertions(+), 61 deletions(-) diff --git a/BigBaseV2/src/features/teleport.cpp b/BigBaseV2/src/features/teleport.cpp index 52a6f7e9..5464cdf9 100644 --- a/BigBaseV2/src/features/teleport.cpp +++ b/BigBaseV2/src/features/teleport.cpp @@ -2,21 +2,41 @@ namespace big::features::teleport { - Vector3 get_ground_at_3d_coord(Vector3 location) + bool load_ground_at_3dcoord(Vector3 location) { float groundZ; - uint16_t attempts = 10; - for (uint16_t i = 0; i < attempts; i++) + 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. - if (i) + for (uint8_t z = 0; i && z < 1000; z += 100) { - for (uint16_t z = 0; z < 1000; z += 100) - { - STREAMING::REQUEST_COLLISION_AT_COORD(location.x, location.y, z); + STREAMING::REQUEST_COLLISION_AT_COORD(location.x, location.y, z); - script::get_current()->yield(); - } + script::get_current()->yield(); + } + + if (MISC::GET_GROUND_Z_FOR_3D_COORD(location.x, location.y, 1000.f, &groundZ, false, false)) + return true; + + script::get_current()->yield(); + } + + return false; + } + + Vector3 get_ground_at_3dcoord(Vector3 location) + { + float groundZ; + 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 (uint8_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)) @@ -34,23 +54,6 @@ namespace big::features::teleport return location; } - // Teleport the player (with/without car to a waypoint) - bool waypoint() - { - Ped player = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_playerId); - - Blip blipHandle = HUD::GET_FIRST_BLIP_INFO_ID(8); - if (!HUD::DOES_BLIP_EXIST(blipHandle)) return false; - - Vector3 location = HUD::GET_BLIP_COORDS(blipHandle); - - location = get_ground_at_3d_coord(location); - - PED::SET_PED_COORDS_KEEP_VEHICLE(player, location.x, location.y, location.z); - - return true; - } - bool bring_blip(int blipSprite, int blipColor, int flag) { Blip blipHandle = HUD::GET_FIRST_BLIP_INFO_ID(blipSprite); @@ -107,34 +110,79 @@ namespace big::features::teleport if (!HUD::DOES_BLIP_EXIST(blipHandle) || (blipColor != -1 && HUD::GET_BLIP_COLOUR(blipHandle) != blipColor)) return false; Vector3 location = HUD::GET_BLIP_COORDS(blipHandle); - float groundZ; + location = get_ground_at_3dcoord(location); - UINT16 attempts = 10; - for (UINT16 i = 0; i < attempts; i++) + PED::SET_PED_COORDS_KEEP_VEHICLE(player, location.x, location.y, location.z); + + return true; + } + + void teleport_into_player_vehicle(Player player) + { + Ped target = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player); + + if (!PED::IS_PED_IN_ANY_VEHICLE(target, true)) { - // Only request a collision after the first try failed because the location might already be loaded on first attempt. - if (i) - { - for (UINT16 z = 0; z < 1000; z += 100) - { - STREAMING::REQUEST_COLLISION_AT_COORD(location.x, location.y, z); + features::notify::above_map("This player is not in a vehicle right now."); - 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; - - break; - } - - if (i == attempts - 1) location.z = 1000.f; - - script::get_current()->yield(); + return; } + Vector3 location = ENTITY::GET_ENTITY_COORDS(target, true); + + for (uint8_t i = 0; !load_ground_at_3dcoord(location); i++) + if (i == 5) break; + + Ped current = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_playerId); + + Vehicle veh; + for (veh = 0; !veh; veh = PED::GET_VEHICLE_PED_IS_IN(target, false)) + { + if (!PED::IS_PED_IN_ANY_VEHICLE(target, true)) + { + features::notify::above_map("Player is no longer in a vehicle."); + + return; + } + + veh = PED::GET_VEHICLE_PED_IS_IN(target, false); + + if (!veh) + { + ENTITY::SET_ENTITY_COORDS(current, location.x, location.y, 1000.f, 0, 0, 0, 0); + + script::get_current()->yield(50ms); + } + } + + int seatIndex = -2; + if (VEHICLE::IS_VEHICLE_SEAT_FREE(veh, -1, 0)) seatIndex = -1; + + PED::SET_PED_INTO_VEHICLE(current, veh, seatIndex); + } + + void teleport_to_player(Player player) + { + Ped target = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player); + + Vector3 location = ENTITY::GET_ENTITY_COORDS(target, true); + load_ground_at_3dcoord(location); + + PED::SET_PED_COORDS_KEEP_VEHICLE(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_playerId), location.x, location.y, location.z); + } + + // Teleport the player (with/without car to a waypoint) + bool waypoint() + { + Ped player = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_playerId); + + Blip blipHandle = HUD::GET_FIRST_BLIP_INFO_ID(8); + if (!HUD::DOES_BLIP_EXIST(blipHandle)) return false; + + Vector3 location = HUD::GET_BLIP_COORDS(blipHandle); + + location = get_ground_at_3dcoord(location); + PED::SET_PED_COORDS_KEEP_VEHICLE(player, location.x, location.y, location.z); return true; diff --git a/BigBaseV2/src/features/teleport.hpp b/BigBaseV2/src/features/teleport.hpp index a5567c55..0642a034 100644 --- a/BigBaseV2/src/features/teleport.hpp +++ b/BigBaseV2/src/features/teleport.hpp @@ -6,7 +6,10 @@ namespace big::features::teleport { bool bring_blip(int blipSprite, int blipColor, int flag = 70); - Vector3 get_ground_at_3d_coord(Vector3 location); + bool load_ground_at_3dcoord(Vector3 location); + Vector3 get_ground_at_3dcoord(Vector3 location); bool teleport_to_blip(int blipSprite, int blipColor = -1); + void teleport_into_player_vehicle(Player player); + void teleport_to_player(Player player); bool waypoint(); } \ No newline at end of file diff --git a/BigBaseV2/src/gui/player_window.cpp b/BigBaseV2/src/gui/player_window.cpp index 483055bd..5b01d78a 100644 --- a/BigBaseV2/src/gui/player_window.cpp +++ b/BigBaseV2/src/gui/player_window.cpp @@ -33,16 +33,17 @@ namespace big { QUEUE_JOB_BEGIN_CLAUSE() { - Ped player = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_playerId); - Ped target = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(g_selectedPlayer); - - Vector3 location = ENTITY::GET_ENTITY_COORDS(target, true); - - PED::SET_PED_COORDS_KEEP_VEHICLE(player, location.x, location.y, location.z + 1.f); + features::teleport::teleport_to_player(g_selectedPlayer); }QUEUE_JOB_END_CLAUSE } - + if (ImGui::Button("Teleport into Vehicle")) + { + QUEUE_JOB_BEGIN_CLAUSE() + { + features::teleport::teleport_into_player_vehicle(g_selectedPlayer); + }QUEUE_JOB_END_CLAUSE + } ImGui::Separator(); @@ -108,7 +109,8 @@ namespace big }QUEUE_JOB_END_CLAUSE } - if (ImGui::BeginCombo("Invite Location:", location_names[g_temp.teleport_location])) + ImGui::Text("Force TP Location:"); + if (ImGui::BeginCombo("##teleport_location", location_names[g_temp.teleport_location])) { for (uint8_t i = 0; i < IM_ARRAYSIZE(location_names); i++) { @@ -121,7 +123,7 @@ namespace big ImGui::EndCombo(); } - if (ImGui::Button("Send Invite")) + if (ImGui::Button("Teleport to selected location.")) { QUEUE_JOB_BEGIN_CLAUSE() { @@ -141,7 +143,6 @@ namespace big OBJECT::CREATE_AMBIENT_PICKUP(0x1E9A99F8, coords.x, coords.y, coords.z + 0.5f, 0, rand() % 500 + 2000, (Hash)-1666779307, false, true); STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED((Hash)-1666779307); }QUEUE_JOB_END_CLAUSE - } ImGui::End(); diff --git a/BigBaseV2/src/gui/tab_bar/tab_vehicle.cpp b/BigBaseV2/src/gui/tab_bar/tab_vehicle.cpp index 9832ec76..7b44c5b0 100644 --- a/BigBaseV2/src/gui/tab_bar/tab_vehicle.cpp +++ b/BigBaseV2/src/gui/tab_bar/tab_vehicle.cpp @@ -44,7 +44,7 @@ namespace big { Vector3 location = HUD::GET_BLIP_COORDS(blipHandle); // Make sure the AI can reach this - location = features::teleport::get_ground_at_3d_coord(location); + location = features::teleport::get_ground_at_3dcoord(location); TASK::TASK_VEHICLE_DRIVE_TO_COORD(PLAYER::PLAYER_PED_ID(), veh, location.x, location.y, location.z, 35.f, 0, veh, 2883620, 10.f, true); }