Y_INI issue. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Y_INI issue. (
/showthread.php?tid=592392)
Y_INI issue. -
alexanderjb918 - 24.10.2015
Код:
CMD:changename(playerid,params[])
{
new oldname[128], newname[128], string[90];
if(sscanf(params,"s[128]s[128]", oldname, newname)) return SendClientMessage(playerid,COLOR_GREEN, "Correct Usage: /renameaccount [OldName][New name]");
new filestring[128];
new filestring2[128];
format(filestring2, sizeof(filestring2), "/Users/%s.ini", oldname);
if(!fexist(filestring2)) return SendClientMessage(playerid, COLOR_GREEN, "That account name doesn't exist!");
format(filestring, sizeof(filestring), "/Users/%s.ini", newname);
if(fexist(filestring)) return SendClientMessage(playerid, COLOR_GREEN, "The new name you've chosen is already taken");
frename(filestring2, filestring);
new INI:File = INI_Open(filestring);
INI_SetTag(File, "data");
INI_WriteString(File,"Name", newname);
INI_Close(File);
format(string, sizeof(string), "You have successfully renamed %s's account to %s" ,oldname, newname);
SendClientMessage(playerid, COLOR_GREEN, string);
return 1;
}
CMD works but it create a new user and I just want it to rename the account hes on now not keep this account and make a new one so you got to relog and then use the other one..
Re: Y_INI issue. -
Dusan01 - 24.10.2015
here u go:
PHP код:
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;
}
use it like this:
PHP код:
CMD:changename(playerid,params[])
{
new oldname[128], newname[128], string[90];
if(sscanf(params,"s[128]s[128]", oldname, newname)) return SendClientMessage(playerid,COLOR_GREEN, "Correct Usage: /renameaccount [OldName][New name]");
new filestring[128];
new filestring2[128];
format(filestring2, sizeof(filestring2), "/Users/%s.ini", oldname);
if(!fexist(filestring2)) return SendClientMessage(playerid, COLOR_GREEN, "That account name doesn't exist!");
format(filestring, sizeof(filestring), "/Users/%s.ini", newname);
if(fexist(filestring)) return SendClientMessage(playerid, COLOR_GREEN, "The new name you've chosen is already taken");
frename(oldname, newname);
format(string, sizeof(string), "You have successfully renamed %s's account to %s" ,oldname, newname);
SendClientMessage(playerid, COLOR_GREEN, string);
return 1;
}
Re : Y_INI issue. -
alexanderjb918 - 24.10.2015
Don't work now.. thanks for trying tho.
Re: Y_INI issue. -
Dusan01 - 24.10.2015
Ahh sorry bro my bad, try it like this:
PHP код:
CMD:changename(playerid,params[])
{
new oldname[128], newname[128], string[90];
if(sscanf(params,"s[128]s[128]", oldname, newname)) return SendClientMessage(playerid,COLOR_GREEN, "Correct Usage: /renameaccount [OldName][New name]");
new filestring[128];
new filestring2[128];
format(filestring2, sizeof(filestring2), "/Users/%s.ini", oldname);
if(!fexist(filestring2)) return SendClientMessage(playerid, COLOR_GREEN, "That account name doesn't exist!");
format(filestring, sizeof(filestring), "/Users/%s.ini", newname);
if(fexist(filestring)) return SendClientMessage(playerid, COLOR_GREEN, "The new name you've chosen is already taken");
frename(filestring2, filestring);
format(string, sizeof(string), "You have successfully renamed %s's account to %s" ,oldname, newname);
SendClientMessage(playerid, COLOR_GREEN, string);
return 1;
}
Re : Y_INI issue. -
alexanderjb918 - 24.10.2015
Il be testing shortly thanks.