Jump to content

GUI trigger server events


TimJ

Recommended Posts

Posted

Im confused with GUI triggering server events :(

I tried a couple of times, i tried to use the wiki to help,

What i got was:

Server:

function greetingHandler ( message ) 
  
    outputChatBox ( "lalala:", source ) 
end 
addEvent( "onGreeting", true ) 
  
  
addEventHandler( "onGreeting", getRootElement(), greetingHandler ) 

Client:

button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Test", true ) 
  
function spawner ( commandName ) 
  
    triggerServerEvent ( "onGreeting", getLocalPlayer(), " wowow" )  
     
end 
  
  
addEventHandler ( "onClientGUIClick", button, spawner ) 

Help would be very kindly appreciated :)

Posted

I don't see anything wrong in the code after a quick look, more info would be nice. What exactly is the problem? Error messages, etc.

Posted

i just added a command handler to the spawner function... which worked :S which means ive done something wrong with the button i guess...

Posted

Ah, I think I know it. Add an event handler for onClientResourceStart and put the function that creates a button inside it.

Posted

i thought about that then thought it might just trigger the event on the client resource start, so i just tried it and it made no difference just triggered the event on resource start :(

Posted
i thought about that then thought it might just trigger the event on the client resource start, so i just tried it and it made no difference just triggered the event on resource start :(

How did you do that?

-- SERVER -- 
function greetingHandler ( message ) 
    outputChatBox ( message, source ); 
end 
addEvent( "onGreeting", true ); 
addEventHandler( "onGreeting", getRootElement(), greetingHandler ); 
  
  
  
-- CLIENT -- 
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), 
    function ( ) 
        button = guiCreateButton( 0.7, 0.1, 0.2, 0.1, "Test", true ); 
        addEventHandler( "onClientGUIClick", button, spawner, false ); 
    end 
) 
function spawner (  ) 
    triggerServerEvent ( "onGreeting", getLocalPlayer(), " wowow" ) 
end 

Posted

Im trying to make the cursor show but it wont and im getting:

 Bad argument @ 'showCursor'  

in the console.

im typing:

showCursor(source, true) 

help :(

EDIT: Scrap That- Fixed :D

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