DrawText(x, y) problems?

Hey everyone, i’m having trouble with DrawText()

It seems like no matter what number is in DrawText(x, y), the text is always at the top left of the screen. I am trying to make the text appear in the middle of the players screen. Here is what I have:

   local screenW, screenH = GetScreenResolution()
   local height = 1080
   local ratio = screenW/screenH
   local width = height*ratio

   SetTextFont(1)
   SetTextProportional(1)
   SetTextScale(0.0, 0.3)
   SetTextColour(128, 128, 128, 255)
   SetTextDropshadow(0, 0, 0, 0, 255)
   SetTextEdge(1, 0, 0, 0, 150)
   SetTextDropshadow()
   SetTextOutline()
   --SetTextCentre(1)
   SetTextEntry("String")
   AddTextComponentString("Press E to sell your vehicle!")
   DrawText( width/2, 100 ) -- seems like no matter what numbers are in here, the text is always at the top left
ClientHelpers.DrawText3D = function(x, y, z, text)
    local onScreen,_x,_y=World3dToScreen2d(x,y,z)
    local px,py,pz=table.unpack(GetGameplayCamCoords())
    local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1)
 
    local scale = (1/dist)*2
    local fov = (1/GetGameplayCamFov())*100
    local scale = scale*fov
   
    if onScreen then
        SetTextScale(0.0*scale, 0.55*scale)
        SetTextFont(0)
        SetTextProportional(1)
        -- SetTextScale(0.0, 0.55)
        SetTextColour(255, 255, 255, 255)
        SetTextDropshadow(0, 0, 0, 0, 255)
        SetTextEdge(2, 0, 0, 0, 150)
        SetTextDropShadow()
        SetTextOutline()
        SetTextEntry("STRING")
        SetTextCentre(1)
        AddTextComponentString(text)
        DrawText(_x,_y)
    end
end

I believe that script is for displaying text in certain areas of the map (the text gets smaller/larger depending on how far you are). I’m not trying to do something quite that complex, I just want the text to display in the middle of the players screen.

I am on my phone was just showing you some examples of some things you could use from this.
(I am also in bed)

If you can’t figure this out you could try to use NUI.

function drawTxt(x,y ,width,height,scale, text, r,g,b,a, outline)
    SetTextFont(0)
    SetTextProportional(0)
    SetTextScale(scale, scale)
    SetTextColour(r, g, b, a)
    SetTextDropShadow(0, 0, 0, 0,255)
    SetTextEdge(1, 0, 0, 0, 255)
    SetTextDropShadow()
    if(outline)then
	    SetTextOutline()
	end
    SetTextEntry("STRING")
    AddTextComponentString(text)
    DrawText(x - width/2, y - height/2 + 0.005)
end

Found this one oon the forums.

Hmm. I have similar stuff to this script. The thing is, mine should work, but it seems no matter what width and height I enter inside of DrawText(), it is still in the top left of my screen. I even tried DrawText(960, 540), which is the center of a 1080p monitor, and yet it still displays in the top left.

Still having trouble with this.

I figured it out. It looks like the x and y in DrawText(x, y) have to be a float from 0.0 to 1.0. DrawText(0.5, 0.7) got it to where I wanted it.