Jump to content

Get element clicked.


Xeno

Recommended Posts

How would I get the element clicked? I tried this but it didn't seem to work:

function click ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) 
        if ( clickedElement == "vehicle" ) then 
  outputChatBox("fuck u") 
        end 
end 
addEventHandler ( "onClientClick", getRootElement(), click) 

Thanks,

Xeno

Link to comment
  
function click ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) 
    if getElementType( clickedElement ) == "vehicle" then 
        outputChatBox("--") 
    end 
end 
addEventHandler ( "onClientClick", root, click) 

You need use function getElementType.

Because clickedElement is element ( userdata ) and you want check with string. :lol:

You understand?

Link to comment

I knew this wasn't going to work, but I tried it anyway.

I'm trying to make it so when you press the "Destroy" button, it destroys the vehicle that was clicked, here is what I have put so far:

  
function destroyCar(clickedElement) 
destroyElement(clickedElement) 
end 
addEventHandler("onClientGUIClick",destroy, destroyCar) 

Link to comment
  
function destroyCar(  ) 
    destroyElement( source ) 
end 
addEventHandler( "onClientGUIClick",destroy, destroyCar ) 

Because argument clickedElement is button ( string ).

You are trying to delete string ? :lol:

function destroyElement destroy only elements.( not string,tables,.. only userdata ( element ) )

Source in this event is clicked gui element.

Link to comment
  
function click ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) 
    if getElementType( clickedElement ) == "vehicle" then 
        destroyElement( clickedElement ) 
    end 
end 
addEventHandler ( "onClientClick", root, click) 

You mean this?

Link to comment
local state 
  
function click ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) 
    if getElementType( clickedElement ) == "vehicle" and state then 
        destroyElement( clickedElement ) 
        state = false 
    end 
end 
addEventHandler ( "onClientClick", root, click) 
  
  
function destroyCar(  ) 
    state = true 
end 
addEventHandler( "onClientGUIClick",destroy, destroyCar ) 

Steps:

1.click on button.

2.click on element.

3.clicked element destroyed.

Or you want click on car and then delete with button?

local element 
  
function click ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) 
    if getElementType( clickedElement ) == "vehicle" then 
        element = clickedElement 
    end 
end 
addEventHandler ( "onClientClick", root, click) 
  
  
function destroyCar(  ) 
    if element and isElement( element ) then 
        destroyElement( element ) 
    end 
end 
addEventHandler( "onClientGUIClick",destroy, destroyCar ) 

1.click on element.

2.click on button.

3.clicked element destroyed.

Link to comment
local element 
  
function click ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) 
    if getElementType( clickedElement ) == "vehicle" then 
        element = clickedElement 
    end 
end 
addEventHandler ( "onClientClick", root, click) 
  
  
function destroyCar(  ) 
    if element and isElement( element ) then 
        destroyElement( element ) 
    end 
end 
addEventHandler( "onClientGUIClick",destroy, destroyCar ) 

1.click on element.

2.click on button.

3.clicked element destroyed.

So use this, but you need modified

( GUI appears, ( options on it like, destroy, ect) )
Link to comment
local element 
  
function click ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) 
    if clickedElement and isElement( clickedElement ) and getElementType( clickedElement ) == "vehicle" then 
        element = clickedElement 
    end 
end 
addEventHandler ( "onClientClick", root, click) 
  
  
function destroyCar(  ) 
    if element and isElement( element ) then 
        destroyElement( element ) 
    end 
end 
addEventHandler( "onClientGUIClick",destroy, destroyCar ) 

Updated.

Forgot it condition :/

Because if you not click at element then it not return element in last argument function.

Link to comment

Client

addEvent( 'onClientElementClicked',true ) 
  
local sx,sy = guiGetScreenSize( ) 
local element 
  
local gui = guiCreateWindow( 0.7672,0.2617,0.2148,0.3248,"Vehicle options", true ) 
local destroy = guiCreateButton( 0.2945,0.6817,0.4618,0.2462,"Destroy", true, gui ) 
local close = guiCreateButton( 0.2800,0.1892,0.4727,0.2312,"Close", true, gui ) 
guiSetVisible( gui, false ) 
  
bindKey( 'F3','down', 
    function( ) 
        guiSetVisible( gui, not guiGetVisible( gui ) ) 
        showCursor( not isCursorShowing( ) ) 
    end 
)    
  
addEventHandler( 'onClientElementClicked',root, 
    function( x,y,z ) 
        element = source 
        fxAddSparks ( x,y,z,1, 1, 1, 1, 10, 0, 0, 0, true, 3, 1 ) 
    end 
) 
     
function click ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) 
    if clickedElement and isElement( clickedElement ) and getElementType( clickedElement ) == "vehicle" then 
        element = clickedElement 
    end 
end 
addEventHandler ( "onClientClick", root, click ) 
  
  
function destroyCar(  ) 
    if element and isElement( element ) then 
        triggerServerEvent( 'onDestroyElement',element ) 
    end 
end 
addEventHandler( "onClientGUIClick",destroy, destroyCar ) 

Server

  
addEvent( 'onDestroyElement',true ) 
addEventHandler( 'onDestroyElement',root, 
    function( ) 
        destroyElement( source ) 
    end 
)    
  
addEventHandler( 'onElementClicked',root, 
    function( _,_,uPlayer,x,y,z ) 
        if source and isElement( source ) and getElementType( source ) == "vehicle" then 
            triggerClientEvent( uPlayer,'onClientElementClicked',source,x,y,z ) 
        end 
    end 
)    
  

Have fun!

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...