Mann56 Posted March 2, 2016 Share Posted March 2, 2016 Hello guys, I've been making a script where i am outputting text on user's click, but it doesn't seem to fade away after timer does it's job. Any help? function addVehScreenInfo ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) if ( clickedElement ) then local elementType = getElementType ( clickedElement ) if elementType == "vehicle" then local occupants = getVehicleOccupants(clickedElement) function drawtheScene() dxDrawRectangle(absoluteX-15,absoluteY-20,300,100,tocolor(0,0,0,75),false) dxDrawText(getVehicleName(clickedElement),absoluteX,absoluteY,300,20,tocolor(255,255,255,255),sx*0.7,"bankgothic") dxDrawText("Driver : " ..getPlayerName(occupants[0]).."",absoluteX,absoluteY+20,300,20,tocolor(255,255,255,255),sx*0.7,"bankgothic") end addEventHandler("onClientRender",root,drawtheScene) setTimer ( stopVehRender,2000, 1) end end end addEventHandler ( "onClientClick", getRootElement(), addVehScreenInfo ) function stopVehRender() removeEventHandler("onClientRender",root,drawtheScene) end Link to comment
Bonus Posted March 2, 2016 Share Posted March 2, 2016 Why do you create the function drawtheScene in the function? Don't do that ... Link to comment
Mann56 Posted March 2, 2016 Author Share Posted March 2, 2016 But dude, the function won't work if outside i have some args in it that won't work outside it's parent function. I already tried it. Link to comment
KariiiM Posted March 2, 2016 Share Posted March 2, 2016 function addVehScreenInfo ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) if ( clickedElement ) then local elementType = getElementType ( clickedElement ) if elementType == "vehicle" then local occupants = getVehicleOccupants(clickedElement) function drawtheScene() dxDrawRectangle(absoluteX-15,absoluteY-20,300,100,tocolor(0,0,0,75),false) dxDrawText(getVehicleName(clickedElement),absoluteX,absoluteY,300,20,tocolor(255,255,255,255),sx*0.7,"bankgothic") dxDrawText("Driver : " ..getPlayerName(occupants[0]).."",absoluteX,absoluteY+20,300,20,tocolor(255,255,255,255),sx*0.7,"bankgothic") end addEventHandler("onClientRender",root,drawtheScene) setTimer(function() removeEventHandler("onClientRender", root, drawtheScene) end, 2000, 1) end end end addEventHandler ( "onClientClick", getRootElement(), addVehScreenInfo ) Link to comment
Mann56 Posted March 2, 2016 Author Share Posted March 2, 2016 It still doesn't work, after 2 secs the rectangle just gets somewhat lighter, doesn't go off.... i did that before too, after that i put the remove event handler out Link to comment
KariiiM Posted March 2, 2016 Share Posted March 2, 2016 It still doesn't work, after 2 secs the rectangle just gets somewhat lighter, doesn't go off....i did that before too, after that i put the remove event handler out Any error/warning? Link to comment
KariiiM Posted March 2, 2016 Share Posted March 2, 2016 Nothing .... Well obviously your code is incorrect, I will try to re script it for you Link to comment
Mann56 Posted March 2, 2016 Author Share Posted March 2, 2016 Nothing .... Well obviously your code is incorrect, I will try to re script it for you A'ight , i just can't find the error since 2 hours Link to comment
KariiiM Posted March 2, 2016 Share Posted March 2, 2016 I had sent you the code via pm, check it and tell me the result (not tested) Link to comment
KariiiM Posted March 2, 2016 Share Posted March 2, 2016 I saw your pm, try this local clickedElement = nil local absoluteX = nil local absoluteY = nil function addVehScreenInfo (button, state, absX, absY, wx, wy, wz, element) if element and getElementType(element) == "vehicle" then clickedElement = element absoluteX = absX absoluteY = absY removeEventHandler("onClientRender",root,drawtheScene) addEventHandler("onClientRender",root,drawtheScene) setTimer(function() removeEventHandler("onClientRender", root, drawtheScene) end, 2000, 1) end end addEventHandler ("onClientClick", getRootElement(), addVehScreenInfo,true) function drawtheScene() dxDrawRectangle(absoluteX-15,absoluteY-20,300,100,tocolor(0,0,0,75),false) dxDrawText(getVehicleName(clickedElement),absoluteX,absoluteY,300,20,tocolor(255,255,255,255),sx*0.7,"bankgothic") dxDrawText("Driver : " ..getPlayerName(getVehicleOccupants(clickedElement)[0]).."",absoluteX,absoluteY+20,300,20,tocolor(255,255,255,255),sx*0.7,"bankgothic") end Link to comment
Mann56 Posted March 2, 2016 Author Share Posted March 2, 2016 Working great, thanks buddy!! Link to comment
KariiiM Posted March 2, 2016 Share Posted March 2, 2016 Working great, thanks buddy!! You're welcome 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