2021-05-20 21:04:03 +02:00
|
|
|
#include "backend/looped/looped.hpp"
|
|
|
|
#include "core/enums.hpp"
|
|
|
|
#include "util/math.hpp"
|
|
|
|
#include "util/vehicle.hpp"
|
2022-06-27 15:59:25 +02:00
|
|
|
#include "gui.hpp"
|
2021-05-20 21:04:03 +02:00
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
2022-06-27 15:59:25 +02:00
|
|
|
static auto last_time = std::chrono::steady_clock::now();
|
2021-05-20 21:04:03 +02:00
|
|
|
|
|
|
|
void looped::weapons_vehicle_gun()
|
|
|
|
{
|
2022-06-27 15:59:25 +02:00
|
|
|
const bool is_vehicle_gun_selected = g->weapons.custom_weapon == CustomWeapon::VEHICLE_GUN;
|
2021-05-20 21:04:03 +02:00
|
|
|
|
2022-06-27 15:59:25 +02:00
|
|
|
const auto time_now = std::chrono::steady_clock::now();
|
|
|
|
|
|
|
|
const auto elapsed_time_in_ms = std::chrono::duration_cast<std::chrono::milliseconds>(time_now - last_time).count();
|
|
|
|
|
|
|
|
if (is_vehicle_gun_selected &&
|
2022-12-16 18:55:55 +01:00
|
|
|
!g_gui->is_open() &&
|
2022-06-27 15:59:25 +02:00
|
|
|
elapsed_time_in_ms >= 100 &&
|
|
|
|
PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_ATTACK))
|
2021-05-20 21:04:03 +02:00
|
|
|
{
|
2022-06-27 15:59:25 +02:00
|
|
|
Vector3 location = self::pos;
|
|
|
|
|
|
|
|
constexpr int rotation_order = 2;
|
|
|
|
|
|
|
|
Vector3 rot = CAM::GET_GAMEPLAY_CAM_ROT(rotation_order);
|
|
|
|
float pitch = math::deg_to_rad(rot.x); // vertical
|
|
|
|
//float roll = rot.y;
|
|
|
|
float yaw = math::deg_to_rad(rot.z + 90); // horizontal
|
|
|
|
|
|
|
|
float dist = 10.f;
|
|
|
|
location.x += dist * cos(pitch) * cos(yaw);
|
|
|
|
location.y += dist * sin(yaw) * cos(pitch);
|
|
|
|
location.z += dist * sin(pitch);
|
|
|
|
Vehicle veh = vehicle::spawn(
|
2022-07-10 06:33:14 +08:00
|
|
|
rage::joaat((const char*)g->weapons.vehicle_gun_model),
|
2022-06-27 15:59:25 +02:00
|
|
|
location,
|
|
|
|
ENTITY::GET_ENTITY_HEADING(self::ped)
|
|
|
|
);
|
|
|
|
|
|
|
|
dist = 150.f;
|
|
|
|
Vector3 velocity
|
2021-05-20 21:04:03 +02:00
|
|
|
{
|
2022-06-27 15:59:25 +02:00
|
|
|
dist * cos(pitch) * cos(yaw),
|
|
|
|
dist * sin(yaw) * cos(pitch),
|
|
|
|
dist * sin(pitch)
|
|
|
|
};
|
|
|
|
|
|
|
|
ENTITY::SET_ENTITY_ROTATION(veh, rot.x, rot.y, rot.z, rotation_order, 1);
|
|
|
|
ENTITY::SET_ENTITY_VELOCITY(veh, velocity.x, velocity.y, velocity.z);
|
|
|
|
|
|
|
|
// flagging the veh as no longer needed so that the game can remove it
|
|
|
|
// when reaching the maximum vehicle limit,
|
|
|
|
// allowing the vehicle gun to keep working
|
|
|
|
ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&veh);
|
|
|
|
|
|
|
|
last_time = time_now;
|
2021-05-20 21:04:03 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-25 21:17:35 +02:00
|
|
|
}
|