justn Posted April 14, 2014 Share Posted April 14, 2014 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
manve1 Posted April 14, 2014 Share Posted April 14, 2014 DirectX needs an event to render it: onClientRender/onClientPreRender. Link to comment
Twisted Posted April 14, 2014 Share Posted April 14, 2014 Try using this: https://wiki.multitheftauto.com/wiki/OnClientRender This will keep the text rendered to the screen and stop it from disappearing on start up Link to comment
Moderators IIYAMA Posted April 14, 2014 Moderators Share Posted April 14, 2014 (edited) setElementVisibleTo > Server-only function dxDrawText Returns true if successful, false otherwise. You should read better, all the information is on the wiki. Edited April 14, 2014 by Guest Link to comment
Weii. Posted April 14, 2014 Share Posted April 14, 2014 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
Saml1er Posted April 14, 2014 Share Posted April 14, 2014 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. 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now