OnPlayerLogin: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(12 intermediate revisions by 10 users not shown)
Line 5: Line 5:
==Parameters==
==Parameters==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
account thePreviousAccount, account theCurrentAccount, bool autoLogin
account thePreviousAccount, account theCurrentAccount
</syntaxhighlight>  
</syntaxhighlight>  


*'''thePreviousAccount''': The account the player was logged into before
*'''thePreviousAccount''': The [[account]] the player was logged into before.
*'''theCurrentAccount''': The account the player logged into just now
*'''theCurrentAccount''': The [[account]] the player logged into just now.
*'''autoLogin''': Whether this login was a result of an autologin


==Source==
==Source==
Line 21: Line 20:
This example just outputs to the player console that a player in one account logged into an another account:
This example just outputs to the player console that a player in one account logged into an another account:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- root = getElementRoot()
addEventHandler("onPlayerLogin", root,
addEventHandler("onPlayerLogin",root,
   function()
   function()
     outputChatBox(getPlayerName(source).." has logged in!", root)
     outputChatBox(getPlayerName(source).." has logged in!", root)
   end
   end
)
</syntaxhighlight>
This example allows only hardcoded serials to access given accounts.
<syntaxhighlight lang="lua">
Firewall =
{
--  [ 'accountName' ] = 'playerSerial',
    [ '3ash8' ] = '9C9F3B55D9D7BB7135FF274D3BF444E4',
    [ 'test5' ] = '1D6F76CF8D7193792D13789849498452',
}
addEventHandler ( 'onPlayerLogin', getRootElement ( ),
    function ( _, theCurrentAccount )
    local Serial = Firewall[getAccountName(theCurrentAccount)]
        if Serial and Serial ~= getPlayerSerial ( source ) then
            outputChatBox( "Sorry, you're not allowed to access this account.", source)
            cancelEvent( true )
        end
    end
)
)
</syntaxhighlight>
</syntaxhighlight>


{{See also/Server event|Player events}}
{{See also/Server event|Player events}}
[[ru:onPlayerLogin]]

Latest revision as of 17:02, 27 November 2021

This event is triggered when a player logs into their account in-game.

Parameters

account thePreviousAccount, account theCurrentAccount
  • thePreviousAccount: The account the player was logged into before.
  • theCurrentAccount: The account the player logged into just now.

Source

The source of this event is the player element that just logged in.

Cancel effect

If this event is canceled the player will not be logged in.

Example

This example just outputs to the player console that a player in one account logged into an another account:

addEventHandler("onPlayerLogin", root,
  function()
    outputChatBox(getPlayerName(source).." has logged in!", root)
  end
)

This example allows only hardcoded serials to access given accounts.

Firewall = 
{
--  [ 'accountName' ] = 'playerSerial',
    [ '3ash8' ] = '9C9F3B55D9D7BB7135FF274D3BF444E4',
    [ 'test5' ] = '1D6F76CF8D7193792D13789849498452',
}
 
addEventHandler ( 'onPlayerLogin', getRootElement ( ),
    function ( _, theCurrentAccount )
    local Serial = Firewall[getAccountName(theCurrentAccount)]
        if Serial and Serial ~= getPlayerSerial ( source ) then
            outputChatBox( "Sorry, you're not allowed to access this account.", source)
            cancelEvent( true )
        end
    end
)

See Also

Player events


Event functions