stock frename(oldname[], newname[])
{
if (!fexist(oldname)) return 0;
new File:oldfile = fopen(oldname, io_read);
new File:newfile = fopen(newname, io_write);
new line[256];
while (fread(oldfile, line))
{
fwrite(newfile, line);
}
fclose(oldfile);
fclose(newfile);
fremove(oldname);
return 1;
}
if (dialogid == DIALOG_CHANGENAME)
{
if (!response) return 1;
if (response)
{
new path[40], str[150];
if (isnull(inputtext)) return SendClientMessage(playerid, -1, "ERROR: You have not specified any new name.");
if (strlen(inputtext) < 3 || strlen(inputtext) > 24) return SendClientMessage(playerid, -1, "ERROR: new nick cannot be smaller than 3 or longer than 24 characters!");
format(path, sizeof(path), "ZeroAdmin/Accounts/%s.ini", inputtext);
if (fexist(path)) return SendClientMessage(playerid, -1, "ERROR:The name you have entered is already registered. Please enter a different name to proceed.");
else
frename(UserPath(playerid), path);
SetPlayerName(playerid, inputtext);
format(str, sizeof(str), "{F5CD1B}You have successfully changed your name to %s. Make sure you change your name on your SA-MP client.", inputtext);
SendClientMessage(playerid, -1, str);
return 1;
}
}
return 0;
}
stock UserPath(playerid)
{
new str[128], name[MAX_PLAYER_NAME], Path[126];
GetPlayerName(playerid, name, sizeof(name));
format(str, sizeof(str), Path, name);
return str;
}
new pName[MAX_PLAYER_NAME], str[50];
GetPlayerName(playerid, pName, sizeof pName);
format(str, sizeof str, "%s.ini", pName);
fremove(str);
// this is just an example. If you saved the info into "House" folder, you'd have to format the str in otherway:
format(str, sizeof str, "/Houses/%s.ini", pName);
fremove(str)
I have said for years that tying user files to names is a terrible idea (in fact, it used to be the case (and potentially still is) that doing so could crash a server, yet people still insist on doing it). If they weren't so directly tied, you wouldn't need to rename the file at all, just change an index somewhere.
|
Password = D49EB6B9A7D987E2387B414126340048BE446AAB586598513C D0890AAED5E1CF204C04FACBB83175D881A7477B4F7AE7D9D7 763AB96092AA37183F60F7B5C7D6 RegisteredDate = 22/1/2015 Ip = 127.0.0.1 Registered = 1 Banned = 0 Kills = 0 Level = 5 VipLevel = 3 Warnings = 0 LastOn = 29.1.2015 Hours = 2 Minutes = 6 Seconds = 12 Deaths = 7 Score = 200 Cash = 148999 TempVip = 1 FavSkin = 104 UseSkin = 1 |
Banned = 0 Kills = 0 Deaths = 7 Score = 200 Cash = 148999 Hours = 2 Minutes = 6 Seconds = 52 LastOn = 31.1.2015 |