Icon Above Head – FiveM
I was wondering how does some server able to display a custom icon above their character head. For example like the image below
You can see the custom Staff Icon, that is not a default icon available in FiveM. It is a neat feature, at first I tried with NUI since I believe that icon is an image and the only way you can display an image in fiveM is via NUI. It worked, however, it is not the same since if you are using NUI, while the character is moving, you can see the icon staggering. I keep doing research until I found out about DUI and DrawSprites.
DUI
DUI is stands for Direct-rendered UI or ‘Direct NUI’ . From the function itself, I understand that DUI loaded any video,image or URL into the memory , hence the name – Direct UI, while using NUI, you need to call “SendNuiMessages” everytime you wanna display/Close UI. For DUI, Once the URL is loaded, if it is an image URL, you can use “DrawSprites” function to display the image anywhere in the game.
However, the downside of using DUI in “DrawSprites” function is, it does not support background transparency and it looks like below :
This is not the solution that I was looking for. Then I did some research again, I found out that you can use any available texture in ytd form in “DrawSprites” function. For example, you can use default helicopter HUD in the function and it supports any transparent background. So I went through the GTA files via OpenIV try to find the HUD properties.
The properties are :
1. Pixel Format : DXT5
2. MipMaps : 1
3. Size should be under 1024×1024
Then by using Open IV, I created my own custom icon YTD with name customrank
Be careful with the size, for icon you should make it under 128×128. above image is only for testing purpose
And call the function like this :
RequestStreamedTextureDict("customrank", false)
DrawSprite("customrank", "rankone", worldX, worldY, 0.05, 0.1, 0.0, 255, 255, 255, 255)
And voila, this is the result :
Conclusion
You can use NUI or YTD to display an Image/logo without background. However, for something more static like posters/videos that does not need any transparent background. DUI is the better option.