Jump to content

onClientGUIClick isn't being called.


Cyanide

Recommended Posts

Posted

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 ) 

Posted

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.

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

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 ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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?

Posted

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.

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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