create me a fivem hud script
- User
create me a fivem hud script
- Assistant
Creating a HUD (Heads-Up Display) script for FiveM can vary in complexity depending on the features you want to include. Below is a simple example of a HUD script using Lua that displays the player's health, armor, money, and a basic radar.
This script uses the basic FiveM client-side features. Make sure you have the necessary resources set up in your FiveM server for this to work. Create a new resource folder in your
resourcesdirectory namedmy_custom_hud, then create a__resource.luaorfxmanifest.lua, and aclient.luafile as outlined below.Step 1: Create
fxmanifest.luafx_version 'cerulean' game 'gta5' author 'YourName' description 'Simple HUD for FiveM' version '1.0.0' client_scripts { 'client.lua', }Step 2: Create
client.luaCitizen.CreateThread(function() while true do Citizen.Wait(0) -- This makes sure the loop runs every frame -- Get player's health, armor, and money local playerPed = PlayerPedId() local health = GetEntityHealth(playerPed) - 100 -- Health Example local armor = GetPedArmour(playerPed) local playerId = PlayerId() local money = GetAccountMoney("bank") -- Replace with your money method -- Draw the HUD elements drawHud(health, armor, money) end end) function drawHud(health, armor, money) -- HUD Background drawRectangle(0.025, 0.025, 0.2, 0.1, 0, 0, 0, 150) -- Health drawText(0.03, 0.03, "Health: " .. health .. "%", 0.4) -- Armor drawText(0.03, 0.05, "Armor: " .. armor .. "%", 0.4) -- Money drawText(0.03, 0.07, "Money: $" .. money, 0.4) end function drawRectangle(x, y, width, height, r, g, b, a) -- Drawing a rectangle on the screen local w = width * GetScreenResolution() local h = height * GetScreenResolution() DrawRect(x + (w / 2), y + (h / 2), w, h, r, g, b, a) end function drawText(x, y, text, scale) -- Draw text on screen SetTextScale(scale, scale) SetTextFont(0) SetTextProportional(1) SetTextColour(255, 255, 255, 255) SetTextEntry("STRING") AddTextComponentString(text) DrawText(x, y) end function GetScreenResolution() local screenW, screenH = GetActiveScreenResolution() return screenW / 1920, screenH / 1080 endStep 3: Edit
server.cfgMake sure to add your resource to the
server.cfgfile to ensure it loads when you start your server:start my_custom_hudExplanation of the Code
- fxmanifest.lua: Defines the resource metadata like version, author, and the client script file.
- client.lua: Contains the logic to retrieve player stats (health, armor, money) and draw them on the screen.
- drawHud function: Responsible for displaying the HUD on the screen.
- drawRectangle and drawText functions: Helper functions for rendering the background and text.
Installation
- Create a folder named
my_custom_hudin theresourcesdirectory of your FiveM server. - Create
fxmanifest.luaandclient.luafiles inside that folder and paste the respective code snippets. - Add
start my_custom_hudto yourserver.cfg. - Start your FiveM server and test it in-game.
Note
This is a very basic HUD that can be extended with more features such as speed, GPS direction, etc. Make sure to customize and expand this code according to your server's needs.