PDA

View Full Version : /changename command not finished


Sibuscus
14/03/2017, 09:15 PM
So, I made this command with the help of some outdated tutorial, but the problem is that it doesn't delete the old file and also you can still log in the old file (Admin level doesn't change either. The old file has admin 5, but the new file doesn't get the admin value). When you log in with the old file, you are still an admin. The old file should delete.

stock frename(oldname[],newname[])// Renaming the player and file name
{
if (!fexist(oldname)) return false;
fremove(newname);
if (!fcopy(oldname,newname)) return false;
fremove(oldname);
return true;
}

stock fcopy(oldname[],newname[])// Making a new file to copy from old files
{
new File:ohnd,File:nhnd;
if (!fexist(oldname)) return false;
ohnd=fopen(oldname,io_read);
nhnd=fopen(newname,io_write);
new buf2[1];
new i;
for (i=flength(ohnd);i>0;i--) {
fputchar(nhnd, fgetchar(ohnd, buf2[0],false),false);
}
fclose(ohnd);
fclose(nhnd);
return true;
}

stock fdelete(oldname[])
{
fremove(oldname);
}

These are some stocks. My registration system is made according to Kush's tutorial.

CMD:renameplayer(playerid, params[])
{
if(PlayerInfo[playerid][pAdmin] > 4)
{
new oldname[24], newname[24], AdminName[MAX_PLAYER_NAME];
new filestring[128];
new filestring2[128];
new string[128];
GetPlayerRPName(playerid, AdminName, sizeof(AdminName));
if(sscanf(params,"s[24]s[24]", oldname, newname)) return SendClientMessage(playerid, COLOR_DARKCORAL, "[BS] {AFAFAF}USAGE: /renameplayer [OLD name] [NEW name] ");
format(filestring2, sizeof(filestring2), "/Users/%s.ini", oldname);
if(!fexist(filestring2)) return SendClientMessage(playerid, COLOR_DARKCORAL, "[BS] {AFAFAF}ERROR: That player was not found.");
format(filestring, sizeof(filestring), "/Users/%s.ini", newname);
if(fexist(filestring)) return SendClientMessage(playerid, COLOR_DARKCORAL, "[BS] {AFAFAF}ERROR: That name is already taken.");
frename(filestring2, filestring);
fdelete(filestring2);
format(string, sizeof(string), "[BS] {FFFF00}You have successfully renamed %s's account to %s" ,oldname, newname);
SendClientMessage(playerid, COLOR_DARKCORAL, string);
format(string, sizeof(string), "[BS] {FFFF00}Your name was changed to %s. Please relog." ,oldname, newname);
SendClientMessage(playerid, COLOR_DARKCORAL, string);
format(string, sizeof(string), "[%d] [/renameplayer] %s has renamed %s's account to %s" , ReturnDate(), AdminName, oldname, newname);
AdminCmdLog(string);
}
else
{
SendClientMessage(playerid, COLOR_DARKCORAL, "[BS] {AFAFAF}You cannot use this command!");
}

return 1;
}

I mean, is the problem in the stocks or what? Maybe the SetPlayerName(); command is better?