[Util] DrawText via NUI

This is a simple dev release designed with the intended purpose of replacing the Native DrawText function.

The upside to this alternative is that you don’t need to run the function every tick, making it great for resource optimization.

Image

image

Download
DrawText.zip (39.0 KB)

Features

  • Lower ms usage
  • Looks identical to DrawText
  • Can use native color codes (~r~, ^6, ect…)
  • Simple and straight forward

Usage

Creating an element:

exports['DrawText']:CreateUIText(text, id, ?x, ?y, ?size)

*The only required arguments are text and id. Text can be nil

Updating an element:

exports['DrawText']:UpdateUIText(id, ?text, ?size, ?color, ?x, ?y)

*All arguments besides ID are optional. color only works if no color code override is used

Showing / Hiding an element:

exports['DrawText']:ToggleUIText(id, ?bool)

*If no bool is provided, the element will toggle between states, Otherwise true = show, false = hide

Removing an element:

exports['DrawText']:DeleteUIText(id)

*Simply deletes the element

Script Example

This simply displays a street label beside your radar.

Citizen.CreateThread(function()
    exports['DrawText']:CreateUIText(nil, "RoadLabel", 17, 2.5, 25)
    while true do
        local street = GetStreetNameFromHashKey(GetStreetNameAtCoord(table.unpack(GetEntityCoords(GetPlayerPed(-1)))))
        if not IsHudHidden() then
            exports['DrawText']:UpdateUIText("RoadLabel", street)
        else
            exports['DrawText']:UpdateUIText("RoadLabel", nil)
        end
        Citizen.Wait(500)
    end
end)

Notes

Obviously, elements cannot have the same ID, so don’t try.

The DrawText resource will increase ms usage with the more requests it handles, however it stays very low in contrast to DrawText()

The resource supports chat and notification color codes. IE ~r~ and ^7.
More info Chat Formatting // Colors, Bold, Underline and here

One last thing, you’re free to rip code, reupload with your scripts, edit and whatever else you can think of. Credit isn’t required though its appriciated.

Code is accessible Yes
Subscription-based No
Lines (approximately) 156
Requirements None
Support Limited
9 Likes

Nice,
We are currently starting to release resources and I think we are going to use that in the future.
Don’t worry we will link you and the post to every script that uses it.

2 Likes

Very nice release! Looking forward to using this!

1 Like

Savior, thank you.

1 Like

is it possible to make a new line in the text by using ~n~