OnPlayerConnect: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Added version parameter)
Line 5: Line 5:
==Parameters==
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string playerNick, string playerIP, string playerUsername, string playerSerial
string playerNick, string playerIP, string playerUsername, string playerSerial, int playerVersion
</syntaxhighlight>  
</syntaxhighlight>  


Line 12: Line 12:
*'''playerUsername''': The player's community username.
*'''playerUsername''': The player's community username.
*'''playerSerial''': The player's serial number.
*'''playerSerial''': The player's serial number.
''Extra parameter from 1.0.2 onwards:''
*'''playerVersion''': The player's MTA version in pure numerical form, e.g. "256"


==Cancel effect==
==Cancel effect==
Line 22: Line 24:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--when a player connects
--when a player connects
function playerConnect (playerNick, playerIP, playerUsername, playerSerial)
function playerConnect (playerNick, playerIP, playerUsername, playerSerial, playerVersion)
     if playerNick == "Player" then --check if his nick is "Player"
     if playerNick == "Player" then --check if his nick is "Player"
         cancelEvent(true,"The nick \"Player\" is not allowed, please change it to something else. You can change your nick in Settings menu Multiplayer tab.") --in that case refuse the connection
         cancelEvent(true,"The nick \"Player\" is not allowed, please change it to something else. You can change your nick in Settings menu Multiplayer tab.") --in that case refuse the connection

Revision as of 04:38, 18 October 2009

This event is triggered when a player attempts to connect to the server.

Parameters

string playerNick, string playerIP, string playerUsername, string playerSerial, int playerVersion
  • playerNick: The player's current nickname.
  • playerIP: The player's current IP.
  • playerUsername: The player's community username.
  • playerSerial: The player's serial number.

Extra parameter from 1.0.2 onwards:

  • playerVersion: The player's MTA version in pure numerical form, e.g. "256"

Cancel effect

If this event is canceled, the player will be disconnected with an error message saying the reason specified in cancelEvent or "Disconnected: server refused the connection" if none was specified.

Example

This example cancels connection attempts of people who use the nick "Player" or outputs some data about the connecting player otherwise.

--when a player connects
function playerConnect (playerNick, playerIP, playerUsername, playerSerial, playerVersion)
    if playerNick == "Player" then --check if his nick is "Player"
        cancelEvent(true,"The nick \"Player\" is not allowed, please change it to something else. You can change your nick in Settings menu Multiplayer tab.") --in that case refuse the connection
    else
        --output some data about the player
        outputChatBox (playerNick.." just connected to the server.")
        outputChatBox ("IP: "..playerIP.." Username: "..playerUsername.." Serial: "..playerSerial)
    end
end

--add the playerConnect function as a handler for onPlayerConnect
addEventHandler ("onPlayerConnect", getRootElement(), playerConnect)

See Also

Player events


Event functions