[C#] Add Text to HUD

I wanna be able to draw a text on the screen and change the text at runtime. I figured I would do something like:

Text text = new Text(“Test to see if this works”, new System.Drawing.PointF(20, 30), 1.0f);

text.Draw();

and then whenever I wanna change it use something like: text.caption = “whateverIwant”;

But the text doesn’t show on my screen.

I tried it on playerspawn.

Text needs to be drawn every frame on screen every frame.
So you’ll need to draw the text in the OnTick, and have another function change or enable/disable the text.

Thanks a lot! The text does flash this way even with delay of 0 but it does work :smiley:

If you’re running it on the OnTick you shouldn’t put a delay in it. Because it’s already ran once every tick and it’s not in a while (true) loop that’d cause the thread to be blocked :wink:

Yeah I had delay set to 0. so I just took it away, works perfectly fine now, it sucks there is not much documentation on UI and c# :frowning:

You can learn a lot just by looking through the different classes here: https://github.com/citizenfx/fivem/tree/5db7a5cee1ae1de65b98ffc8c9a19521d7567352/code/client/clrcore/External

If there is something I want to do, and I know it uses a specific function, I’ll just search it on the github repo and it will bring me to the appropriate class and methods I need.

Oh that definitely is useful thank you so much!

1 Like