SetAccountName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Socialz moved page SetAccountName to Useful Functions/SetAccountName: Added to MTA natively in https://buildinfo.mtasa.com/index.php?Revision=11747&Branch=master)
(Added to MTA natively in https://buildinfo.mtasa.com/index.php?Revision=11747)
Line 1: Line 1:
{{Useful Function}}
{{Useful Function}}
{{Delete|Added to MTA natively in r11747.}}
__NOTOC__
__NOTOC__
This function is used to change existing [[account]]s name.<br>
This function is used to change existing [[account]]s name.<br>
Line 64: Line 65:
==Author==
==Author==
Created By 3NAD.
Created By 3NAD.
<br>
==See Also==
{{Useful_Functions}}

Revision as of 22:21, 1 July 2018


Edit-delete.png This page is marked for deletion.

Reason: Added to MTA natively in r11747.
Actions: Delete (Administrators) - Discuss - What links here - Category


This function is used to change existing accounts name.

Syntax

bool setAccountName ( element player, string oldAccount, string newAccount )

Required Arguments

  • player: The player who called the function.
  • oldAccount: The account you want to change.
  • newAccount: The name you wanna to apply old account on it.

Returns

Returns true if account was successfully changed, false if the old account does not exist/ the new account exist.

Code

Click to collapse [-]
Server
setAccountName = function ( plr, old, new )
	if old and new then
		local oldAccount, newAccount, newPass = getAccount ( old ), getAccount ( new ), "mta"..math.random(10000,100000)
		if oldAccount and not newAccount then
			if addAccount ( new, newPass ) then
				local newAccount = getAccount ( new )
				local player = getAccountPlayer ( oldAccount )
				for index, value in pairs ( getAllAccountData ( oldAccount ) ) do
					setAccountData ( newAccount, index, value )
				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

Example

Click to collapse [-]
Server

This example will change account name.

addCommandHandler ( "chgAccName", function ( player, _, old, new )
	setAccountName ( player, old, new )
end )

Author

Created By 3NAD.