-
-
Save cm8263/c2f337134838c1aaf89d1612ffd38d89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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