Hide HUD Script


#1

Trying to remove the hud from the client using this LUA script. But not working.

-- https://wiki.fivem.net/wiki/HUD#Components

--Hide HUD

Citizen.CreateThread(
    while true do 
        if ( DoesEntityExist( ped ) and not IsEntityDead( ped ) ) then
            HideHudComponentThisFrame( 1 ) -- Wanted Stars
            HideHudComponentThisFrame( 2 ) -- Weapon Icon
            HideHudComponentThisFrame( 3 ) -- Cash
            HideHudComponentThisFrame( 4 ) -- MP Cash
            HideHudComponentThisFrame( 6 ) -- Vehicle Name
            HideHudComponentThisFrame( 7 ) -- Area Name
            HideHudComponentThisFrame( 8 ) -- Vehicle Class      
            HideHudComponentThisFrame( 9 ) -- Street Name
            HideHudComponentThisFrame( 13 ) -- Cash Change
            HideHudComponentThisFrame( 17 ) -- Save Game  
            HideHudComponentThisFrame( 20 ) -- Weapon Stats 
        end 
    end 
end )

Any ideas for a fix?

Kind Regards,
Catraz


[HELP] Hide hud and chat and how to disable background chat?
#2

Does it work if you remove the if statement?


#3

what so it would be like:

https://wiki.fivem.net/wiki/HUD#Components

–Hide HUD

Citizen.CreateThread(
HideHudComponentThisFrame( 1 ) – Wanted Stars
HideHudComponentThisFrame( 2 ) – Weapon Icon
HideHudComponentThisFrame( 3 ) – Cash
HideHudComponentThisFrame( 4 ) – MP Cash
HideHudComponentThisFrame( 6 ) – Vehicle Name
HideHudComponentThisFrame( 7 ) – Area Name
HideHudComponentThisFrame( 8 ) – Vehicle Class
HideHudComponentThisFrame( 9 ) – Street Name
HideHudComponentThisFrame( 13 ) – Cash Change
HideHudComponentThisFrame( 17 ) – Save Game
HideHudComponentThisFrame( 20 ) – Weapon Stats
end )

ill check now


#4
Citizen.CreateThread(function()
    while true do
        HideHudComponentThisFrame( 1 ) – Wanted Stars
        HideHudComponentThisFrame( 2 ) – Weapon Icon
        HideHudComponentThisFrame( 3 ) – Cash
        HideHudComponentThisFrame( 4 ) – MP Cash
        HideHudComponentThisFrame( 6 ) – Vehicle Name
        HideHudComponentThisFrame( 7 ) – Area Name
        HideHudComponentThisFrame( 8 ) – Vehicle Class
        HideHudComponentThisFrame( 9 ) – Street Name
        HideHudComponentThisFrame( 13 ) – Cash Change
        HideHudComponentThisFrame( 17 ) – Save Game
        HideHudComponentThisFrame( 20 ) – Weapon Stats
    end
end)

Don’t forget the function() part and loop part! :slight_smile:


#5

ok testing now - just got to load the server


#6

No it doesn’t - it looks like this now

https://wiki.fivem.net/wiki/HUD#Components

–Hide HUD

Citizen.CreateThread(function()
while true do
HideHudComponentThisFrame( 1 ) – Wanted Stars
HideHudComponentThisFrame( 2 ) – Weapon Icon
HideHudComponentThisFrame( 3 ) – Cash
HideHudComponentThisFrame( 4 ) – MP Cash
HideHudComponentThisFrame( 6 ) – Vehicle Name
HideHudComponentThisFrame( 7 ) – Area Name
HideHudComponentThisFrame( 8 ) – Vehicle Class
HideHudComponentThisFrame( 9 ) – Street Name
HideHudComponentThisFrame( 13 ) – Cash Change
HideHudComponentThisFrame( 17 ) – Save Game
HideHudComponentThisFrame( 20 ) – Weapon Stats
end
end)

weird eh?


#7

Are you trying to remove everything from the hud including the minimap?
Or only specific components?

If you want to hide everything try to use this instead:

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0) -- Wait 0 seconds to prevent crashing.
        HideHudAndRadarThisFrame() -- Hides the hud & radar (also removes the weapon wheel etc)
    end
end)

This will prevent you from switching weapons though as you can’t use the weapons wheel anymore, neither using 0-9 will work anymore so if you still want to use weapons, then don’t use this.


#8

No I’m trying to hide specific elements. However i can use this as a base for mine and see if it works. Where did you find HideHudAndRadarThisFrame()?


#9

Should be here somewhere :wink:
https://runtime.fivem.net/doc/reference.html

This is the list for all hud components btw

Full list of components below

HUD = 0;
HUD_WANTED_STARS = 1;
HUD_WEAPON_ICON = 2;
HUD_CASH = 3;
HUD_MP_CASH = 4;
HUD_MP_MESSAGE = 5;
HUD_VEHICLE_NAME = 6;
HUD_AREA_NAME = 7;
HUD_VEHICLE_CLASS = 8;
HUD_STREET_NAME = 9;
HUD_HELP_TEXT = 10;
HUD_FLOATING_HELP_TEXT_1 = 11;
HUD_FLOATING_HELP_TEXT_2 = 12;
HUD_CASH_CHANGE = 13;
HUD_RETICLE = 14;
HUD_SUBTITLE_TEXT = 15;
HUD_RADIO_STATIONS = 16;
HUD_SAVING_GAME = 17;
HUD_GAME_STREAM = 18;
HUD_WEAPON_WHEEL = 19;
HUD_WEAPON_WHEEL_STATS = 20;
MAX_HUD_COMPONENTS = 21;
MAX_HUD_WEAPONS = 22;
MAX_SCRIPTED_HUD_COMPONENTS = 141;

