Is ti possible to disable the autoaiming for the player who's playing with a controller

where should i put this code? Could you make a release real quick?

2 Likes

put it in a client.lua file

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		if currentWeaponHash ~= -1569615261 then
        	SetPlayerLockon(PlayerId(), false)
        else
        	SetPlayerLockon(PlayerId(), true)
		end
	end
end)

works best thx for sharing this native with me

1 Like

Keep in mind that doing so breaks this native:

IsPlayerFreeAiming
1 Like

Where do I find this

1 Like

I am still having the issue of not being able to melee attack. We can’t focus on locals or each other for melee attacks. Are there any solutions?

2 Likes

How so?

I’ve had issues w/ core-evidence. When aiming my flash light I couldn’t see shell casings anymore or destroy evidence. The dev who created core-evidence had to make it so shell casings would show whenever I’m holding a flashlight instead of aiming it. IsPlayerFreeAiming has definitely be affected

1 Like

wont lock on melee attacks now

1 Like

Is this done in any script? like police job or qb-weapon?

This is the code you want. Make sure to add it to a client.lua and you should be good.

Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
SetPlayerTargetingMode(2)
end
end)

1 Like

I think u actually want to use SetPlayerTargetingMode(3), not 2

see: SetPlayerTargetingMode - FiveM Natives @ Cfx.re Docs

What I have set works for me so I don’t.

where?

where did you put this?

I’m going to assume anywhere you have free space.

as long as it’s not inside a function or method you will be fine.

client sided. so any client.lua. If on qbcore, i suggest the ignore.lua at the bottom

stopTargetPlayer.rar (661 Bytes)

based on everything read here i made a quick script
plug and play should disable player targeting and keep all ai functions
we are using it on our fivePD server

well not exactly. i must have been tired… dont hang me up on this i may be wrong

client.lua
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)

    local playerPed = PlayerPedId()
    local _, targetPed = GetEntityPlayerIsFreeAimingAt(PlayerId())
    
    if targetPed and IsEntityAPed(targetPed) then
        if IsPedAPlayer(targetPed) then
            -- If the target is another player, disable lock-on
            SetPlayerLockon(PlayerId(), false)
        else
            -- If the target is AI (non-player ped), allow lock-on
            SetPlayerLockon(PlayerId(), true)
        end
    else
        -- No target, allow default behavior
        SetPlayerLockon(PlayerId(), true)
    end

Version 2.0 Changelog

Updated Features:

  • Continuous Enforcement of Combat Settings:
    The script now applies combat settings continuously, checking every second to ensure that all players have the correct settings. This guarantees no magnetism or auto-lock on during combat, ensuring fair play.

  • No More Instant Kill Animations:
    By removing auto-targeting, snap-to reactions, and takedown mechanics, this version eliminates unwanted instant kill animations that could disrupt gameplay.

  • Optimized for Performance:
    The script is optimized to run with minimal performance impact, continuously reapplying the settings without any noticeable delay or resource drain. A check interval of 1 second is used, ensuring the settings stay consistent without introducing lag.

  • Automatic Reapplication on Respawn/Dropped Players:
    The settings are automatically reapplied when a player respawns or disconnects. This ensures that even after a player dies or leaves the game, they will immediately have the correct settings once they re-enter the game.

  • Simplified and Clean Code:
    Detailed comments have been added throughout the script to explain the function and purpose of each section, making it easy to understand and customize if needed.


How to Use:

1. Place the Script in the Resources Folder

  • Navigate to your server’s resources folder.
  • Create a new folder (e.g., stopTargetPlayer) and place your client.lua script inside it.

2. Create a fxmanifest.lua File

  • Inside the same folder, create a file named fxmanifest.lua with the following content:
fx_version 'bodacious'
game 'gta5'

client_scripts {
    'client.lua'
}

3. Start the Resource in server.cfg

  • Open your server.cfg file.
  • Add the line to start the script:

CopyEdit

ensure stopTargetPlayer
  • Save the file and restart your server.

That’s it! Your new script should now be running on your FiveM server.


Benefits:

  • Lightweight: With a 1-second check interval, the script operates efficiently and doesn’t add noticeable performance overhead.
  • No Redundant Checks: Settings are reapplied immediately when a player respawns or drops, ensuring consistent behavior without the need for additional checks.
  • Fair Combat: No auto-lock or aim magnetism, promoting free aim during combat, ensuring a level playing field for everyone.
-- Version 2.0 - Final Version of StopTargetPlayer Combat Settings
-- This script enforces free aim, disables auto-targeting, snap, and kill animations for players in your server.
-- It is designed to work efficiently and continuously for all players without introducing performance issues.

-- Function to apply settings to a player's ped
function ApplyManualCombatSettings(ped)
    -- Enforce Free Aim (no lock-on)
    SetPlayerTargetingMode(3)

    -- Disable ALL lock-on (players AND peds)
    SetPlayerLockon(PlayerId(), false)

    -- Passive flags to remove auto-targeting / snap / takedowns
    SetPedResetFlag(ped, 77, true)    -- Disable melee tracking
    SetPedResetFlag(ped, 155, true)   -- No kill/takedown moves
    SetPedResetFlag(ped, 12, true)    -- Prevent snap-to reactions
    SetPedResetFlag(ped, 124, true)   -- Disable stealth kill logic
    SetPedResetFlag(ped, 292, true)   -- Undocumented but useful

    -- Disable soft aim assist tracking (e.g., magnetism)
    SetPedUsingActionMode(ped, false, -1, 0)
end

-- Ensure settings are reapplied after respawn, drop, and for all players
AddEventHandler('playerSpawned', function()
    local ped = PlayerPedId()
    ApplyManualCombatSettings(ped)
end)

-- Ensure that settings are reapplied after the player drops and respawns
AddEventHandler('playerDropped', function()
    Citizen.Wait(1000) -- Allow time for player to be dropped and respawn
    local ped = PlayerPedId()
    ApplyManualCombatSettings(ped)
end)

-- Reapply combat settings to all players every time the script runs or player joins
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(1000)  -- Set this to a reasonable delay (1 second check)

        -- Loop through all players and apply settings
        local players = GetActivePlayers()
        for _, playerId in ipairs(players) do
            local ped = GetPlayerPed(playerId)
            if DoesEntityExist(ped) then
                ApplyManualCombatSettings(ped)
            end
        end
    end
end)

-- This script is designed for **StopTargetPlayer** combat mechanics
-- It will make sure there is no aim magnetism or auto-lock on players, ensuring fair and free aim during combat.
-- The settings will be reapplied every second to all players, ensuring continuous enforcement.