Jump to content

onClientClick


Chronic

Recommended Posts

Hello everyone I'm having trouble with dx. I know my code isn't correct, I'm just not sure how to do it. :cry:

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! :P

Link to comment
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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...