#10

HIDEHUDCOMPONENTTHIS_FRAME(5), with a coma at the end of each line


#11

Could not parse resource metadata file C:/FXServer/resources//Catraz_HUD/__resource.lua: C:/FXServer/resources//Catraz_HUD/__resource.lua:8: syntax error near ‘,’

get that error with the commas


#12

Resource loading for Catraz_HUD failed:
Could not execute resource metadata file C:/FXServer/resources//Catraz_HUD/__resource.lua: C:/FXServer/resources//Catraz_HUD/__resource.lua:5: attempt to index a function value (global ‘Citizen’)
stack traceback:
C:/FXServer/resources//Catraz_HUD/__resource.lua:5: in local 'chunk’
citizen:/scripting/resource_init.lua:38: in function citizen:/scripting/resource_init.lua:1

error without the commas lol


#13

Commas would not work with that. What is the code you have now?


#14

https://wiki.fivem.net/wiki/HUD#Components

–Hide HUD

Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
HideHudComponentThisFrame( 1 ), – Wanted Stars
HideHudComponentThisFrame( 2 ), – Weapon Icon
HideHudComponentThisFrame( 3 ), – Cash
HideHudComponentThisFrame( 4 ), – MP Cash
HideHudComponentThisFrame( 6 ), – Vehicle Name
HideHudComponentThisFrame( 7 ), – Area Name
HideHudComponentThisFrame( 8 ), – Vehicle Class
HideHudComponentThisFrame( 9 ), – Street Name
HideHudComponentThisFrame( 13 ), – Cash Change
HideHudComponentThisFrame( 17 ), – Save Game
HideHudComponentThisFrame( 20 ) – Weapon Stats
end
end)


#15

Try this:

Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
HideHudComponentThisFrame( 1 )
HideHudComponentThisFrame( 2 )
HideHudComponentThisFrame( 3 )
HideHudComponentThisFrame( 4 )
HideHudComponentThisFrame( 6 )
HideHudComponentThisFrame( 7 )
HideHudComponentThisFrame( 8 )
HideHudComponentThisFrame( 9 )
HideHudComponentThisFrame( 13 )
HideHudComponentThisFrame( 17 )
HideHudComponentThisFrame( 20 )
end
end)

#16

tried that already both in the __resource as well as an external client script - doesn’t work

also tried with and with the original if statement and the commas

still no luck


#17

You shouldn’t place that code in your __resource.lua.


This works fine for me:

client.lua

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        HideHudComponentThisFrame(1)
        HideHudComponentThisFrame(2)
        HideHudComponentThisFrame(3)
        HideHudComponentThisFrame(4)
        HideHudComponentThisFrame(6)
        HideHudComponentThisFrame(7)
        HideHudComponentThisFrame(8)
        HideHudComponentThisFrame(9)
        HideHudComponentThisFrame(13)
        HideHudComponentThisFrame(17)
        HideHudComponentThisFrame(20)
    end
end)

__resource.lua

resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'

client_script 'client.lua'

#18

ok brilliant - works for me.

Your a life saver <3


#19

Is there a way to toggle this and show for a period of time? For example
you type
/hud and it shows it for like 20 seconds then disappears or?


#20

Take the while true bit out and add a message command.

Then add a citizen.wait at the bottom and show the hud again.

I’m new to lua but id imagine it would look something like this.

AddEventHandler('chatMessage', function(source, name, msg)
    sm = stringsplit(msg, " ");
    if sm[1] == "/hud" then
        CancelEvent()
        Citizen.Wait(0)
        HideHudComponentThisFrame(1)
        HideHudComponentThisFrame(2)
        HideHudComponentThisFrame(3)
        HideHudComponentThisFrame(4)
        HideHudComponentThisFrame(6)
        HideHudComponentThisFrame(7)
        HideHudComponentThisFrame(8)
        HideHudComponentThisFrame(9)
        HideHudComponentThisFrame(13)
        HideHudComponentThisFrame(17)
        HideHudComponentThisFrame(20)
        Citizen.Wait(20)
        ShowHudComponentThisFrame(1)
        ShowHudComponentThisFrame(2)
        ShowHudComponentThisFrame(3)
        ShowHudComponentThisFrame(4)
        ShowHudComponentThisFrame(6)
        ShowHudComponentThisFrame(7)
        ShowHudComponentThisFrame(8)
        ShowHudComponentThisFrame(9)
        ShowHudComponentThisFrame(13)
        ShowHudComponentThisFrame(17)
        ShowHudComponentThisFrame(20)
    end
end)

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end)

That would be the server.lua and then put this in your __resource.lua:

server_scripts {
	"server.lua"
}

Credit to Chat Commands (/me /do etc) as i used their LUA files as a reference.


[HELP] hide hud by using /hud