Hide HUD Script

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'
2 Likes

ok brilliant - works for me.

Your a life saver <3

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?

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.

Nope that wouldn’t work.

  1. Hiding the hud needs to be done on the client, not the server.
  2. Hiding the hud needs to execute every frame, so hiding it for 1 frame, then waiting 20 frames will just make it show for those 20 frames and then tell it to “show again”, even though it’s already visible.

Also, whenever possible, use RegisterCommand() instead of the old stringsplit method.

This should work fine though:

local delay = 5 -- 5 seconds


local showHud = false
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0) -- Wait 0 seconds to prevent crashing.
        if (not showHud) then -- hide the hud elements.
			HideHudComponentThisFrame(1)
			HideHudComponentThisFrame(2)
			HideHudComponentThisFrame(3)
			HideHudComponentThisFrame(4)
			HideHudComponentThisFrame(6)
			HideHudComponentThisFrame(7)
			HideHudComponentThisFrame(8)
			HideHudComponentThisFrame(9)
			HideHudComponentThisFrame(13)
			HideHudComponentThisFrame(17)
			HideHudComponentThisFrame(20)
		end
    end
end)

RegisterCommand("hud", function()
	showHud = true
	local timer = GetGameTimer()
	while (GetGameTimer() - timer < (delay * 1000)) do
		Citizen.Wait(0)
	end
	showHud = false
end)

Type /hud in chat or hud in the client (F8) console and it should show for 5 seconds.

2 Likes

Your a genius <3.

Out of interest have you seen my other post about help? Its about vRP, don’t worry if you don’t know i was just wondering.

I know absolutely nothing about esx or vrp. And I try to keep it that way. Personally I’m not a fan of either framework.

Doesn’t seem to be working for some reason :confused: Hmm

works for me. You probably have a customized chat resource that does not support commands. Try typing hud in the F8 console instead.

Giving it a shot right now

Weird…
I tried even in the F8 Console
Uploading…
Map is still there :confused:

The minimap shows because you didn’t disable that. The script I showed you isn’t supposed to disable the minimap. Simply add that id in there on a new line and it should work.

What about the money as well? cause its still there as well cause when I run it nothing happens nothing changes could possibly because of ESX

The script that i made with the help on here should disable the default GTA 5 money but UI elements on ESX wont be effected by this.

how is it you hide the map then?

The minimap?
One of the following ways:

-- every frame
HideHudAndRadarThisFrame()
DisableRadarThisFrame()

-- just once
DisplayRadar(false)

When re-enabling it after calling DisplayRadar(false) I always make sure to check IsRadarPreferenceSwitchedOn() first.

1 Like

Ok so the DisplayRadar(false) one doesnt do anything and the others just make it flash on and back on. DO you know why?

Works fine. You probably have another resource calling that and setting it to true every frame.

you need to call them every frame like i said.

I wasnt sure how to do this but I ended up wiritng a radar toggle inside of my script and then I called that event and it made it work. Hard to explain but thanks for the help :slight_smile:

i am getting this error any ideas?

image