Artisz Posted November 2, 2016 Share Posted November 2, 2016 Hi! I want to get the clicked gui label's text, what I clicked on. There is a loop, so I can't add the label an own ID, or I don't know how can I do it. So I create labels in a loop(with the online players's name), and then under the onClientClick eventhandler, I retrieve the clickedElement type, but I get false. Everywhere I clicked, I get just false slot = 0 for v, character in ipairs(getElementsByType("player")) do local characterName = getElementData(character, "CharName") local name = tostring(characterName) slot = slot + 1 guiCreateLabel(440,230 + slot * (30) ,700,50,name,false) end function MemberClick ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) if (button == "left" and state == "up") then local tipe = getElementType( clickedElement ) outputChatBox(tostring(tipe)) end end addEventHandler ( "onClientClick", root, MembeClick) Link to comment
iPrestege Posted November 2, 2016 Share Posted November 2, 2016 (edited) You have a missing 'r' in the function name in the addEventHandler function so ; function MemberClick ( button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement ) if ( button == 'left' and state == 'up' and clickedElement ) then outputChatBox ( getElementType( clickedElement ) ) end end addEventHandler ( 'onClientClick',root,MemberClick ) and this should not give you false anymore because you have to make sure that you have clicked an element . Regards, @Artisz Edited November 2, 2016 by FaHaD Link to comment
Artisz Posted November 2, 2016 Author Share Posted November 2, 2016 It's still bad. When there is the "clickedElement" in the if, it don't write anything, when I delete the clickedElement, it writes false Link to comment
iPrestege Posted November 2, 2016 Share Posted November 2, 2016 what are you trying to click? which element? player? vehicle or what? Link to comment
Artisz Posted November 2, 2016 Author Share Posted November 2, 2016 A gui-label, but anything I click on, I get just false Link to comment
iPrestege Posted November 2, 2016 Share Posted November 2, 2016 isCursorInPosition Use this useful function to get the cursor details x,y,width,height . Link to comment
Artisz Posted November 2, 2016 Author Share Posted November 2, 2016 But how? These labels like a gridlist, there is more label, and don't know how many. How can I use this function? Link to comment
iPrestege Posted November 2, 2016 Share Posted November 2, 2016 aMyLabelOne = guiCreateLabel ( x,y,width,height,'FaHaD',false ) aMyLabelTwo = guiCreateLabel ( x,y,width,height,'Artisz',false ) aMyPositions = { { x,y,width,height,aMyLabelOne }; { x,y,width,height,aMyLabelTwo }; -- Usage = { x,y,width,height,label } -- This how to use this put your label values inside this table -- X = Your label x -- Y = Your label y -- Width = Your label width -- Height = Your label height -- Label = The label verible -- And see the results is should out put the labels text -- You have to replace the x,y,width,height in the table and labels in here to see the results. } function isMouseInPosition ( x,y,width,height ) if ( not isCursorShowing( ) ) then return false end local sx, sy = guiGetScreenSize ( ) local cx, cy = getCursorPosition ( ) local cx, cy = ( cx * sx ), ( cy * sy ) if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then return true else return false end end addEventHandler ( 'onClientClick',root, function ( button,state ) if ( button == 'left' and state == 'up' ) then for _,aValue in ipairs ( aMyPositions ) do if isMouseInPosition ( aValue[1],aValue[2],aValue[3],aValue[4] ) then outputChatBox ( guiGetText ( aValue[5] ) ) end end end end ) @Artisz PS. This is just an example. + Also i forgot to put 'break' so add it to the code. 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