// 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.
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 Код:
|
{ 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; }
new query[128], oldname[MAX_PLAYER_NAME], newname[MAX_PLAYER_NAME];
GetPlayerName(playerid, oldname, sizeof(oldname));
format(newname,sizeof(newname),"%s",inputtext);//Inputtext for example if you will create a dialog for this
SetPlayerName(playerid, newname);
format(query,sizeof(query),"UPDATE your_account_table_name SET your_name_field_name ='%s' WHERE Name = '%s'",newname,oldname);
mysql_query(query);
if (response)
{
if (!inputtext[0])
{
SendClientMessage(playerid, -1, "Error: Input a name.");
ShowPlayerDialog(...);
return 1;
}
new p_name[MAX_PLAYER_NAME];
GetPlayerName(playerid, p_name, MAX_PLAYER_NAME);
switch (SetPlayerName(playerid, inputtext))
{
case 1:
{
new Query[100];
mysql_format(connection_handle_here, Query, sizeof Query, "UPDATE users SET name='%e' WHERE name='%e' LIMIT 1", inputtext, p_name);
mysql_tquery(connection_handle_here, Query, "", "");
SendClientMessage(playerid, -1, "Name was changed successfully.");
}
case 0: SendClientMessage(playerid, -1, "Error: Your currently name is the same.");
case -1: SendClientMessage(playerid, -1, "Error: The name cannot be changed (it's already in use, too long or has invalid characters).");
}
return 1;
}