2022-12-22 21:23:32 +00:00
|
|
|
#include "backend/bool_command.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "backend/command.hpp"
|
2022-12-22 21:23:32 +00:00
|
|
|
#include "natives.hpp"
|
|
|
|
#include "pointers.hpp"
|
|
|
|
#include "util/vehicle.hpp"
|
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
2023-07-26 22:22:40 +02:00
|
|
|
class spawn_vehicle : command
|
|
|
|
{
|
|
|
|
using command::command;
|
2023-05-10 17:11:59 -04:00
|
|
|
|
2023-08-01 11:10:14 +02:00
|
|
|
virtual std::optional<command_arguments> parse_args(const std::vector<std::string>& args, const std::shared_ptr<command_context> ctx) override
|
2023-07-26 22:22:40 +02:00
|
|
|
{
|
|
|
|
command_arguments result(1);
|
|
|
|
result.push(rage::joaat(args[0]));
|
2023-05-10 17:11:59 -04:00
|
|
|
|
2023-07-26 22:22:40 +02:00
|
|
|
return result;
|
|
|
|
}
|
2023-05-10 17:11:59 -04:00
|
|
|
|
2023-08-01 11:10:14 +02:00
|
|
|
virtual CommandAccessLevel get_access_level() override
|
2023-07-26 22:22:40 +02:00
|
|
|
{
|
|
|
|
return CommandAccessLevel::FRIENDLY;
|
|
|
|
}
|
2023-05-10 17:11:59 -04:00
|
|
|
|
2023-08-01 11:10:14 +02:00
|
|
|
virtual void execute(const command_arguments& args, const std::shared_ptr<command_context> ctx) override
|
2023-07-26 22:22:40 +02:00
|
|
|
{
|
2024-01-31 04:47:03 -05:00
|
|
|
const auto hash = args.get<rage::joaat_t>(0);
|
|
|
|
if (!entity::request_model(hash))
|
2023-07-26 22:22:40 +02:00
|
|
|
{
|
2023-10-20 12:24:44 -04:00
|
|
|
ctx->report_error("BACKEND_SPAWN_VEHICLE_INVALID_MODEL"_T.data());
|
2023-07-26 22:22:40 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-05-10 17:11:59 -04:00
|
|
|
|
2024-04-27 10:10:35 -04:00
|
|
|
auto id = ctx->get_sender()->id();
|
|
|
|
|
|
|
|
const auto spawn_location = vehicle::get_spawn_location(id == self::id ? g.spawn_vehicle.spawn_inside : false,
|
|
|
|
hash, PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(id));
|
|
|
|
const auto spawn_heading = ENTITY::GET_ENTITY_HEADING(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(id));
|
2023-05-10 17:11:59 -04:00
|
|
|
|
2023-08-07 04:16:08 -04:00
|
|
|
auto veh = vehicle::spawn(hash, spawn_location, spawn_heading);
|
2023-05-10 17:11:59 -04:00
|
|
|
|
2023-07-26 22:22:40 +02:00
|
|
|
if (veh == 0)
|
|
|
|
{
|
2024-03-23 00:04:49 +01:00
|
|
|
g_notification_service.push_error("GUI_TAB_SPAWN_VEHICLE"_T.data(), "UNABLE_TO_SPAWN_VEHICLE"_T.data());
|
2023-07-26 22:22:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (g.spawn_vehicle.spawn_maxed)
|
|
|
|
{
|
|
|
|
vehicle::max_vehicle(veh);
|
|
|
|
}
|
2023-05-10 17:11:59 -04:00
|
|
|
|
2023-07-26 22:22:40 +02:00
|
|
|
if (g.spawn_vehicle.spawn_inside && ctx->get_sender()->id() == self::id)
|
|
|
|
{
|
|
|
|
vehicle::teleport_into_vehicle(veh);
|
|
|
|
}
|
2023-08-07 04:16:08 -04:00
|
|
|
ENTITY::SET_ENTITY_AS_NO_LONGER_NEEDED(&veh);
|
2023-07-26 22:22:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-10-20 12:24:44 -04:00
|
|
|
spawn_vehicle g_spawn_vehicle("spawn", "GUI_TAB_SPAWN_VEHICLE", "BACKEND_SPAWN_VEHICLE_DESC", 1);
|
2024-01-31 04:47:03 -05:00
|
|
|
bool_command g_spawn_maxed("spawnmaxed", "SPAWN_MAXED", "SPAWN_MAXED_DESC", g.spawn_vehicle.spawn_maxed);
|
|
|
|
bool_command g_spawn_inside("spawnin", "SPAWN_IN", "SPAWN_IN_DESC", g.spawn_vehicle.spawn_inside);
|
2023-05-10 17:11:59 -04:00
|
|
|
}
|