SA-MP Forums Archive
Mysql Change Name HElp Pleaasee - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Mysql Change Name HElp Pleaasee (/showthread.php?tid=612473)



Mysql Change Name HElp Pleaasee - alishvasis - 18.07.2016

Hi Allll
I Use MySql Game Mode And Dont Have Change Name System I need deleted the old account and replaced it with the new one ANyone Can Help Me Pleaaase TnX


Re: Mysql Change Name HElp Pleaasee - Konstantinos - 18.07.2016

SQL is nothing like file systems that renaming a file requires to delete the current and create a new one. All you have to do is execute a query:
pawn Код:
// an example (in mysql_format):
"UPDATE users SET name='%e' WHERE name='%e' LIMIT 1", new_name, old_name
// or better yet "... WHERE ID=%i LIMIT 1" if you have a unique ID per-player.
Of course, you should check if the name is valid before updating the table.


Re: Mysql Change Name HElp Pleaasee - alishvasis - 18.07.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
SQL is nothing like file systems that renaming a file requires to delete the current and create a new one. All you have to do is execute a query:
pawn Код:
// an example (in mysql_format):
"UPDATE users SET name='%e' WHERE name='%e' LIMIT 1", new_name, old_name
// or better yet "... WHERE ID=%i LIMIT 1" if you have a unique ID per-player.
Of course, you should check if the name is valid before updating the table.
This Is My Ban System Please GIve Me CHange Name Systeem On /Changename I Realy Need It And I Cant MAke It TNX
Код HTML:
{
	if(!adminLevel(playerid, 4))
		return 0;
			
	new otherID, time, reason[26];
	if(sscanf(params, "uds[26]", otherID, time, reason))
	{
		Usage(playerid, "ban <playerid> <day> <reason>");
	}
	else
	{
		if(time < 1 || time > 30)
		{
			Server(playerid, "Please input between 1 - 30.");
			return 1;
		}
		
		if(isMe(playerid, otherID))
		{
			Server(playerid, "You can't use this command to yourself.");
			return 1;
		}
		
		if(!isConnected(otherID))
		{
			Server(playerid, "That player isn't logged in!");
			return 1;
		}
		
		if(isHigher(playerid, otherID))
		{
			Server(playerid, "You can't use this command to that player.");
			return 1;
		}
		
		time = time * 1440;
		ban(playerid, otherID, reason, time);
	}
	return 1;
}



Re: Mysql Change Name HElp Pleaasee - GangstaSunny - 18.07.2016

You dont need to delete the account. Use the mysql update function.

PHP код:
new query[128], oldname[MAX_PLAYER_NAME], newname[MAX_PLAYER_NAME];
GetPlayerName(playeridoldnamesizeof(oldname));
format(newname,sizeof(newname),"%s",inputtext);//Inputtext for example if you will create a dialog for this
SetPlayerName(playeridnewname);
format(query,sizeof(query),"UPDATE your_account_table_name SET your_name_field_name ='%s' WHERE Name = '%s'",newname,oldname);
mysql_query(query); 



Re: Mysql Change Name HElp Pleaasee - Konstantinos - 18.07.2016

If inputtext is empty, it will crash the server and you don't escape the strings.

Anyway, it is really simple. Modify the code to match the table's and columns' name as we can't possible guess your code and display a dialog with input style. On its response:
PHP код:
if (response)
{
    if (!
inputtext[0])
    {
        
SendClientMessage(playerid, -1"Error: Input a name.");
        
ShowPlayerDialog(...);
        return 
1;
    }

    new 
p_name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridp_nameMAX_PLAYER_NAME);

    switch (
SetPlayerName(playeridinputtext))
    {
        case 
1:
        {
            new 
Query[100];

            
mysql_format(connection_handle_hereQuerysizeof Query"UPDATE users SET name='%e' WHERE name='%e' LIMIT 1"inputtextp_name);
            
mysql_tquery(connection_handle_hereQuery"""");
            
SendClientMessage(playerid, -1"Name was changed successfully.");
        }
        case 
0SendClientMessage(playerid, -1"Error: Your currently name is the same.");
        case -
1SendClientMessage(playerid, -1"Error: The name cannot be changed (it's already in use, too long or has invalid characters).");
    }
    return 
1;

If you don't know about the dialogs, read: https://sampwiki.blast.hk/wiki/ShowPlayerDialog and https://sampwiki.blast.hk/wiki/OnDialogResponse

And don't expect a working code for just copy-paste, you SHOULD try an attempt yourself.


Re: Mysql Change Name HElp Pleaasee - alishvasis - 18.07.2016

Not Work Brother


Re: Mysql Change Name HElp Pleaasee - alishvasis - 18.07.2016

|Please Give Me /Changename Command For Mysql Please So TnX