GetAccountName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Edited language change)
Tag: Manual revert
m (Added a new example, and fixed wide spaces.)
 
Line 18: Line 18:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function outputOnLogin ( previous_account, current_account, auto_login ) --when a player logs in
function outputOnLogin ( previous_account, current_account, auto_login ) --when a player logs in
outputConsole(getAccountName(previous_account).." Logged into "..getAccountName(current_account)) -- announce it into the console
    outputConsole(getAccountName(previous_account).." Logged into "..getAccountName(current_account)) -- announce it into the console
end
end
addEventHandler("onPlayerLogin",root,outputOnLogin ) --add an event handler
addEventHandler("onPlayerLogin",root,outputOnLogin ) --add an event handler
</syntaxhighlight>
This example shows the account you are logged into.
<syntaxhighlight lang="lua">
addCommandHandler("mylogin", function(source)
    local account = getPlayerAccount(source)
    if account and not isGuestAccount(account) then
        local accountName = getAccountName(account)
        outputChatBox("Your login is: "..accountName, source)
    else
        outputChatBox("You are not logged in!", source)
    end
end)
</syntaxhighlight>
</syntaxhighlight>



Latest revision as of 18:20, 23 December 2025

This function retrieves the name of an account.

Syntax

string getAccountName ( account theAccount )

OOP Syntax Help! I don't understand this!

Method: account:getName(...)
Variable: .name


Required Arguments

  • theAccount: The account you wish to get the name of.

Returns

Returns a string containing the account's name, false if the account does not exist or an invalid argument was passed to the function.

Example

This example announces into the console when a player logs into his account.

function outputOnLogin ( previous_account, current_account, auto_login ) --when a player logs in
    outputConsole(getAccountName(previous_account).." Logged into "..getAccountName(current_account)) -- announce it into the console
end
addEventHandler("onPlayerLogin",root,outputOnLogin ) --add an event handler

This example shows the account you are logged into.

addCommandHandler("mylogin", function(source)
    local account = getPlayerAccount(source)
    if account and not isGuestAccount(account) then
        local accountName = getAccountName(account)
        outputChatBox("Your login is: "..accountName, source)
    else
        outputChatBox("You are not logged in!", source)
    end
end)

See Also