04.09.2011, 16:13
pawn Код:
dcmd_changename(playerid,params[])
{
if(Spieler[playerid][AdminLevel] > 2)
{
new pID,pname[24],newname[24];
if(sscanf(params, "ds[24]",pID,newname))return SendClientMessage(playerid,0xFF0000FF,"Usage: /changename [ID][New Name]");
if(pID == INVALID_PLAYER_ID)return SendClientMessage(playerid,0xFF0000FF,"This PlayerId is invalid!");
GetPlayerName(pID,pname,24);
new query1[256],escapename[24];
mysql_real_escape_string(newname, escapename);
format(query1, sizeof(query1), "SELECT `name` FROM `Users` WHERE `name` = '%s' LIMIT 1", escapename);
mysql_query(query1);
mysql_store_result();
new rows = mysql_num_rows();
if(!rows)
{
new query[256];
format(query, sizeof(query), "UPDATE `Users` SET `name`= '%s' WHERE `name` ='%s'",escapename,pname);
mysql_query(query);
SetPlayerName(pID,escapename);
new levelsetter[MAX_PLAYER_NAME],adminstring[128];
GetPlayerName(playerid,levelsetter,sizeof(levelsetter));
format(adminstring,sizeof(adminstring),"Admin * %s * has changed your name to %s!",levelsetter, newname);
SendClientMessage(pID,0xFF0000FF, adminstring);
SendClientMessage(playerid, 0xFF0000FF, "You have changed the name successfully.");
}
else if(rows == 1)
{
SendClientMessage(playerid, 0xFF0000FF, "This name already exists!");
}
mysql_free_result();
}
else return SendClientMessage(playerid, 0xFF0000FF, "You don't have permission to use this command!");
return 1;
}
(Fixed your indention as well^^)
Jeffry
