DarkLink Posted January 24, 2008 Share Posted January 24, 2008 Hi guys again! ^^ I did like to know how i can put a function to players, need to register to spawn.. I mean, to play in the server they need to register.. I see this script: function registerPlayer ( source, commandName, password ) -- Check if the password field is blank or not (only blank if they didnt enter one) if ( password ~= "" and password ~= nil ) then --Attempt to add the account, and save its value in a var local accountAdded = addAccount( getClientName(source), password ) if ( accountAdded ) then -- Tell the user all is done outputChatBox ( "Thank you " .. getClientName(source) .. ", you're now registed, you can login with /login", source ) else -- There was an error making the account, tell the user outputChatBox ( "Error creating account, contact the server admin", source ) end else -- There was an error in the syntax, tell the user the correct syntax. outputChatBox ( "Error creating account, correct syntax: /register <password>", source ) end end addCommandHandler ( "register", registerPlayer ) -- add the command handler This is for players register in the server, but i want to make a obligator register, so they need to register to play.. How i do that..? Please help.. Link to comment
50p Posted January 24, 2008 Share Posted January 24, 2008 Use getAccount function. local account = getAccount( getClientName(source) ) if account then -- if account exists then send player a message to login else -- otherwise tell the user to register to play end Link to comment
DarkLink Posted January 24, 2008 Author Share Posted January 24, 2008 Thaaank you very much again!! 50p! Thank you! Link to comment
DarkLink Posted January 25, 2008 Author Share Posted January 25, 2008 Are you sure, that script is right..? =/ I try it, and give me a error on the black screen (server) Then i try like this.. local account = getAccount( getClientName(source) ) if account then outputChatBox ( "login", source) else outputChatBox ( "register", source) end But still appear some bugs and warnings in the black screen of the server... Hmmm can you help..?? =/ Thank you.. Link to comment
mabako Posted January 25, 2008 Share Posted January 25, 2008 you should use getAccount( source ) Link to comment
DarkLink Posted January 25, 2008 Author Share Posted January 25, 2008 you should use getAccount( source ) Like this? local account = getAccount( getAccount (source) ) if account then outputChatBox ( "Login", source) else outputChatBox ( "Register", source) end I try that...still give me some error... Thank you...and can you help me again..? =/ Link to comment
50p Posted January 25, 2008 Share Posted January 25, 2008 mabako meant to use 'getAccount( source )' instead of 'getAccount( getClientName( source ) )' But params shown on wiki says: account getAccount ( string username, [ string password ] ) string is string string is not userdata So username should be a string not an element. Link to comment
DarkLink Posted January 25, 2008 Author Share Posted January 25, 2008 mabako meant to use 'getAccount( source )' instead of 'getAccount( getClientName( source ) )'But params shown on wiki says: account getAccount ( string username, [ string password ] ) string is string string is not userdata So username should be a string not an element. Ok i will try that! Thanks for the help! By the way...what you mean it.. "string is string string is not userdata So username should be a string not an element." I am a bit noobish in lua.. Thank you.. Link to comment
DarkLink Posted January 25, 2008 Author Share Posted January 25, 2008 I try like.. local account = getAccount( source ) if account then outputChatBox ( "Login", source) else outputChatBox ( "Register", source) end And is still getting me an error... =/ I cant understand...what is wrong... =/ Thank you.. Link to comment
50p Posted January 25, 2008 Share Posted January 25, 2008 These are types of variables. I meant that if parameter on wiki says that there should be a "string" (representing name of account) there should be string. So I wrote that: string (param of the function) must be string ("blah blah") string (param of the function) cannot be userdata (source, which represents player is a userdata type of variable) EDIT: I have just tested this short script and it seems there must be an error in getAccount function... I get the same message as you have shown above on the screenshot of console. Assertion failed: szName, file .\logic\CStaticFunctionDefinitions.cpp, line 6365This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Link to comment
DarkLink Posted January 25, 2008 Author Share Posted January 25, 2008 Hmmm see... So the problem is the console.. =/ What can we do now? Call the application's support team ? Well i dont know.. Link to comment
mabako Posted January 25, 2008 Share Posted January 25, 2008 I'm sorry, I meant getClientAccount local account = getClientAccount( source ) And that is a difference, because i can login as FUBAR (/login FUBAR password), but that's not the account named [NB]mabako I use then Link to comment
DarkLink Posted January 25, 2008 Author Share Posted January 25, 2008 OMG! This is Unbelievable... I try the local account = getClientAccount( source ) you said.. Then try local account = getAccountClient( source )... And i get the same error like : Warning: registar.lua: Bad Argument @ ' getClientAccount 1 - line: 3 LOOL...i cant get it.. Link to comment
50p Posted January 26, 2008 Share Posted January 26, 2008 If you do this in onPlayerJoin, then try to add a param to your function (the one which check whether account exists) and use this param instead of 'source'. The parameter would represent 'source', so the event would pass the source as a parameter to the function. I had similar message with bindKey, when I didn't use a param in the function. I hope you know what I mean. Link to comment
DarkLink Posted January 26, 2008 Author Share Posted January 26, 2008 Hmmm ok! I am a bit noob, but i think i got it ^^ You said me to use this: -- we register greetPlayer as a handler for the event function greetPlayer ( ) -- we store the player's name local joinedPlayerName = getClientName ( source ) -- and send him a greeting outputChatBox ( "Welcome " .. joinedPlayerName .. " to the server!" , source, 255, 255, 255 ) end addEventHandler ( "onPlayerJoin", getRootElement(), greetPlayer ) And in source "local joinedPlayerName = getClientName ( source )" i should use the param to check if the account exists or not..right? I think is that...you meant.. Or not..? Thank you again for all 50p! Link to comment
50p Posted January 26, 2008 Share Posted January 26, 2008 I said add a parameter to a function which gets called when a player connects, so in this case greetPlayer function greetPlayer ( player ) -- <== look here, this replaces 'source' to 'player' local joinedPlayerName = getClientName ( player ) outputChatBox ( "Welcome " .. joinedPlayerName .. " to the server!" , player, 255, 255, 255 ) if getClientAccount( player ) then outputChatBox( "Login...", player, 0, 255, 0 ) else outputChatBox( "You must register to play!", player, 255, 0, 0) end end addEventHandler ( "onPlayerJoin", getRootElement(), greetPlayer ) It helps sometime to add a parameter to the function, so you wouldn't see the "Bad argument" warning. Because I used a function which gave me the warning, why? I used 'source'! I don't know, but when I added a param it fixed the prob. 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