Help with the /changename command
#1

Okay, I started to script recently and need a little help with the /changename (I've used /setname here) command.
The idea is to actually change the name of the player completely. By that I mean, his userfiles get copied into another one with a new name. I tried my best to create it but it doesn't copy his data into a new file. Also I'm using the Y_INI system.

Please take a look at the coding and help me out. I'd be eternally grateful thanks.

pawn Код:
COMMAND:setname(playerid, params[])

{   new oldname[125], newname[125], string[128];
    GetPlayerName(playerid, oldname, sizeof(oldname));
    if(sscanf(params, "s[125]", newname)) return SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /setname [new_name]");
    format(string,sizeof(string),"\\Users\\%s.ini",newname);
    if(fexist(string)) return SendClientMessage(playerid, COLOR_YELLOW, "Account name already exists! Please choose another name!");
    else
        {
        new INI:File2 = INI_Open(string); new lolname[128];
        if (File2 != INI_NO_FILE)
        {
        INI_SetTag(File2,"data");
        INI_WriteInt(File2,"Password",PlayerInfo[playerid][pPass]);
        INI_WriteString(File2,"PasswordOrig",stringpass);
        INI_WriteInt(File2,"Cash",GetPlayerMoney(playerid));
        INI_WriteInt(File2,"Admin",PlayerInfo[playerid][pAdmin]);
        INI_WriteInt(File2,"Kills",PlayerInfo[playerid][pKills]);
        INI_WriteInt(File2,"Deaths",PlayerInfo[playerid][pDeaths]);
        INI_WriteFloat(File2,"X_Coord",1683.2069); //ignore the value of the coords
        INI_WriteFloat(File2,"Y_Coord",1449.3086);
        INI_WriteFloat(File2,"Z_Coord",10.7716);
        INI_Close(File2);
        }
        SetPlayerName(playerid,newname);
        format(lolname,sizeof(lolname)," ~ %s has changed his account name to %s", oldname, newname);
        SendClientMessageToAll(COLOR_ORANGE,lolname);
        fremove(UserPath(playerid));
       
  }
  return 1;
}
Reply
#2

Here is a tip
The idea is to just change player name..
When player disconnects, file is created automatically with all data.

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
        INI_WriteInt(File2,"Password",PlayerInfo[playerid][pPass]);
        INI_WriteString(File2,"PasswordOrig",stringpass);
        INI_WriteInt(File2,"Cash",GetPlayerMoney(playerid));
        INI_WriteInt(File2,"Admin",PlayerInfo[playerid][pAdmin]);
        INI_WriteInt(File2,"Kills",PlayerInfo[playerid][pKills]);
        INI_WriteInt(File2,"Deaths",PlayerInfo[playerid][pDeaths]);
        INI_WriteFloat(File2,"X_Coord",1683.2069); //ignore the value of the coords
        INI_WriteFloat(File2,"Y_Coord",1449.3086);
        INI_WriteFloat(File2,"Z_Coord",10.7716);
    INI_Close(File);
    return 1;
}
pawn Код:
COMMAND:setname(playerid, params[])

{   new oldname[125], newname[125], string[128];
    GetPlayerName(playerid, oldname, sizeof(oldname));
    if(sscanf(params, "s[125]", newname)) return SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /setname [new_name]");
    format(string,sizeof(string),"\\Users\\%s.ini",newname);
    if(fexist(string)) return SendClientMessage(playerid, COLOR_YELLOW, "Account name already exists! Please choose another name!");
    else
        {
        SetPlayerName(playerid,newname);
        format(lolname,sizeof(lolname)," ~ %s has changed his account name to %s", oldname, newname);
        SendClientMessageToAll(COLOR_ORANGE,lolname);  
  }
  return 1;
}
Reply
#3

Shouldn't you use 'fremove' before you change their name?
Reply
#4

Quote:
Originally Posted by ryansheilds
Посмотреть сообщение
Shouldn't you use 'fremove' before you change their name?
lol, I'm so stupid, Thanks a ton mate!

@RoXor Thanks for your help too, appreciate it
Reply
#5

pawn Код:
COMMAND:setname(playerid, params[])

{   new oldname[125], newname[125], string[128];
    GetPlayerName(playerid, oldname, sizeof(oldname));
    if(sscanf(params, "s[125]", newname)) return SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /setname [new_name]");
    format(string,sizeof(string),"\\Users\\%s.ini",newname);
    if(fexist(string)) return SendClientMessage(playerid, COLOR_YELLOW, "Account name already exists! Please choose another name!");
    else
        {
        new INI:File2 = INI_Open(string); new lolname[128];
        if (File2 != INI_NO_FILE)
        {
        INI_SetTag(File2,"data");
        INI_WriteInt(File2,"Password",PlayerInfo[playerid][pPass]);
        INI_WriteString(File2,"PasswordOrig",stringpass);
        INI_WriteInt(File2,"Cash",GetPlayerMoney(playerid));
        INI_WriteInt(File2,"Admin",PlayerInfo[playerid][pAdmin]);
        INI_WriteInt(File2,"Kills",PlayerInfo[playerid][pKills]);
        INI_WriteInt(File2,"Deaths",PlayerInfo[playerid][pDeaths]);
        INI_WriteFloat(File2,"X_Coord",1683.2069); //ignore the value of the coords
        INI_WriteFloat(File2,"Y_Coord",1449.3086);
        INI_WriteFloat(File2,"Z_Coord",10.7716);
        INI_Close(File2);
        }
        SetPlayerName(playerid,newname);
        format(lolname,sizeof(lolname)," ~ %s has changed his account name to %s", oldname, newname);
        SendClientMessageToAll(COLOR_ORANGE,lolname);
        fremove(UserPath(playerid));
       
  }
  return 1;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)