SetAccountName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Added to MTA natively in https://buildinfo.mtasa.com/index.php?Revision=11747)
m (Обновление информации)
 
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Useful Function}}
{{Server function}}
{{Delete|Added to MTA natively in r11747.}}
__NOTOC__
__NOTOC__
This function is used to change existing [[account]]s name.<br>
{{New feature/item|3.155|1.5.5|11747|
This function sets the name of an [[account]].
}}


==Syntax==
==Syntax==  
<syntaxhighlight lang="lua">bool setAccountName ( element player, string oldAccount, string newAccount )</syntaxhighlight>
<syntaxhighlight lang="lua">
bool setAccountName ( account theAccount, string name [, bool allowCaseVariations = false] )
</syntaxhighlight>  
{{OOP||[[account]]:setName|name|getAccountName}}
===Required Arguments===
*'''theAccount:''' The account you wish to change the name.
*'''name:''' The new name.


===Required Arguments===
===Optional Arguments===
* '''player''': The player who called the function.
*'''allowCaseVariations:''' Whether the username is case sensitive (if this is set to true, usernames "Bob" and "bob" will refer to different accounts)
* '''oldAccount''': The account you want to change.
* '''newAccount''': The name you wanna to apply old account on it.


===Returns===
===Returns===
Returns ''true'' if account was successfully changed, ''false'' if the old account does not exist/ the new account exist.
Returns a ''true'' if the account name was set, ''false'' if an invalid argument was specified.


==Code==
==Example==  
<section name="Server" class="server" show="true">
Change the name of an account.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
setAccountName = function ( plr, old, new )
addCommandHandler("changeaccountname", function(player, _, oldname, newname)
if old and new then
    if not oldname or not newname then
local oldAccount, newAccount, newPass = getAccount ( old ), getAccount ( new ), "mta"..math.random(10000,100000)
        return
if oldAccount and not newAccount then
    end
if addAccount ( new, newPass ) then
    local account = getAccount(oldname)
local newAccount = getAccount ( new )
    if not account then
local player = getAccountPlayer ( oldAccount )
        return
for index, value in pairs ( getAllAccountData ( oldAccount ) ) do
    end
setAccountData ( newAccount, index, value )
    setAccountName(account, newname)
end
end)
for index, value in ipairs ( aclGroupList ( ) ) do
if isObjectInACLGroup ( "user."..old, value ) then
aclGroupAddObject ( value, "user."..new )
aclGroupRemoveObject ( value, "user."..old )
end
end
if player then
logOut ( player )
logIn ( player, newAccount, newPass )
if plr == player then
outputChatBox ( "* Your new account and password: [ "..new.." ] [ "..newPass.." ].", player, 255, 255, 0, true )
else
outputChatBox ( "* Your new account and password: [ "..new.." ] [ "..newPass.." ].", player, 255, 255, 0, true )
outputChatBox ( "* New account and password: [ "..new.." ] [ "..newPass.." ].", plr, 255, 255, 0, true )
end
else
outputChatBox ( "* New account and password: [ "..new.." ] [ "..newPass.." ].", plr, 255, 255, 0, true )
end
setTimer ( removeAccount, 100, 1, oldAccount )
return true
end
end
end
return false
end
</syntaxhighlight>
</syntaxhighlight>
</section>
==Example==
<section name="Server" class="server" show="true">
This example will change account name.
<syntaxhighlight lang="lua">addCommandHandler ( "chgAccName", function ( player, _, old, new )
setAccountName ( player, old, new )
end )</syntaxhighlight></section>


==Author==
==See Also==
Created By 3NAD.
{{Account_functions}}
[[en:SetAccountName]]
[[ru:setAccountName]]
[[zh-cn:SetAccountName]]

Latest revision as of 17:12, 12 April 2021

ADDED/UPDATED IN VERSION 1.5.5 r11747:

This function sets the name of an account.

Syntax

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

OOP Syntax Help! I don't understand this!

Method: account:setName(...)
Variable: .name
Counterpart: getAccountName


Required Arguments

  • theAccount: The account you wish to change the name.
  • name: The new 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)

Returns

Returns a true if the account name was set, false if an invalid argument was specified.

Example

Change the name of an account.

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