off Posted November 26, 2016 Share Posted November 26, 2016 (edited) I need some help on: dxDrawText Code: local screenWidth, screenHeight = guiGetScreenSize () local playerRadioChannel = getRadioChannelName(getRadioChannel()) function stationDraw(station) dxDrawText ( playerRadioChannel, screenWidth, screenHeight - 155, screenWidth - 66, screenHeight, tocolor ( 135, 96, 45, 255 ), 1.5, "bankgothic", "right" ) end addEventHandler("onClientPlayerRadioSwitch", getLocalPlayer(), stationDraw) I want the text having border, and staying uppercase, how? I do not know. How can I make it stay on screen for a few seconds and then disappear? I think we should use this: setTimer Thanks for everything! Edited November 26, 2016 by IgorRodriguesCo Link to comment
Tails Posted November 26, 2016 Share Posted November 26, 2016 (edited) You must use onClientRender to draw the text on the screen, check this out: local screenWidth, screenHeight = guiGetScreenSize () function onChannelSwitch(station) playerRadioChannel = getRadioChannelName(station) if isTimer(switchTimer) then resetTimer(switchTimer) else switchTimer = setTimer(function() playerRadioChannel = nil end,3000,1) end end addEventHandler("onClientPlayerRadioSwitch", getLocalPlayer(), stationDraw) function stationDraw() if playerRadioChannel then dxDrawText ( playerRadioChannel, screenWidth, screenHeight - 155, screenWidth - 66, screenHeight, tocolor ( 135, 96, 45, 255 ), 1.5, "bankgothic", "right" ) end end addEventHandler("onClientRender", root, stationDraw) The render will try to draw the text so long the playerRadioChannel var is a station name. The onChannelSwitch function takes care of that variable plus a timer to remove it. I think it's easy to understand. Edited November 26, 2016 by Tails Link to comment
Tails Posted November 26, 2016 Share Posted November 26, 2016 (edited) 4 hours ago, IgorRodriguesCo said: I want the text having border, and staying uppercase, how? I do not know. Replace this in the onChannelSwitch func: playerRadioChannel = getRadioChannelName(station):upper() Put this above the other dxDrawText: dxDrawText ( playerRadioChannel, screenWidth + 1, screenHeight - 155 + 1, screenWidth - 66 + 1, screenHeight + 1, tocolor ( 0, 0, 0, 255 ), 1.5, "bankgothic", "right" ) Edited November 26, 2016 by Tails Link to comment
off Posted November 26, 2016 Author Share Posted November 26, 2016 3 hours ago, Tails said: Replace this in the onChannelSwitch func: playerRadioChannel = getRadioChannelName(station):upper() Put this above the other dxDrawText: dxDrawText ( playerRadioChannel, screenWidth + 1, screenHeight - 155 + 1, screenWidth - 66 + 1, screenHeight + 1, tocolor ( 0, 0, 0, 255 ), 1.5, "bankgothic", "right" ) Just add ": upper ()" and work. About borders, its not as I wanted, but for now is a better option. And for how long the text display on the screen, could you help me? Appreciate your help! Thank you! Link to comment
Tails Posted November 26, 2016 Share Posted November 26, 2016 (edited) The text will be shown for 3 seconds (3000 ms). Check the timer function. As for the borders, just play around with the draw functions. All I did was make a copy of the dxDrawText line and add +1 the x,y, width and height. Make another copy on top of it and do -1, then another copy and just do -1 on the y and another one and do +1 on the y. Check this post of mine from 2015: Hope this helps. Edited November 26, 2016 by Tails 1 Link to comment
koragg Posted November 26, 2016 Share Posted November 26, 2016 (edited) 5 hours ago, IgorRodriguesCo said: And for how long the text display on the screen, could you help me? I'll give you my function(s) I made few days ago. Take a look at them and you'll get how it works, probably function snowonmsg() local screenW, screenH = guiGetScreenSize() local px,py = 1600,900 local x,y = (screenW/px), (screenH/py) dxDrawText(snowOnMessage, (screenW * 0.0000) - 1, (screenH * 0.1417) - 1, (screenW * 1.0000) - 1, (screenH * 0.3815) - 1, tocolor(0, 0, 0, 255), 3*y, "default", "center", "center", false, false, false, true, false) dxDrawText(snowOnMessage, (screenW * 0.0000) + 1, (screenH * 0.1417) - 1, (screenW * 1.0000) + 1, (screenH * 0.3815) - 1, tocolor(0, 0, 0, 255), 3*y, "default", "center", "center", false, false, false, true, false) dxDrawText(snowOnMessage, (screenW * 0.0000) - 1, (screenH * 0.1417) + 1, (screenW * 1.0000) - 1, (screenH * 0.3815) + 1, tocolor(0, 0, 0, 255), 3*y, "default", "center", "center", false, false, false, true, false) dxDrawText(snowOnMessage, (screenW * 0.0000) + 1, (screenH * 0.1417) + 1, (screenW * 1.0000) + 1, (screenH * 0.3815) + 1, tocolor(0, 0, 0, 255), 3*y, "default", "center", "center", false, false, false, true, false) dxDrawText(snowOnMessage, screenW * 0.0000, screenH * 0.1417, screenW * 1.0000, screenH * 0.3815, tocolor(255, 255, 0, 255), 3*y, "default", "center", "center", false, false, false, true, false) if isEventHandlerAdded("onClientRender", root, snowoffmsg) == true then removeEventHandler("onClientRender", root, snowoffmsg) end if isEventHandlerAdded("onClientRender", root, snowonmsg) == false then addEventHandler("onClientRender", root, snowonmsg) end setTimer(snowonnomsg,7000,1) end function snowonnomsg() removeEventHandler("onClientRender", root, snowonmsg) end ------------------------------------------------------------------------------------------------------------------------------------------------------------ function isEventHandlerAdded(sEventName, pElementAttachedTo, func) if type(sEventName) == 'string' and isElement(pElementAttachedTo) and type(func) == 'function' then local aAttachedFunctions = getEventHandlers(sEventName, pElementAttachedTo) if type(aAttachedFunctions) == 'table' and #aAttachedFunctions > 0 then for i, v in ipairs(aAttachedFunctions) do if v == func then return true end end end end return false end Where 'snowOnMessage' is a string defined at the top of my script and 'isEventHandlerAdded' is a function which gets rid of annoying debug spam warning messages Edited November 26, 2016 by koragg Link to comment
off Posted November 26, 2016 Author Share Posted November 26, 2016 5 hours ago, Tails said: The text will be shown for 3 seconds (3000 ms). Check the timer function. As for the borders, just play around with the draw functions. All I did was make a copy of the dxDrawText line and add +1 the x,y, width and height. Make another copy on top of it and do -1, then another copy and just do -1 on the y and another one and do +1 on the y. Check this post of mine from 2015: Hope this helps. Thank you! Time is still a problem for me, but I'll try to understand better anyway. Link to comment
Simple0x47 Posted November 26, 2016 Share Posted November 26, 2016 Just add the same dxDrawText with another colour to different X and Y position Link to comment
off Posted November 26, 2016 Author Share Posted November 26, 2016 49 minutes ago, koragg said: I'll give you my function(s) I made few days ago. Take a look at them and you'll get how it works, probably function snowonmsg() local screenW, screenH = guiGetScreenSize() local px,py = 1600,900 local x,y = (screenW/px), (screenH/py) dxDrawText(snowOnMessage, (screenW * 0.0000) - 1, (screenH * 0.1417) - 1, (screenW * 1.0000) - 1, (screenH * 0.3815) - 1, tocolor(0, 0, 0, 255), 3*y, "default", "center", "center", false, false, false, true, false) dxDrawText(snowOnMessage, (screenW * 0.0000) + 1, (screenH * 0.1417) - 1, (screenW * 1.0000) + 1, (screenH * 0.3815) - 1, tocolor(0, 0, 0, 255), 3*y, "default", "center", "center", false, false, false, true, false) dxDrawText(snowOnMessage, (screenW * 0.0000) - 1, (screenH * 0.1417) + 1, (screenW * 1.0000) - 1, (screenH * 0.3815) + 1, tocolor(0, 0, 0, 255), 3*y, "default", "center", "center", false, false, false, true, false) dxDrawText(snowOnMessage, (screenW * 0.0000) + 1, (screenH * 0.1417) + 1, (screenW * 1.0000) + 1, (screenH * 0.3815) + 1, tocolor(0, 0, 0, 255), 3*y, "default", "center", "center", false, false, false, true, false) dxDrawText(snowOnMessage, screenW * 0.0000, screenH * 0.1417, screenW * 1.0000, screenH * 0.3815, tocolor(255, 255, 0, 255), 3*y, "default", "center", "center", false, false, false, true, false) if isEventHandlerAdded("onClientRender", root, snowoffmsg) == true then removeEventHandler("onClientRender", root, snowoffmsg) end if isEventHandlerAdded("onClientRender", root, snowonmsg) == false then addEventHandler("onClientRender", root, snowonmsg) end setTimer(snowonnomsg,7000,1) end function snowonnomsg() removeEventHandler("onClientRender", root, snowonmsg) end ------------------------------------------------------------------------------------------------------------------------------------------------------------ function isEventHandlerAdded(sEventName, pElementAttachedTo, func) if type(sEventName) == 'string' and isElement(pElementAttachedTo) and type(func) == 'function' then local aAttachedFunctions = getEventHandlers(sEventName, pElementAttachedTo) if type(aAttachedFunctions) == 'table' and #aAttachedFunctions > 0 then for i, v in ipairs(aAttachedFunctions) do if v == func then return true end end end end return false end Where 'snowOnMessage' is a string defined at the top of my script and 'isEventHandlerAdded' is a function which gets rid of annoying debug spam warning messages Excuse me, but this code is very confusing. 1 Link to comment
koragg Posted November 26, 2016 Share Posted November 26, 2016 I tried your code and it works even without event handlers lol I think first you need to use this setPlayerHudComponentVisible("radio", false) to hide the default gtasa radio hud and then try draw your own custom radio station text. Link to comment
off Posted November 27, 2016 Author Share Posted November 27, 2016 22 hours ago, koragg said: I tried your code and it works even without event handlers lol I think first you need to use this setPlayerHudComponentVisible("radio", false) to hide the default gtasa radio hud and then try draw your own custom radio station text. My code works, I just wanted borders and uppercase with an on-screen display time. The problem now is get a time, the rest is already done. 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