12.12.2013, 21:47
My aim is to make a command for admins that can change any name in the database to desired. It doesn't return anything when processed.
pawn Код:
CMD:changepname(playerid,params[])
{
new query1[256],firstname[24],secondname[24],escapename[24],escapename2[24];
if(pInfo[playerid][AdminLevel] <= 3) return 0;
if(sscanf(params, "s[24]s[24]",firstname,secondname)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /changepname [first_name] [second_name]");
mysql_real_escape_string(firstname, escapename);
mysql_real_escape_string(secondname, escapename2);
format(query, sizeof(query), "SELECT `username` FROM `users` WHERE `username` = '%s'", escapename);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
if(rows)
{
format(query1,sizeof(query1),"SELECT `username` FROM `users` WHERE `username` = '%s'",escapename2);
mysql_query(query);
mysql_store_result();
new rows2 = mysql_num_rows();
if(!rows2)
{
format(query, sizeof(query), "UPDATE `users` SET `username` = '%s' WHERE `username` ='%s'",escapename2,escapename);
mysql_query(query);
format(string,sizeof(string),"An admin has changed %s's account name to %s",firstname,secondname);
format(query,sizeof(query),"UPDATE `timeline` SET `name` = '%s' WHERE `name` = '%s'",escapename,pName(playerid));
SendClientMessageToAll(COLOR_YELLOW,string);
}
}
else if(rows == 1)
{
SendClientMessage(playerid,COLOR_GREY,"No such username found!");
}
mysql_free_result();
return 1;
}