changename bugs
#1

Hey, I'm pretty new on scripting and I've some questions about a recent command I've made with yini.

I've tried to make a /changename cmd but I can't get rid of the old files of the player and the public message to all doesn't shows the "old name" like (" has changed his name to "new name"!).
Код:
CMD:changename(playerid,params[])
{
    new oldname[128], newname[128], string[90];
    if(sscanf(params,"s[128]", newname)) return SendClientMessage(playerid,COLOR_LIGHTBLUE, "Usage: /Changename [new name]");
    new filestring[128];
    new filestring2[128];
    format(filestring2, sizeof(filestring2), "/Users/%s.ini", oldname);
    format(filestring, sizeof(filestring), "/Users/%s.ini", newname);
    if(fexist(filestring)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: The new name you've chosen is already taken");
    format(string, sizeof(string), "%s has changed his name to %s!" ,oldname, newname);
    SetPlayerName(playerid, newname);
    SendClientMessageToAll(COLOR_WHITE, string);
    frename(filestring2, filestring);
    new INI:File = INI_Open(filestring);
    INI_SetTag(File, "data");
    new str[50];
    format(str, sizeof str, "/Users/%s.ini", oldname);
    INI_RemoveEntry(File,str);
    INI_Close(File);
    return 1;
}
If some experienced guy can help me I will be thankful with a rep!
Regards, rakinz.
Reply
#2

Quote:
Originally Posted by rakinz
Посмотреть сообщение
Hey, I'm pretty new on scripting and I've some questions about a recent command I've made with yini.

I've tried to make a /changename cmd but I can't get rid of the old files of the player and the public message to all doesn't shows the "old name" like (" has changed his name to "new name"!).
Код:
CMD:changename(playerid,params[])
{
    new oldname[128], newname[128], string[90];
    if(sscanf(params,"s[128]", newname)) return SendClientMessage(playerid,COLOR_LIGHTBLUE, "Usage: /Changename [new name]");
    new filestring[128];
    new filestring2[128];
    format(filestring2, sizeof(filestring2), "/Users/%s.ini", oldname);
    format(filestring, sizeof(filestring), "/Users/%s.ini", newname);
    if(fexist(filestring)) return SendClientMessage(playerid, COLOR_RED, "[ERROR]: The new name you've chosen is already taken");
    format(string, sizeof(string), "%s has changed his name to %s!" ,oldname, newname);
    SetPlayerName(playerid, newname);
    SendClientMessageToAll(COLOR_WHITE, string);
    frename(filestring2, filestring);
    new INI:File = INI_Open(filestring);
    INI_SetTag(File, "data");
    new str[50];
    format(str, sizeof str, "/Users/%s.ini", oldname);
    INI_RemoveEntry(File,str);
    INI_Close(File);
    return 1;
}
If some experienced guy can help me I will be thankful with a rep!
Regards, rakinz.
you just had to put this display the client message before you change the player's name
PHP код:

CMD
:changename(playerid,params[])
{
    new 
oldname[128], newname[128], string[90];
    if(
sscanf(params,"s[128]"newname)) return SendClientMessage(playerid,COLOR_LIGHTBLUE"Usage: /Changename [new name]");
    new 
filestring[128];
    new 
filestring2[128];
    
format(filestring2sizeof(filestring2), "/Users/%s.ini"oldname);
    
format(filestringsizeof(filestring), "/Users/%s.ini"newname);
    if(
fexist(filestring)) return SendClientMessage(playeridCOLOR_RED"[ERROR]: The new name you've chosen is already taken");
    
format(stringsizeof(string), "%s has changed his name to %s!" ,oldnamenewname);
    
SendClientMessageToAll(COLOR_WHITEstring);
    
frename(filestring2filestring);
    
SetPlayerName(playeridnewname);
    new 
INI:File INI_Open(filestring);
    
INI_SetTag(File"data");
    new 
str[50];
    
format(strsizeof str"/Users/%s.ini"oldname);
    
INI_RemoveEntry(File,str);
    
INI_Close(File);
    return 
1;

Код:
NOTE: it'd be better for people to read your code if you used [ PHP ][ /PHP ] wrappers instead of [ CODE ][ /CODE ]
Reply
#3

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
you just had to put this display the client message before you change the player's name
PHP код:

CMD
:changename(playerid,params[])
{
    new 
oldname[128], newname[128], string[90];
    if(
sscanf(params,"s[128]"newname)) return SendClientMessage(playerid,COLOR_LIGHTBLUE"Usage: /Changename [new name]");
    new 
filestring[128];
    new 
filestring2[128];
    
format(filestring2sizeof(filestring2), "/Users/%s.ini"oldname);
    
format(filestringsizeof(filestring), "/Users/%s.ini"newname);
    if(
fexist(filestring)) return SendClientMessage(playeridCOLOR_RED"[ERROR]: The new name you've chosen is already taken");
    
format(stringsizeof(string), "%s has changed his name to %s!" ,oldnamenewname);
    
SendClientMessageToAll(COLOR_WHITEstring);
    
frename(filestring2filestring);
    
SetPlayerName(playeridnewname);
    new 
INI:File INI_Open(filestring);
    
INI_SetTag(File"data");
    new 
str[50];
    
format(strsizeof str"/Users/%s.ini"oldname);
    
INI_RemoveEntry(File,str);
    
INI_Close(File);
    return 
1;

Your code does not fixing my problem, notice that I'd 2 problems, The first one was the player's "old name" doesn't appear and the second was that the old ini file doesn't get delete and it just copying the old player's data to a new file with the new name I choose.
None of the problems got fixed.
Reply
#4

To delete the in file use fremove
https://sampwiki.blast.hk/wiki/Fremove
Reply
#5

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
To delete the in file use fremove
https://sampwiki.blast.hk/wiki/Fremove
I don't really know how to use it, I would love to if you could ease me and write the end of the code.
By the way, I still don't get it how to make the "old name" appear at the message (I've tried putting it as top as I can).
Reply
#6

PHP код:
GetPlayerName(playeridoldnamesizeof(oldname)); 
add this line under the "sscanf" line and both of your problems are fixed.
Reply
#7

Quote:
Originally Posted by GangstaSunny.
Посмотреть сообщение
PHP код:
GetPlayerName(playeridoldnamesizeof(oldname)); 
add this line under the "sscanf" line and both of your problems are fixed.
Respect. Thanks a lot, short and sweet

You deserve a huge rep for helping.
Reply
#8

Now just to wait until a player inputs invalid characters or more than 20 characters. The account will become corrupt and the player won't be able to login again. Verify the output of SetPlayerName before applying any actual changes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)