#1

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(oldnamenewname)) 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:ohndFile: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(nhndfgetchar(ohndbuf2[0],false),false);
    }
    
fclose(ohnd);
    
fclose(nhnd);
    return 
true;

Reply
#2

Do you only parse the player name and not the file extension? If yes, it's probably that.
Reply
#3

Can you explain me that?? And how to fix it
Reply
#4

Do you do frename("Jamester", "James")? Or do you do (the correct way): frename("Jamester.ini", "James.ini"); I think atleast.
Reply
#5

Totally not understanding. Are you talking about command or what??

PS:Sorry for my stupidity
Reply
#6

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.
Reply
#7

Here you go
PHP код:
YCMD:specime(playeridparams[], 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]"oldnamenewname))
            {
                
SCM(playerid, -1""ORANGE"ES:RPG Pomoc | "BELA"/specime [Staro Ime] [Novo Ime]");
                return 
1;
            }
            new 
filestring2[128];
            
format(filestring2sizeof(filestring2), "/Korisnici/%s.ini"oldname);
            if(!
fexist(filestring2))
            {
                
SCM(playerid, -"Taj account ne postoji!");
                return 
1;
            }
            new 
filestring[128];
            
format(filestringsizeof(filestring), "/Korisnici/%s.ini"newname);
            if(
fexist(filestring))
            {
                
SCM(playerid,  -1"To novo ime vec neko koristi");
                return 
1;
            }
            
frename(filestring2filestring);
            new 
string[128];
            
format(stringsizeof(string), "Uspjesno ste promijenili ime %s-og accounta na %s" ,oldnamenewname);
            
SCM(playerid, -1string);
        }
        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
Reply
#8

You can do it easilier.
Let's take a example with explications.
PHP код:
if(sscanf(params,"us[25]"targetnName)) 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(PATHT50"/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(targetnName); 
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.
Reply
#9

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)