Help? -
Micko123 - 08.06.2016
So i made this /rename command. It works good but i have one problem. It changes player's name and put it in file where other users are. Problem is it won't delete old account. How can i fix this??
This is my stock frename
PHP код:
stock frename(oldname[], newname[])
{
if(!fexist(oldname)) return false;
fremove(newname);
if(!fcopy(oldname, newname)) return false;
fremove(oldname);
return 1;
}
I don't see problem here, or it is maybe somewhere else\
EDIT: This is stock fcopy
PHP код:
stock fcopy(oldname[], newname[])
{
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;
}
Re: Help? -
J0sh... - 08.06.2016
Do you only parse the player name and not the file extension? If yes, it's probably that.
Re: Help? -
Micko123 - 08.06.2016
Can you explain me that?? And how to fix it
Re: Help? -
J0sh... - 08.06.2016
Do you do frename("Jamester", "James")? Or do you do (the correct way): frename("Jamester.ini", "James.ini"); I think atleast.
Re: Help? -
Micko123 - 08.06.2016
Totally not understanding. Are you talking about command or what??
PS:Sorry for my stupidity
Re: Help? -
J0sh... - 08.06.2016
I'm talking about when you call the function. If you only pass the player name it wouldn't work. So yes, probably the admin command, show me what you call.
Re: Help? -
Micko123 - 08.06.2016
Here you go
PHP код:
YCMD:specime(playerid, params[], help)
{
#pragma unused help
if(PlayerInfo[playerid][pAdmin] >= 6)
{
if(AdminDuty[playerid] == 0)
{
new oldname[24], newname[24];
if(sscanf(params,"s[24]s[24]", oldname, newname))
{
SCM(playerid, -1, ""ORANGE"ES:RPG Pomoc | "BELA"/specime [Staro Ime] [Novo Ime]");
return 1;
}
new filestring2[128];
format(filestring2, sizeof(filestring2), "/Korisnici/%s.ini", oldname);
if(!fexist(filestring2))
{
SCM(playerid, -1 , "Taj account ne postoji!");
return 1;
}
new filestring[128];
format(filestring, sizeof(filestring), "/Korisnici/%s.ini", newname);
if(fexist(filestring))
{
SCM(playerid, -1, "To novo ime vec neko koristi");
return 1;
}
frename(filestring2, filestring);
new string[128];
format(string, sizeof(string), "Uspjesno ste promijenili ime %s-og accounta na %s" ,oldname, newname);
SCM(playerid, -1, string);
}
else
{
SCM(playerid,-1,""CRVENA"[ES:RPG] "SIVA"Morate biti na duznosti!");
return 1;
}
}
else
{
SCM(playerid,-1,""CRVENA"[ES:RPG] "SIVA"Samo Vlasnik!");
return 1;
}
return 1;
}
If you want i can translate it to english
Re: Help? -
Dayrion - 09.06.2016
You can do it easilier.
Let's take a example with explications.
PHP код:
if(sscanf(params,"us[25]", target, nName)) return SendClientMessage(playerid, -1, "/name [id_joueur] [new_name]");
Then do some verefications like
PHP код:
if(!IsPlayerConnected(target)) return SendClientMessage(playerid, -1, "This player is not connected.");
format(PATHT, 50, "/Players/%s.ini", nName);
if(fexist(PATHT)) return SendClientMessage(playerid, -1, "Name already taken");
Remove the old file and attribute the new name.
PHP код:
fremove(UserPath(target));
SetPlayerName(target, nName);
Put new parameters like a new player who is regestering on your server.
PHP код:
new INI:File = INI_Open(UserPath(target));
INI_WriteInt(File,"MDP", PlayerInfo[target][pMDP]);
INI_WriteInt(File,"Admin", PlayerInfo[target][pAdminlvl]);
INI_WriteInt(File,"Cash", PlayerInfo[target][pCash]);
INI_WriteInt(File,"Score", PlayerInfo[target][pScore]);
INI_Close(File);
Dont copy/paste this code. He comes from my gamemode (my /name commands) and may not work on yours because I didn't put the whole code.
Re: Help? -
Micko123 - 09.06.2016
Thanks