GetServerPassword: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Server function}}<!-- Change this to "Client function" or "Server function" appropriately--> <!-- Describe in plain english what this function does. Don't go into details, jus...)
 
(Undo revision 43282 by Glossy (talk))
 
(5 intermediate revisions by 3 users not shown)
Line 15: Line 15:


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example prints the serverpassword to the player
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--TODO
function viewPassword ( thePlayer, command )
mooo
  -- Put the password in a var
  local password = getServerPassword ()
 
  -- Check if the server has a password
  -- If the server has an password, echo it
  if password then
    outputChatBox ( "The server password is " .. password, thePlayer )
 
  -- Else print that there isnt any password
  else
    outputChatBox ( "The server doesn't have any password set", thePlayer )
  end
end
 
-- Add console command 'viewpassword'
addCommandHandler ( "viewpassword", viewPassword )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{Server functions}}
{{Server functions}}
[[Category:Needs_Example]] <!-- leave this until the example is completed. -->

Latest revision as of 14:46, 16 December 2014

This function returns the current password required to join the server.

Syntax

string getServerPassword ()

Returns

Returns the current server password as a string if it has a password, if not it returns nil.

Example

This example prints the serverpassword to the player

function viewPassword ( thePlayer, command )
  -- Put the password in a var
  local password = getServerPassword ()

  -- Check if the server has a password
  -- If the server has an password, echo it
  if password then
    outputChatBox ( "The server password is " .. password, thePlayer )
  
  -- Else print that there isnt any password
  else
    outputChatBox ( "The server doesn't have any password set", thePlayer )
  end
end

-- Add console command 'viewpassword'
addCommandHandler ( "viewpassword", viewPassword )

See Also