feat(Teleport): Moved getting ground at 3d coords to a separate function

This commit is contained in:
Yimura 2020-12-26 23:36:58 +01:00
parent b44404a57b
commit a76de46046
No known key found for this signature in database
GPG Key ID: 54EFAD29393A6E78
2 changed files with 20 additions and 12 deletions

View File

@ -2,24 +2,16 @@
namespace big::features::teleport namespace big::features::teleport
{ {
// Teleport the player (with/without car to a waypoint) Vector3 get_ground_at_3d_coord(Vector3 location)
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);
float groundZ; float groundZ;
uint16_t attempts = 10;
UINT16 attempts = 10; for (uint16_t i = 0; i < attempts; i++)
for (UINT16 i = 0; i < attempts; i++)
{ {
// Only request a collision after the first try failed because the location might already be loaded on first attempt. // Only request a collision after the first try failed because the location might already be loaded on first attempt.
if (i) if (i)
{ {
for (UINT16 z = 0; 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);
@ -39,6 +31,21 @@ namespace big::features::teleport
script::get_current()->yield(); script::get_current()->yield();
} }
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); PED::SET_PED_COORDS_KEEP_VEHICLE(player, location.x, location.y, location.z);
return true; return true;

View File

@ -6,6 +6,7 @@
namespace big::features::teleport namespace big::features::teleport
{ {
bool bring_blip(int blipSprite, int blipColor, int flag = 70); bool bring_blip(int blipSprite, int blipColor, int flag = 70);
Vector3 get_ground_at_3d_coord(Vector3 location);
bool teleport_to_blip(int blipSprite, int blipColor = -1); bool teleport_to_blip(int blipSprite, int blipColor = -1);
bool waypoint(); bool waypoint();
} }