2022-01-08 23:59:32 +01:00
|
|
|
#pragma once
|
2021-05-26 14:38:38 +02:00
|
|
|
#include "blip.hpp"
|
2021-07-25 21:03:49 +02:00
|
|
|
#include "entity.hpp"
|
2021-05-26 14:38:38 +02:00
|
|
|
|
|
|
|
namespace big::teleport
|
|
|
|
{
|
2021-07-25 21:03:49 +02:00
|
|
|
inline bool bring_player(Player player)
|
|
|
|
{
|
|
|
|
Entity ent = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player);
|
|
|
|
|
|
|
|
if (ENTITY::IS_ENTITY_DEAD(ent, true))
|
|
|
|
{
|
2022-03-02 00:21:29 +01:00
|
|
|
g_notification_service->push_warning("Teleport", "Target player is dead.");
|
2021-07-25 21:03:49 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PED::IS_PED_IN_ANY_VEHICLE(ent, true))
|
|
|
|
{
|
2022-03-02 00:21:29 +01:00
|
|
|
g_notification_service->push_warning("Teleport", "Target player is not in a vehicle.");
|
2021-07-25 21:03:49 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ent = PED::GET_VEHICLE_PED_IS_IN(ent, false);
|
|
|
|
|
|
|
|
if (entity::take_control_of(ent))
|
2022-05-07 18:27:59 -04:00
|
|
|
ENTITY::SET_ENTITY_COORDS(ent, self::pos.x, self::pos.y, self::pos.z, 0, 0, 0, 0);
|
2021-07-25 21:03:49 +02:00
|
|
|
else
|
2022-03-02 00:21:29 +01:00
|
|
|
g_notification_service->push_warning("Teleport", "Failed to take control of player vehicle.");
|
2021-07-25 21:03:49 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-26 14:38:38 +02: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;
|
|
|
|
}
|
|
|
|
|
2021-07-25 21:03:49 +02:00
|
|
|
inline bool into_vehicle(Vehicle veh)
|
|
|
|
{
|
|
|
|
if (!veh)
|
|
|
|
{
|
2022-03-02 00:21:29 +01:00
|
|
|
g_notification_service->push_warning("Teleport", "Player is not in a vehicle.");
|
2021-07-25 21:03:49 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int seat_index = 255;
|
|
|
|
if (VEHICLE::IS_VEHICLE_SEAT_FREE(veh, -1, true))
|
|
|
|
seat_index = -1;
|
|
|
|
else if (VEHICLE::IS_VEHICLE_SEAT_FREE(veh, -2, true))
|
|
|
|
seat_index = -2;
|
|
|
|
|
|
|
|
if (seat_index == 255)
|
|
|
|
{
|
2022-03-02 00:21:29 +01:00
|
|
|
g_notification_service->push_warning("Teleport", "No seats are free in the player vehicle.");
|
2021-07-25 21:03:49 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 location = ENTITY::GET_ENTITY_COORDS(veh, true);
|
|
|
|
load_ground_at_3dcoord(location);
|
|
|
|
|
|
|
|
ENTITY::SET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), location.x, location.y, location.z, 0, 0, 0, 0);
|
|
|
|
|
|
|
|
script::get_current()->yield();
|
|
|
|
|
|
|
|
PED::SET_PED_INTO_VEHICLE(PLAYER::PLAYER_PED_ID(), veh, seat_index);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-08 23:59:32 +01:00
|
|
|
inline void to_coords(Vector3 location)
|
|
|
|
{
|
|
|
|
PED::SET_PED_COORDS_KEEP_VEHICLE(PLAYER::PLAYER_PED_ID(), location.x, location.y, location.z + 1.f);
|
|
|
|
}
|
|
|
|
|
2021-05-26 14:38:38 +02:00
|
|
|
inline bool to_blip(int sprite, int color = -1)
|
|
|
|
{
|
|
|
|
Vector3 location;
|
|
|
|
|
|
|
|
if (!blip::get_blip_location(location, sprite, color))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
load_ground_at_3dcoord(location);
|
|
|
|
|
|
|
|
PED::SET_PED_COORDS_KEEP_VEHICLE(PLAYER::PLAYER_PED_ID(), location.x, location.y, location.z);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-25 21:03:49 +02:00
|
|
|
inline bool to_entity(Entity ent)
|
|
|
|
{
|
|
|
|
Vector3 location = ENTITY::GET_ENTITY_COORDS(ent, true);
|
|
|
|
|
|
|
|
PED::SET_PED_COORDS_KEEP_VEHICLE(PLAYER::PLAYER_PED_ID(), location.x, location.y, location.z);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool to_player(Player player)
|
|
|
|
{
|
|
|
|
return to_entity(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player));
|
|
|
|
}
|
|
|
|
|
2021-05-26 14:38:38 +02:00
|
|
|
inline bool to_waypoint()
|
|
|
|
{
|
|
|
|
if (!to_blip((int)BlipIcons::Waypoint))
|
|
|
|
{
|
2022-03-02 00:21:29 +01:00
|
|
|
g_notification_service->push_warning("Teleport", "Failed to find waypoint position");
|
2021-05-26 14:38:38 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|