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"
|
2022-05-10 05:00:50 +08:00
|
|
|
#include "gta/enums.hpp"
|
2023-03-09 12:23:01 +00:00
|
|
|
#include "gta/net_object_mgr.hpp"
|
2022-12-06 16:12:02 +00:00
|
|
|
#include "services/players/player_service.hpp"
|
2023-03-09 12:23:01 +00:00
|
|
|
#include "vehicle.hpp"
|
2021-05-26 14:38:38 +02:00
|
|
|
|
|
|
|
namespace big::teleport
|
|
|
|
{
|
2022-12-06 16:12:02 +00:00
|
|
|
inline bool teleport_player_to_coords(player_ptr player, Vector3 coords)
|
2021-07-25 21:03:49 +02:00
|
|
|
{
|
2022-12-06 16:12:02 +00:00
|
|
|
Entity ent = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id());
|
2021-07-25 21:03:49 +02:00
|
|
|
|
|
|
|
if (ENTITY::IS_ENTITY_DEAD(ent, true))
|
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
g_notification_service->push_warning("TELEPORT"_T.data(), "TELEPORT_PLAYER_IS_DEAD"_T.data());
|
2021-07-25 21:03:49 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-09 12:23:01 +00:00
|
|
|
if (PED::IS_PED_IN_ANY_VEHICLE(ent, true))
|
2021-07-25 21:03:49 +02:00
|
|
|
{
|
2023-03-09 12:23:01 +00:00
|
|
|
ent = PED::GET_VEHICLE_PED_IS_IN(ent, false);
|
2021-07-25 21:03:49 +02:00
|
|
|
|
2023-03-09 12:23:01 +00:00
|
|
|
if (entity::take_control_of(ent))
|
|
|
|
ENTITY::SET_ENTITY_COORDS(ent, coords.x, coords.y, coords.z, 0, 0, 0, 0);
|
|
|
|
else
|
|
|
|
g_notification_service->push_warning("TELEPORT"_T.data(), "TELEPORT_FAILED_TO_TAKE_CONTROL"_T.data());
|
2021-07-25 21:03:49 +02:00
|
|
|
|
2023-03-09 12:23:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-07-25 21:03:49 +02:00
|
|
|
else
|
2023-03-09 12:23:01 +00:00
|
|
|
{
|
|
|
|
auto hnd = vehicle::spawn(RAGE_JOAAT("ninef"), *player->get_ped()->get_position(), 0.0f, true);
|
|
|
|
ENTITY::SET_ENTITY_VISIBLE(hnd, false, false);
|
|
|
|
ENTITY::SET_ENTITY_COLLISION(hnd, false, false);
|
|
|
|
ENTITY::FREEZE_ENTITY_POSITION(hnd, true);
|
2021-07-25 21:03:49 +02:00
|
|
|
|
2023-03-09 12:23:01 +00:00
|
|
|
g.m_tp_position = {coords.x, coords.y, coords.z};
|
|
|
|
g.m_tp_player_net_id = player->get_ped()->m_net_object->m_object_id;
|
|
|
|
g.m_tp_veh_net_id = g_pointers->m_handle_to_ptr(hnd)->m_net_object->m_object_id;
|
2022-12-06 16:12:02 +00:00
|
|
|
|
2023-03-09 12:23:01 +00:00
|
|
|
if ((player->is_valid() && PED::IS_PED_IN_ANY_VEHICLE(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id()), false))
|
|
|
|
|| PLAYER::IS_REMOTE_PLAYER_IN_NON_CLONED_VEHICLE(player->id()))
|
|
|
|
g_pointers->m_clear_ped_tasks_network(player->get_ped(), true);
|
2021-05-26 14:38:38 +02:00
|
|
|
|
2023-03-09 12:23:01 +00:00
|
|
|
for (int i = 0; i < 15; i++)
|
2021-05-26 14:38:38 +02:00
|
|
|
{
|
2023-03-09 12:23:01 +00:00
|
|
|
script::get_current()->yield(50ms);
|
|
|
|
|
|
|
|
if (auto ptr = (rage::CDynamicEntity*)g_pointers->m_handle_to_ptr(hnd))
|
|
|
|
{
|
|
|
|
if (auto netobj = ptr->m_net_object)
|
|
|
|
{
|
|
|
|
g_pointers->m_migrate_object(player->get_net_game_player(), netobj, 3);
|
|
|
|
}
|
|
|
|
}
|
2021-05-26 14:38:38 +02:00
|
|
|
}
|
|
|
|
|
2023-03-09 12:23:01 +00:00
|
|
|
entity::delete_entity(hnd);
|
2021-05-26 14:38:38 +02:00
|
|
|
|
2023-03-09 12:23:01 +00:00
|
|
|
return true;
|
2021-05-26 14:38:38 +02:00
|
|
|
}
|
2023-03-09 12:23:01 +00:00
|
|
|
}
|
2021-05-26 14:38:38 +02:00
|
|
|
|
2023-03-09 12:23:01 +00:00
|
|
|
inline bool bring_player(player_ptr player)
|
|
|
|
{
|
|
|
|
return teleport_player_to_coords(player, self::pos);
|
2021-05-26 14:38:38 +02:00
|
|
|
}
|
|
|
|
|
2021-07-25 21:03:49 +02:00
|
|
|
inline bool into_vehicle(Vehicle veh)
|
|
|
|
{
|
2022-06-27 15:45:26 +02:00
|
|
|
if (!ENTITY::IS_ENTITY_A_VEHICLE(veh))
|
2021-07-25 21:03:49 +02:00
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
g_notification_service->push_warning("TELEPORT"_T.data(), "TELEPORT_INVALID_VEHICLE"_T.data());
|
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)
|
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
g_notification_service->push_warning("TELEPORT"_T.data(), "TELEPORT_NO_SEATS_FREE"_T.data());
|
2021-07-25 21:03:49 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 location = ENTITY::GET_ENTITY_COORDS(veh, true);
|
2023-03-09 12:23:01 +00:00
|
|
|
entity::load_ground_at_3dcoord(location);
|
2021-07-25 21:03:49 +02:00
|
|
|
|
2022-05-23 06:38:45 +08:00
|
|
|
Ped ped = self::ped;
|
|
|
|
|
|
|
|
ENTITY::SET_ENTITY_COORDS(ped, location.x, location.y, location.z, 0, 0, 0, 0);
|
2021-07-25 21:03:49 +02:00
|
|
|
|
|
|
|
script::get_current()->yield();
|
|
|
|
|
2022-05-23 06:38:45 +08:00
|
|
|
PED::SET_PED_INTO_VEHICLE(ped, veh, seat_index);
|
2021-07-25 21:03:49 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-08 23:59:32 +01:00
|
|
|
inline void to_coords(Vector3 location)
|
|
|
|
{
|
2022-05-23 06:38:45 +08:00
|
|
|
PED::SET_PED_COORDS_KEEP_VEHICLE(self::ped, location.x, location.y, location.z + 1.f);
|
2022-01-08 23:59:32 +01:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2022-06-27 15:45:26 +02:00
|
|
|
if (sprite == (int)BlipIcons::Waypoint)
|
2023-03-09 12:23:01 +00:00
|
|
|
entity::load_ground_at_3dcoord(location);
|
2021-05-26 14:38:38 +02:00
|
|
|
|
2022-05-23 06:38:45 +08:00
|
|
|
PED::SET_PED_COORDS_KEEP_VEHICLE(self::ped, location.x, location.y, location.z);
|
2021-05-26 14:38:38 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-25 21:03:49 +02:00
|
|
|
inline bool to_entity(Entity ent)
|
|
|
|
{
|
|
|
|
Vector3 location = ENTITY::GET_ENTITY_COORDS(ent, true);
|
|
|
|
|
2022-05-23 06:38:45 +08:00
|
|
|
PED::SET_PED_COORDS_KEEP_VEHICLE(self::ped, location.x, location.y, location.z);
|
2021-07-25 21:03:49 +02:00
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
g_notification_service->push_warning("TELEPORT"_T.data(), "TELEPORT_NO_WAYPOINT_SET"_T.data());
|
2021-05-26 14:38:38 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2022-05-10 05:00:50 +08:00
|
|
|
|
|
|
|
inline bool to_objective()
|
|
|
|
{
|
2022-07-31 00:53:08 +08:00
|
|
|
Vector3 location;
|
|
|
|
|
|
|
|
if (!blip::get_objective_location(location))
|
2022-06-27 15:45:26 +02:00
|
|
|
{
|
2023-02-01 19:46:33 +01:00
|
|
|
g_notification_service->push_warning("TELEPORT"_T.data(), "TELEPORT_NO_OBJECTIVE"_T.data());
|
2022-07-31 00:53:08 +08:00
|
|
|
return false;
|
2022-05-10 05:00:50 +08:00
|
|
|
}
|
2022-07-31 00:53:08 +08:00
|
|
|
|
|
|
|
PED::SET_PED_COORDS_KEEP_VEHICLE(self::ped, location.x, location.y, location.z);
|
|
|
|
|
2022-05-10 05:00:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
2022-06-27 15:45:26 +02:00
|
|
|
}
|