Cyanide Posted July 10, 2011 Share Posted July 10, 2011 Hey MTA, I've been trying to solve this problem for a while now. The problem is that, onClientGUIClick isn't being called. My code is below, any help? Team_Selection_1 = {} function onPlayerResourceStart( ) Team_Selection_1[1] = guiCreateButton(326,534,196,88,"Attack",false) guiSetFont(Team_Selection_1[1],"sa-header") Team_Selection_1[2] = guiCreateButton(199,90,5,5,"",false,Team_Selection_1[1]) Team_Selection_1[3] = guiCreateButton(562,534,196,88,"Defence",false) guiSetFont(Team_Selection_1[3],"sa-header") Team_Selection_1[4] = guiCreateButton(199,90,5,5,"",false,Team_Selection_1[3]) guiSetVisible( Team_Selection_1, true ) showCursor(true) end function onPlayerClickGUI( ) ouputChatBox( "You clicked Attack" ) end addEventHandler ( "onClientGUIClick", Team_Selection_1[1], onPlayerClickGUI ) addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), onPlayerResourceStart ) Link to comment
Jaysds1 Posted July 10, 2011 Share Posted July 10, 2011 try this: Team_Selection_1 = {} function onPlayerResourceStart( ) Team_Selection_1[1] = guiCreateButton(326,534,196,88,"Attack",false) guiSetFont(Team_Selection_1[1],"sa-header") Team_Selection_1[2] = guiCreateButton(199,90,5,5,"",false,Team_Selection_1[1]) Team_Selection_1[3] = guiCreateButton(562,534,196,88,"Defence",false) guiSetFont(Team_Selection_1[3],"sa-header") Team_Selection_1[4] = guiCreateButton(199,90,5,5,"",false,Team_Selection_1[3]) guiSetVisible( Team_Selection_1, true ) showCursor(true) end function onPlayerClickGUI(button) if (button == "left") then ouputChatBox( "You clicked Attack" ) end end addEventHandler ( "onClientGUIClick", Team_Selection_1[1], onPlayerClickGUI, false ) addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), onPlayerResourceStart ) You forgot to add the false at the end of onClientGUIClick. Link to comment
Castillo Posted July 10, 2011 Share Posted July 10, 2011 I would do something like this: Team_Selection_1 = {} function onPlayerResourceStart( ) Team_Selection_1[1] = guiCreateButton(326,534,196,88,"Attack",false) guiSetFont(Team_Selection_1[1],"sa-header") Team_Selection_1[2] = guiCreateButton(199,90,5,5,"",false,Team_Selection_1[1]) Team_Selection_1[3] = guiCreateButton(562,534,196,88,"Defence",false) guiSetFont(Team_Selection_1[3],"sa-header") Team_Selection_1[4] = guiCreateButton(199,90,5,5,"",false,Team_Selection_1[3]) guiSetVisible( Team_Selection_1, true ) showCursor(true) end addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), onPlayerResourceStart ) function onPlayerClickGUI(button) if (button == "left") then if (source == Team_Selection_1[1]) then ouputChatBox( "You clicked Attack" ) elseif (source == Team_Selection_1[3]) then ouputChatBox( "You clicked Defence" ) end end end addEventHandler ( "onClientGUIClick", root, onPlayerClickGUI ) Link to comment
Cyanide Posted July 10, 2011 Author Share Posted July 10, 2011 Thank you both for replies! @Solidsnake14 - Thanks, I noticed you used "root" instead of using a function on end addEventHandler ( "onClientGUIClick", root, onPlayerClickGUI ) Is there a difference if I called a function instead of simply putting "root"? @Jaysds1 - Thanks, just curious: How will changing the getPropagated parameter to false effect the code. I've looked up the wiki parameter information but the information wasn't clear to me. Can you explain it to me? Link to comment
Jaysds1 Posted July 10, 2011 Share Posted July 10, 2011 The getPropagated is only if there wasn't any onClientGUIClick, if the player never had to click a button then this could be true but when he clicks it then it goes in to the function. For onClientGUIClick it's suppose to be false always. Link to comment
Cyanide Posted July 10, 2011 Author Share Posted July 10, 2011 Thanks, but also the real problem was the typo with outputChatBox, check the code and you'll notice it's incorrectly spelt. Silly me. Thanks for the help anyway. Link to comment
Castillo Posted July 10, 2011 Share Posted July 10, 2011 Thank you both for replies!@Solidsnake14 - Thanks, I noticed you used "root" instead of using a function on end addEventHandler ( "onClientGUIClick", root, onPlayerClickGUI ) Is there a difference if I called a function instead of simply putting "root"? @Jaysds1 - Thanks, just curious: How will changing the getPropagated parameter to false effect the code. I've looked up the wiki parameter information but the information wasn't clear to me. Can you explain it to me? I'd put a function, else it wouldn't work. P.S: Is better to have one function to handle your event handlers than a lot of them (my opinion). 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