ZH-CN/SetAccountName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Server function}} __NOTOC__ {{New feature/item|3.0155|1.5.5|11747| This function sets the name of an account. }} ==Syntax== <syntaxhighlight lang="lua"> bool setAccoun...")
 
No edit summary
Line 2: Line 2:
__NOTOC__
__NOTOC__
{{New feature/item|3.0155|1.5.5|11747|
{{New feature/item|3.0155|1.5.5|11747|
This function sets the name of an [[account]].
此函数用于设置[[帐户]]的名称.
}}
}}


==Syntax==  
==语法==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool setAccountName ( account theAccount, string name [, bool allowCaseVariations = false] )
bool setAccountName ( account theAccount, string name [, bool allowCaseVariations = false] )
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[account]]:setName|name|getAccountName}}
{{OOP_ZH-CN||[[account]]:setName|name|getAccountName}}
===Required Arguments===  
===必填参数===  
*'''theAccount:''' The account you wish to change the name.
*'''theAccount:''' 您要更改名称的帐户.
*'''name:''' The new name.
*'''name:''' 新的账户名.


===Optional Arguments===
===选填参数===
*'''allowCaseVariations:''' Whether the username is case sensitive (if this is set to true, usernames "Bob" and "bob" will refer to different accounts)
*'''allowCaseVariations:''' 用户名是否区分大小写(如果设置为true,则用户名“Bob”和“bob”将引用不同的帐户)


===Returns===
===Returns===
Returns a ''true'' if the account name was set, ''false'' if an invalid argument was specified.
如果设置了帐户名,则返回“true”;如果指定了无效参数,则返回“false”.


==Example==  
==示例==  
Change the name of an account.
更改帐户名称.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler("changeaccountname", function(player, _, oldname, newname)
addCommandHandler("changeaccountname", function(player, _, oldname, newname)

Revision as of 09:11, 4 February 2021

此函数用于设置帐户的名称.

语法

bool setAccountName ( account theAccount, string name [, bool allowCaseVariations = false] )

OOP 语法 什么是OOP?

方法: account:setName(...)
变量: .name
对称函数: getAccountName

必填参数

  • theAccount: 您要更改名称的帐户.
  • name: 新的账户名.

选填参数

  • allowCaseVariations: 用户名是否区分大小写(如果设置为true,则用户名“Bob”和“bob”将引用不同的帐户)

Returns

如果设置了帐户名,则返回“true”;如果指定了无效参数,则返回“false”.

示例

更改帐户名称.

addCommandHandler("changeaccountname", function(player, _, oldname, newname)
    if not oldname or not newname then
        return
    end
    local account = getAccount(oldname)
    if not account then
        return 
    end
    setAccountName(account, newname)
end)

See Also