Lloyd Logan Posted January 16, 2014 Share Posted January 16, 2014 Why does this instantly delete the text? function drawText() dxDrawText("You have successfully bought a vehicle!", 92, 158, 720, 195, tocolor(65, 205, 4, 255), 1.40, "pricedown", "left", "top", false, false, true, false, false) setTimer ( function() triggerEvent("destroy") end, 5000, 1 ) end addEvent("drawSuccess", true) addEventHandler("drawSuccess", root, drawText) function destroyText() removeEventHandler("drawSuccess", getRootElement(), drawText) end addEvent("destroy", true) addEventHandler("destroy", root, destroyText) Link to comment
Lloyd Logan Posted January 16, 2014 Author Share Posted January 16, 2014 What do you mean? As soon as the it draws the text, it disappears almost extremely quickly (like .5 seconds). Link to comment
Forrest Posted January 16, 2014 Share Posted January 16, 2014 dxDraw functions are only drawn for ONE frame, thus needing to work in conjunction with an event such as onClientRender or onClientPreRender in order to draw them every frame. Check the wiki for an example @ https://wiki.multitheftauto.com/wiki/DxDrawText Link to comment
Lloyd Logan Posted January 16, 2014 Author Share Posted January 16, 2014 dxDraw functions are only drawn for ONE frame, thus needing to work in conjunction with an event such as onClientRender or onClientPreRender in order to draw them every frame.Check the wiki for an example @ https://wiki.multitheftauto.com/wiki/DxDrawText Ah, I understand! So how would I trigger them (not using the render?) Link to comment
Castillo Posted January 16, 2014 Share Posted January 16, 2014 You can't use dxDrawText without onClientRender/onClientPreRender/onClientHUDRender. Link to comment
Lloyd Logan Posted January 16, 2014 Author Share Posted January 16, 2014 You can't use dxDrawText without onClientRender/onClientPreRender/onClientHUDRender. So how could I trigger it at a specific time? Link to comment
Castillo Posted January 16, 2014 Share Posted January 16, 2014 You add the event handler to render it. Link to comment
Lloyd Logan Posted January 16, 2014 Author Share Posted January 16, 2014 You add the event handler to render it. But if I were to do onClientRender wouldn't it show as soon as the player joins? Instead of when I trigger it? Link to comment
Castillo Posted January 16, 2014 Share Posted January 16, 2014 If you add the event only when you need to, then no. Link to comment
WASSIm. Posted January 16, 2014 Share Posted January 16, 2014 you can make like this function drawText() -- draw text dxDrawText("You have successfully bought a vehicle!", 92, 158, 720, 195, tocolor(65, 205, 4, 255), 1.40, "pricedown", "left", "top", false, false, true, false, false) addEventHandler("onClientRender", root, drawText) setTimer (removeEventHandler, 5000, 1, "onClientRender", getRootElement(), drawText) -- remove text OR use Textdisplay Link to comment
Lloyd Logan Posted January 16, 2014 Author Share Posted January 16, 2014 If you add the event only when you need to, then no. Wait so I don't need to use addEventHandler within a function until I want to? Link to comment
Castillo Posted January 16, 2014 Share Posted January 16, 2014 Well, I thought that was obvious. Link to comment
Lloyd Logan Posted January 16, 2014 Author Share Posted January 16, 2014 Well, I thought that was obvious. I never thought of it to be honest! Thanks! Link to comment
Castillo Posted January 16, 2014 Share Posted January 16, 2014 function renderMyText ( ) dxDrawText ( arguments ) end addCommandHandler ( "render", function ( ) addEventHandler ( "onClientRender", root, renderMyText ) -- Begin rendering our text end ) addCommandHandler ( "stoprender", function ( ) removeEventHandler ( "onClientRender", root, renderMyText ) -- Stop rendering our text end ) That's an example. Link to comment
Lloyd Logan Posted January 16, 2014 Author Share Posted January 16, 2014 function renderMyText ( ) dxDrawText ( arguments ) end addCommandHandler ( "render", function ( ) addEventHandler ( "onClientRender", root, renderMyText ) -- Begin rendering our text end ) addCommandHandler ( "stoprender", function ( ) removeEventHandler ( "onClientRender", root, renderMyText ) -- Stop rendering our text end ) That's an example. Thank you! All is working. Link to comment
Sasu Posted January 16, 2014 Share Posted January 16, 2014 Line 13: addEventHandler should be removeEventHandler to stop rendering the text. Link to comment
Lloyd Logan Posted January 17, 2014 Author Share Posted January 17, 2014 Line 13: addEventHandler should be removeEventHandler to stop rendering the text. Yeah, I only used his example as a guideline, so all is good, thanks though! 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