This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
karifeld 04142b2d98
refactor: Modernized/optimized general code, bug fixing and more (#226)
* refactor: Use self globals

* refactor: Use gui::components

* fix(Vehicle Preview): Addresses #119

Previewed vehicle set to unclimbable

Only preview when hovered on vehicle

* fix(Infinite Clip): Disabling it now works

* fix(No Ragdoll): Disabling it now works

Removed unnecessary calls to natives (0xB128377056A54E2A should be enough)

* fix(Spawn): Wrong footer placement

* fix self globals file name typo

* refactor(Mobile): Clear ped tasks when set conditions are met

Only clear ped tasks if pv_teleport_into bool is true and ped is in a vehicle

* feat(Weapons): Remove current weapon

* refactor: Added missing variable in calls to self globals

* refactor: Utilize usage of ControllerInputs

* fix(Vehicle Fly): uninitialized local variable 'ped' used

* refactor(No Ragdoll, Infinite Clip): Only run on boolean change.

* refactor(Infinite Ammo): Simplified code

* refactor: Utilize ControllerInputs in other areas of code

* refactor: Utilize ControllerInputs in other areas of code
2022-05-22 18:38:45 -04:00

104 lines
2.7 KiB
C++

#include "backend/looped/looped.hpp"
#include "fiber_pool.hpp"
#include "gta/enums.hpp"
#include "natives.hpp"
#include "script.hpp"
#include "util/entity.hpp"
namespace big
{
static const int controls[] = {
(int)ControllerInputs::INPUT_SPRINT,
(int)ControllerInputs::INPUT_MOVE_UP_ONLY,
(int)ControllerInputs::INPUT_MOVE_DOWN_ONLY,
(int)ControllerInputs::INPUT_MOVE_LEFT_ONLY,
(int)ControllerInputs::INPUT_MOVE_RIGHT_ONLY,
(int)ControllerInputs::INPUT_DUCK
};
static float speed = 20.f;
static float mult = 0.f;
static bool bLastNoclip = false;
static Entity prev = -1;
static Vector3 rot{};
void looped::self_noclip() {
bool bNoclip = g->self.noclip;
Vector3 location = self::pos;
Entity ent = self::veh != NULL ? self::veh : self::ped;
// cleanup when changing entities
if (prev != ent)
{
ENTITY::FREEZE_ENTITY_POSITION(prev, false);
ENTITY::SET_ENTITY_COLLISION(prev, true, true);
prev = ent;
}
if (bNoclip)
{
for (int control : controls)
PAD::DISABLE_CONTROL_ACTION(0, control, true);
Vector3 vel = { 0.f, 0.f, 0.f };
float heading = 0.f;
// Left Shift
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_SPRINT))
vel.z += speed / 2;
// Left Control
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_DUCK))
vel.z -= speed / 2;
// Forward
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_MOVE_UP_ONLY))
vel.y += speed;
// Backward
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_MOVE_DOWN_ONLY))
vel.y -= speed;
// Left
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_MOVE_LEFT_ONLY))
vel.x -= speed;
// Right
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_MOVE_RIGHT_ONLY))
vel.x += speed;
rot = CAM::GET_GAMEPLAY_CAM_ROT(2);
ENTITY::SET_ENTITY_ROTATION(ent, 0.f, rot.y, rot.z, 2, 0);
ENTITY::SET_ENTITY_COLLISION(ent, false, false);
if (vel.x == 0.f && vel.y == 0.f && vel.z == 0.f)
{
// freeze entity to prevent drifting when standing still
ENTITY::FREEZE_ENTITY_POSITION(ent, true);
mult = 0.f;
}
else
{
if (mult < 20.f)
mult += 0.15f;
ENTITY::FREEZE_ENTITY_POSITION(ent, false);
Vector3 offset = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(ent, vel.x, vel.y, 0.f);
vel.x = offset.x - location.x;
vel.y = offset.y - location.y;
ENTITY::SET_ENTITY_VELOCITY(ent, vel.x * mult, vel.y * mult, vel.z * mult);
}
}
else if (bNoclip != bLastNoclip)
{
if (entity::take_control_of(ent))
{
ENTITY::FREEZE_ENTITY_POSITION(ent, false);
ENTITY::SET_ENTITY_COLLISION(ent, true, false);
}
}
bLastNoclip = bNoclip;
}
}