Skip to content

Instantly share code, notes, and snippets.

@cm8263
Last active August 31, 2021 17:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cm8263/c2f337134838c1aaf89d1612ffd38d89 to your computer and use it in GitHub Desktop.
Save cm8263/c2f337134838c1aaf89d1612ffd38d89 to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
using CustomMath;
using CitizenFX.Core;
using static CitizenFX.Core.Native.API;
namespace AimAssist
{
public class AimAssist : BaseScript
{
private bool _aimAssistEnabled = false;
[Command("aimassist")]
private void OnAimAssistCommand()
{
_aimAssistEnabled = !_aimAssistEnabled;
Chat($"Aim Assist {(_aimAssistEnabled ? "Enabled" : "Disabled")}");
if (_aimAssistEnabled)
{
Tick += AimTick;
}
else
{
Tick -= AimTick;
}
}
private async Task AimTick()
{
Vector3 Source = GetFinalRenderedCamCoord();
Vector3 Player = Game.PlayerPed.Position;
Ped ClosestPed = World.GetClosest<Ped>(new Vector2(Player.X, Player.Y));
if (!Entity.Exists(ClosestPed))
{
await Delay(500);
}
Vector3 Target = ClosestPed.Bones[Bone.SKEL_Head].Position;
Matrix4x4 matrix = Matrix4x4.CreateLookAt(Source, Target);
float yaw = (float)Math.Atan2(matrix.V13, matrix.V33);
float pitch = (float)Math.Asin(-matrix.V23);
float roll = (float)Math.Atan2(matrix.V21, matrix.V22);
Chat($"Roll: {roll} Pitch: {pitch} Yaw: {yaw}");
SetGameplayCamRelativeRotation(roll, pitch, yaw);
await Task.FromResult(0);
}
private void Chat(string message)
{
TriggerEvent("chat:addMessage", new
{
color = new[] { 255, 0, 0 },
args = new[] { "[AimAssist]", $"[LOG] " + message }
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment