SA-MP Forums Archive
Changing a players name - 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: Changing a players name (/showthread.php?tid=647598)



Changing a players name - Uvais - 07.01.2018

I have a command that is used to set a players name based on YINI saving system :-

PHP код:
CMD:setname (playeridparams[])
            {
                new 
idname[25],str[120];
                if(
PInfo[playerid][Admin] < 7) return SendClientMessage(playeridRED,"[ERROR]: {FFFFFF}You do not have the privilleges to perform this command.");
                if(
sscanf(params"us[25]"idname)) return SendClientMessage(playeridTOMATO"[USAGE]: {FFFFFF}/setname [playerid/PartOfName] [name]");
                if(
strlen(name) < 3)return SendClientMessage(playeridCOLOR_RED"[ERROR]: {FFFFFF}The length of the name shouldn't be lower than 3!");
                if(
strlen(name) > MAX_PLAYER_NAME)return SendClientMessage(playeridCOLOR_RED"[ERROR]: {FFFFFF}The length of name exceeds the limit!");
                new 
file[64];
                
format(filesizeof(file), "/Users/%s.ini"name);
                if (
fexist(file)) return SendClientMessage(playeridCOLOR_RED"[ERROR]: {FFFFFF}That name is already registered in the database!");
                
fremove(UserPath(id));
                
SetPlayerName(id,name);
                
SaveStats(id);
                return 
1;
          } 
It works fine at first, i have tested relogging with it multiple times but when i turn off the server and then re start it, it shows a wrong password error according to my registration and login system. I would love any kind of help i can get about how it should be fixed.


Re: Changing a players name - jasperschellekens - 07.01.2018

You are deleting and saving the file again. Try ini_rename


Re: Changing a players name - Logic_ - 07.01.2018

Because you're doing it wrong. You will need to recreate the player file after you delete it (just like you do in the registration) and then save their stats! That's why we recommend SQL as the saving system, you don't need to struggle with any kind of bullshit, straight forward and easy.


Re: Changing a players name - jasperschellekens - 07.01.2018

Quote:
Originally Posted by Logic_
Посмотреть сообщение
Because you're doing it wrong. You will need to recreate the player file after you delete it (just like you do in the registration) and then save their stats! That's why we recommend SQL as the saving system, you don't need to struggle with any kind of bullshit, straight forward and easy.
if you would have taken a better look on his code, you would've noticed that he is doing that:
SaveStats(id);

Also be sure that SaveSats saves the stats for ID and not playerid


Re: Changing a players name - Uvais - 07.01.2018

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
if you would have taken a better look on his code, you would've noticed that he is doing that:
SaveStats(id);

Also be sure that SaveSats saves the stats for ID and not playerid
Yes, SaveStats is saving the id's stats. I have this stock though:

PHP код:
stock frename(oldname[],newname[]) {
                if (!
fexist(oldname)) return false;
                
fremove(newname);
                if (!
fcopy(oldname,newname)) return false;
                
fremove(oldname);
                return 
true;
            }