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:

2 Likes

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

3 Likes

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 )
3 Likes

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.

1 Like

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.

2 Likes

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.

1 Like

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.

1 Like

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

1 Like

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

1 Like

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.

1 Like

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 )
1 Like

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 )
3 Likes

Thank you very much =)

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