Chronic Posted November 21, 2013 Share Posted November 21, 2013 Hello everyone I'm having trouble with dx. I know my code isn't correct, I'm just not sure how to do it. What I have so far is: vis = false function dxInterface ( ) dxDrawRectangle ( sx-950, sy-570, sx, sy ) end bindKey ( "F4", "down", function ( ) addEventHandler ( "onClientRender", getRootElement (), dxInterface ) if not ( vis ) then vis = true elseif ( vis ) then vis = false end end ) --function clix ( ) --outputChatBox ( "Hello" ) --end if ( vis ) then addEventHandler ( "onClientClick", getRootElement(), clix ) elseif not ( vis ) then removeEventHandler ( "onClientClick", getRootElement(), clix ) end So, my question is, how do I make onClientClick work? If anyone could help me it would be greatly appreciated! Link to comment
xXMADEXx Posted November 21, 2013 Share Posted November 21, 2013 You are only checking "vis" for onClientClick when the resource starts... Link to comment
.:HyPeX:. Posted November 21, 2013 Share Posted November 21, 2013 You are only checking "vis" for onClientClick when the resource starts... Not mentioning it is pretty messy how its done PD: Try using these functions and Multiply/divide them to get a rectangle size, so it to work on all resolutions. guiGetScreenSize() dxDrawRectangle Link to comment
Chronic Posted November 21, 2013 Author Share Posted November 21, 2013 Reason why it's messy is because I left out a lot of script. I have guiGetScreenSize(). And xXMADEXx, bindKey changes vis = true/false However, none of this solves my problem. Link to comment
.:HyPeX:. Posted November 21, 2013 Share Posted November 21, 2013 Reason why it's messy is because I left out a lot of script. I have guiGetScreenSize().And xXMADEXx, bindKey changes vis = true/false However, none of this solves my problem. Try doing this: function DxDraw() if vis then DxDraw -- Draw stuff else --Nothing end end addEventHandler("OnClientRender", getRootElement(), DxDraw) function Vis() if vis then vis = nil else vis = true end end addCommandHandler("vis", Vis, false, false) PD: you can also try using a timer setTimer(vis, 50, 0) function vis() if ( vis ) then if visOn then else addEventHandler("onClientRender", getRootElement(), function) visOn = true end elseif not ( vis ) then removeEventHandler("onClientRender", getRootElement(), function) visOn = false end end end Link to comment
Chronic Posted November 21, 2013 Author Share Posted November 21, 2013 I'm trying to get onClientClick to work, but I don't know how. The rectangle draws fine. Link to comment
Blaawee Posted November 22, 2013 Share Posted November 22, 2013 Well, that's need math. here an example for you local screenSize = { guiGetScreenSize( ) }; function drawRectangle( ) dxDrawRectangle( screenSize[ 1 ] / 2 - 125, screenSize[ 2 ] / 2 - 12.5, 250, 25, tocolor( 255, 255, 255, 255 ) ); end function onClick( button, state, x, y ) if ( button == 'left' or button == 'right' and state == 'down' ) then -- mouseX > elementPosX mouseX < elementWidth local checkX = ( x > screenSize[ 1 ] / 2 - 125 and x < screenSize[ 1 ] / 2 - 20 + 250 ); -- mouseY > elementPosY mouseY < elementHeight local checkY = ( y > screenSize[ 2 ] / 2 - 12.5 and y < screenSize[ 2 ] / 2 - 12.5 + 25 ); if ( checkX and checkY ) then -- Do something. removeEventHandler( 'onClientRender', root, drawRectangle ); removeEventHandler( 'onClientClick', root, onClick ); end end end addEventHandler( 'onClientResourceStart', resourceRoot, function( ) addEventHandler( 'onClientRender', root, drawRectangle ); addEventHandler( 'onClientClick', root, onClick ); end ); Corect me guys if i'm wrong. 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