Feat vehicle gun improv (#291)

This commit is contained in:
Quentin E. / iDeath 2022-06-27 15:59:25 +02:00 committed by GitHub
parent 747af10277
commit a64f016412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 32 deletions

View File

@ -2,47 +2,61 @@
#include "core/enums.hpp" #include "core/enums.hpp"
#include "util/math.hpp" #include "util/math.hpp"
#include "util/vehicle.hpp" #include "util/vehicle.hpp"
#include "gui.hpp"
namespace big namespace big
{ {
static auto last_time = std::chrono::steady_clock::now();
void looped::weapons_vehicle_gun() void looped::weapons_vehicle_gun()
{ {
bool bVehicleGun = g->weapons.custom_weapon == CustomWeapon::VEHICLE_GUN; const bool is_vehicle_gun_selected = g->weapons.custom_weapon == CustomWeapon::VEHICLE_GUN;
if (bVehicleGun) 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 &&
!g_gui.m_opened &&
elapsed_time_in_ms >= 100 &&
PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_ATTACK))
{ {
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_AIM)) 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(
(const char*)g->weapons.vehicle_gun_model,
location,
ENTITY::GET_ENTITY_HEADING(self::ped)
);
dist = 150.f;
Vector3 velocity
{ {
if (PAD::IS_DISABLED_CONTROL_JUST_RELEASED(0, (int)ControllerInputs::INPUT_ATTACK)) dist * cos(pitch) * cos(yaw),
{ dist * sin(yaw) * cos(pitch),
Vector3 location = self::pos; dist * sin(pitch)
};
Vector3 rot = CAM::GET_GAMEPLAY_CAM_ROT(2); ENTITY::SET_ENTITY_ROTATION(veh, rot.x, rot.y, rot.z, rotation_order, 1);
float pitch = math::deg_to_rad(rot.x); // vertical ENTITY::SET_ENTITY_VELOCITY(veh, velocity.x, velocity.y, velocity.z);
//float roll = rot.y;
float yaw = math::deg_to_rad(rot.z + 90); // horizontal
float dist = 10.f; // flagging the veh as no longer needed so that the game can remove it
location.x += dist * cos(pitch) * cos(yaw); // when reaching the maximum vehicle limit,
location.y += dist * sin(yaw) * cos(pitch); // allowing the vehicle gun to keep working
location.z += dist * sin(pitch); ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&veh);
Vehicle veh = vehicle::spawn(
(const char*)g->weapons.vehicle_gun_model,
location,
ENTITY::GET_ENTITY_HEADING(self::ped)
);
Vector3 velocity; last_time = time_now;
dist = 150.f;
velocity.x = dist * cos(pitch) * cos(yaw);
velocity.y = dist * sin(yaw) * cos(pitch);
velocity.z = dist * sin(pitch);
ENTITY::SET_ENTITY_ROTATION(veh, rot.x, rot.y, rot.z, 2, 1);
ENTITY::SET_ENTITY_VELOCITY(veh, velocity.x, velocity.y, velocity.z);
}
}
} }
} }
} }

View File

@ -89,8 +89,10 @@ namespace big
switch (selected) switch (selected)
{ {
case CustomWeapon::VEHICLE_GUN: case CustomWeapon::VEHICLE_GUN:
ImGui::Text("Shooting Model:"); components::input_text_with_hint(
ImGui::InputText("##vehicle_gun_model", g->weapons.vehicle_gun_model, 12); "Shooting Model",
"Name of the vehicle model",
g->weapons.vehicle_gun_model, sizeof(g->weapons.vehicle_gun_model));
break; break;
} }