Xeno Posted February 27, 2012 Posted February 27, 2012 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
Kenix Posted February 27, 2012 Posted February 27, 2012 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. You understand?
Xeno Posted February 27, 2012 Author Posted February 27, 2012 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)
Kenix Posted February 27, 2012 Posted February 27, 2012 function destroyCar( ) destroyElement( source ) end addEventHandler( "onClientGUIClick",destroy, destroyCar ) Because argument clickedElement is button ( string ). You are trying to delete string ? function destroyElement destroy only elements.( not string,tables,.. only userdata ( element ) ) Source in this event is clicked gui element.
Xeno Posted February 27, 2012 Author Posted February 27, 2012 Thanks for the reply and advice ;3 This deletes the button, I had already tried it before ;3 What should I do?
Kenix Posted February 27, 2012 Posted February 27, 2012 Thanks for the reply and advice ;3 No problem. This deletes the button, I had already tried it before ;3 What should I do? I not understand, you need destroy 3d element or what?
Xeno Posted February 27, 2012 Author Posted February 27, 2012 Sorry, I didn't explain it properly I'm trying to delete the car that was selected
Kenix Posted February 27, 2012 Posted February 27, 2012 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?
Xeno Posted February 27, 2012 Author Posted February 27, 2012 Yeah, but I'm trying to do it onClientGUIClick ( so when they press the button )
Kenix Posted February 27, 2012 Posted February 27, 2012 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.
Xeno Posted February 27, 2012 Author Posted February 27, 2012 I mean like, 1. Clicks on Vehicle, and a GUI appears, ( options on it like, destroy, ect) 2. Once player clicks destroy, it will destroy the vehicle they clicked on before.
Kenix Posted February 27, 2012 Posted February 27, 2012 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) )
Xeno Posted February 27, 2012 Author Posted February 27, 2012 Bad arguement at if getElementType( clickedElement ) == "vehicle" then D:
Kenix Posted February 27, 2012 Posted February 27, 2012 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.
Xeno Posted February 27, 2012 Author Posted February 27, 2012 Ok, everything opens, its just when I press the button it doesn't destroy it. I get no errors.
Kenix Posted February 27, 2012 Posted February 27, 2012 1.click on element.2.click on button. 3.clicked element destroyed. Or give me full code i test.
Kenix Posted February 27, 2012 Posted February 27, 2012 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!
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