Remove crosshair?

Hey!

I’m running quite new but fast growing FiveM RP server called SuomiRP.

I was thinking could someone help me with removing the crosshair when u aim down sight ? I’ve seen that some servers has that thing but i’ve not figured it out yet.

I really appreciate it if someone could help. :slight_smile:

You can use HIDE_HUD_COMPONENT_THIS_FRAME to hide HUD elements, and I believe the id for the reticle is 14. So you’d use it like:

HideHudComponentThisFrame( 14 )

This page on the wiki has all of the HUD elements: https://wiki.fivem.net/wiki/HUD

Here you go!

--[[------------------------------------------------------------------------
    Remove Reticle on ADS (Third Person)
------------------------------------------------------------------------]]--
function ManageReticle()
    local ped = GetPlayerPed( -1 )

    if ( DoesEntityExist( ped ) and not IsEntityDead( ped ) ) then
        if ( GetFollowPedCamViewMode() ~= 4 and IsPlayerFreeAiming() ) then 
            HideHudComponentThisFrame( 14 )
        end 
    end 
end 

Citizen.CreateThread( function()
    while true do 
        ManageReticle()

        Citizen.Wait( 0 )
    end 
end )

Thanks man you are the best !

It shows the crosshair for a millisecond after u stop aiming but i don’t care, otherwise it works fine and i’m happy.

No problem!

You could probably use Citizen.Wait() to add a delay before the reticle comes back.

Changed the code a bit, so now the crosshair dosen’t show up anymore just like i want it to be.

--[[------------------------------------------------------------------------
    Remove Reticle on ADS (Third Person)
------------------------------------------------------------------------]]--

function ManageReticle()
    local ped = GetPlayerPed( -1 )

    if ( DoesEntityExist( ped ) and not IsEntityDead( ped ) ) then
        if ( GetFollowPedCamViewMode() ~= 4 and IsPlayerFreeAiming() ) then 
            HideHudComponentThisFrame( 14 )
        end
        Citizen.Wait( 0 )
    end 
    HideHudComponentThisFrame( 14 )
end 

Citizen.CreateThread( function()
    while true do 
        ManageReticle()
    end 
end )


I think it’s fine, gonna test it tomorrow on my server.

Just an FYI, I wouldn’t put a Citizen.Wait() in a place that has the potential to not be reached, as the game will crash otherwise.

Yeah, right. i put it back to where u did put it to. I think it’s fine now

Wow great guys, any chance you make a functionnal script from this piece of code ?

The piece of code by @WolfKnight179 is enough to make it functional, just create a recourse__.lua and put the code in a seperate .lua as a client script.

Thanks a lot for sharing the code wolfknight.

Yeah this is what i did and it’s working !

I would take out and IsPlayerFreeAiming(), because if the player just holds down left click they have the crosshair.

That bit is in as he requested it only work when someone is aiming down sight, which is what IsPlayerFreeAiming gets.

Oh ok! I also modified it, so that it is disabled in any cam mode and what I said before.

I have an issue with this code, now when i aim in first person with a long range weapon there is no ironsight. For example the sniper has no ironsight at all. How to correct it ?

Check if the current player’s weapon is a sniper.

Thanks for the idea !
I’ve tried this and it seems to change nothing, any idea ?


function ManageReticle()
    local ped = GetPlayerPed( -1 )
	local sniper = {"WEAPON_HEAVYSNIPER", "WEAPON_SNIPERRIFLE", "WEAPON_REMOTESNIPER"}
	local weaponsniper = GetCurrentPedWeapon(ped, GetHashKey(sniper), 1)

    if ( DoesEntityExist( ped ) and not IsEntityDead( ped ) ) and not weaponsniper then
        if ( GetFollowPedCamViewMode() ~= 4 and IsPlayerFreeAiming() ) then 
            HideHudComponentThisFrame( 14 )
        end
    end 
    HideHudComponentThisFrame( 14 )
end 

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

Sort of there, you should define static tables outside of looped functions, also, you’re hiding the crosshair no matter what, as you put HideHudComponentThisFrame( 14 ) under the if statement.

Use this to fix the scope’s being removed:

--[[------------------------------------------------------------------------
    Remove Reticle on ADS (Third Person)
------------------------------------------------------------------------]]--
local scopedWeapons = 
{
    100416529,  -- WEAPON_SNIPERRIFLE
    205991906,  -- WEAPON_HEAVYSNIPER
    3342088282  -- WEAPON_MARKSMANRIFLE
}

function HashInTable( hash )
    for k, v in pairs( scopedWeapons ) do 
        if ( hash == v ) then 
            return true 
        end 
    end 

    return false 
end 

function ManageReticle()
    local ped = GetPlayerPed( -1 )

    if ( DoesEntityExist( ped ) and not IsEntityDead( ped ) ) then
        local _, hash = GetCurrentPedWeapon( ped, true )

        if ( GetFollowPedCamViewMode() ~= 4 and IsPlayerFreeAiming() and not HashInTable( hash ) ) then 
            HideHudComponentThisFrame( 14 )
        end 
    end 
end 

Citizen.CreateThread( function()
    while true do 
        ManageReticle()

        Citizen.Wait( 0 )
    end 
end )

Thank you very much =)

I was looking for a script like this, thank you.