Jump to content

gui displays at the wrong time


Grievous

Recommended Posts

Hi,

I have a spawn window that shows itself to all players when new players connect. It doesn't happen everytime. I heard the answer was server side. Has anyone had this problem before? Any idea would be most welcome. I'm stuck and its very annoying.

Thanks

Link to comment

I'm not sure what data I should be passing to the client. I'm trying to make the spawn window to show only to theplayer when theplayer joins. I think I need add support to show the spawn window only to theplayer when theplayer is dead.

I have this server side

function onJoin() 
    outputChatBox ( "welcome message.", source ) 
    triggerClientEvent ( thePlayer, "onGreeting", getRootElement()---what goes here?---) 
  
end 
  
addEventHandler ( "onPlayerJoin", getRootElement(), onJoin ) 
  

and this client side

  
function greetingHandler ( message ) 
  
    outputChatBox ( "The server says: " .. message ) 
end 
addEvent( "onClientPlayerJoin", true ) 
addEvent( "onGreeting", true ) 
  
  
addEventHandler( "onClientPlayerJoin", getRootElement(), greetingHandler ) 
addEventHandler( "onGreeting", getRootElement(), greetingHandler ) 
  

I get an error.

Bad argument on triggerclient event. A nil value. I'm not sure what this should be.

Thanks for your help people. I wasn't sure what the problem was until I read the replys. Then I used the wiki to make this code. Some of this lua is almost beging to make sense. I still know very little though.

Link to comment

in the function onJoin, the triggerClientEvent uses thePlayer, which is a nil value. You should use source there instead, since you haven't defined thePlayer anywhere. Also currently you comment out the triggerClientEvent ending bracket ;) and there would go whatever the arguments you want to pass to the clientside function

Link to comment

@Grievous

Do not use triggerClientEvent in onPlayerJoin event! When you do, it will try to triggerClientEvent but player has to download the files before you can trigger client events, so that will result with error message and no window showing up for the new player. Use onClientResourceStart - this event is triggered when resource starts for client, that is when played will have all the files it will be triggered for him.

Link to comment

I made some changes to the client side.

function greetingHandler ( message ) 
  
    outputChatBox ( "The server says: " .. message ) 
end 
addEvent( "OnClientResourceStart", true ) 
addEvent( "onGreeting", true ) 
  
  
addEventHandler( "OnClientResourceStart", getRootElement(), greetingHandler ) 
addEventHandler( "onGreeting", getRootElement(), greetingHandler ) 
  

I'm not sure how to call this from the server side. Or do I even need to? This is what I have for server side.

function onJoin() 
    outputChatBox ( "Welcome") 
    triggerClientEvent ( source, "onGreeting", getRootElement())-----"what event can I use here to start the client script?" 
  
end 
addEventHandler ( "onResourceStart", getRootElement(),onJoin ) 
addEventHandler ( "onPlayerJoin", getRootElement(), onJoin ) 
  
  

I will study the wiki and try to come up with something , Please help.

Edited by Guest
Link to comment

From what I see, it will be very hard for you to understand all this scripting but if you really really want to learn, you need to focus on Lua syntax first. As you can see you code here has lots of red colour, look at the function names (starting from triggerClientEvent), they are all red because you didn't finish your string with " (quotation mark). You must get errors in the console, I'm sure of this.

A question, why do you add new OnClientResourceStart event?

Here are some links for you to learn from:

- http://www.lua.org/manual/5.1/

- http://www.lua.org/pil/index.html

- http://lua-users.org/wiki/ (you may not need this one really)

- http://development.mtasa.com/index.php? ... troduction

Link to comment

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