SA-MP Forums Archive
Help? - 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: Help? (/showthread.php?tid=609107)



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(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;




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(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


Re: Help? - Dayrion - 09.06.2016

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.


Re: Help? - Micko123 - 09.06.2016

Thanks