Jump to content

dxText problems.


justn

Recommended Posts

Hi, so the problem i have here, is the text shows, then it doesnt, everytime i restart the resource, the text shows and disappears within 1 second, can you help fix this problem please?

local GrenadeLaunchers = 0 
local GrenadeLText = dxDrawText(GrenadeLaunchers, 986, 0, 1018, 49, tocolor(255, 255, 255, 255), 1.50, "bankgothic", "left", "top", false, false, true, false, false) 
  
addEventHandler("onClientPlayerWeaponSwitch",getRootElement(),function(prevSlot,newSlot) 
if getPedWeapon(getLocalPlayer(),newSlot) == 30 or getPedWeapon(getLocalPlayer(),newSlot) == 31 then 
setElementVisibleTo(GrenadeLText,localPlayer,true) 
setElementVisibleTo(GrenadeLText,root,false) 
else 
setElementVisibleTo(GrenadeLText,localPlayer,false) 
setElementVisibleTo(GrenadeLText,root,false) 
end 
end) 

Link to comment
local rendering = false 
local GrenadeLaunchers = 0 
function renderGrenadeLaunchers() 
    dxDrawText(GrenadeLaunchers, 986, 0, 1018, 49, tocolor(255, 255, 255, 255), 1.50, "bankgothic", "left", "top", false, false, true, false, false) 
end 
  
addEventHandler("onClientPlayerWeaponSwitch",getRootElement(), 
function(prevSlot,newSlot) 
    if getPedWeapon(getLocalPlayer(),newSlot) == 30 or getPedWeapon(getLocalPlayer(),newSlot) == 31 then 
        if (not rendering) then 
            addEventHandler("onClientRender", root, renderGrenadeLaunchers) 
            rendering = true 
        end 
    else 
        if (rendering) then 
            removeEventHandler("onClientRender", root, renderGrenadeLaunchers) 
            rendering = false 
        end 
    end 
end) 

Link to comment

dxDrawText will work only for your resolution because you didn't use getGuiScreenSize().

Quoting one of my post.

I'm not familiar with sizes as well. I got some free time yesterday and decided to make some tests with
getCursorPosition() 

and I found out that its really amazing for sizes. :fadein:

If you want to display your text on the center then:

( This will work on all resolutions )

local sx,sy =  guiGetScreenSize() 
function drawIt () 
dxDrawText("LOL",sx/2,sy/2, sx/2, sy/2,tocolor(0,255,255,255),0.8,"bankgothic","center","center",false,false,false 
end  
  
addEventHandler("onClientResourceStart", resourceRoot, 
function () addEventHandler("onClientRender", root, drawIt) end ) 

Now may god bless you. If you want them at top right or where ever you want on the screen we'll use getCursorPosition() to get the X and Y coordinates to make it fit on all resolutions.

_____________________________________________________________________________________________________________

Use the following code to get the X and Y sizes where you want to display your text.

addCommandHandler("sh", function ()  
if not showed then  
showCursor (true)  
showed = true 
else 
showCursor (false)  
showed = nil 
end  
end) 
  
addCommandHandler("cu",  
function () 
        if isCursorShowing() then 
        outputChatBox ("a") 
            local ScreX, ScreY, _, _,_ = getCursorPosition() 
            outputChatBox("SizeX: "..ScreX.." |||| SizeY: "..ScreY ) 
        end 
    end ) 

Step #1: Use the code I posted. Now execute the command /sh to toggle the cursor ( you must execute this command or else getCursorPosition() won't work.

Step #2: Once you execute /sh then place your cursor on the position where you want to display the text and then type /cu and it will output the Screen X and Y in chatbox.

Step #3: Now copy the SizeX and SizeY from the chatbox and we'll make a use of it

  
local sx,sy = guiGetScreenSize() 
local SizeX, SizeY = X,Y   --- Replace it with the Size X and Y you got from the chatbox ( with the help of getCursorPosition () 
  
function drawIt () 
dxDrawText("LOL",(SizeX)*sx,( SizeY )*sy, (  SizeX )*sx, ( SizeY )*sy,tocolor(0,255,255,255),0.8,"bankgothic","center","center",false,false,false) 
end  
  
addEventHandler("onClientResourceStart", resourceRoot, 
function () addEventHandler("onClientRender", root, drawIt) end ) 

EDIT: Guys if you see what I wrote is wrong then please correct me because I'm not familiar with sizes. :oops:

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...