/changenick doesnt overwrite the existing file.
#1

Hello,
Well i got a cmd /changenick but its not working as i want. When i use /changenick it creates new file instead renaming the existing file
Code:
pawn Код:
if(strcmp(cmd,"/changenick",true)==0)
        {
            if(PlayerInfo[playerid][power] >= 10)
            {
                new tmp[256],nickid;
                new oldname[ MAX_PLAYER_NAME +9 ], newname[ MAX_PLAYER_NAME +9 ];
                new stringa[MAX_STRING];
                tmp = strtok(cmdtext,idx);
                if(!strlen(tmp))
                {
                    SendClientUsage(playerid, cmd, "[exaclty name] [new name] (case sensitive)");
                    return 1;
                }
                nickid=INVALID_PLAYER_ID;
                if(IsPlayerConnected(PlayerID(tmp)))  nickid=PlayerID(tmp);
                format(oldname, sizeof(oldname), "%s.dudb.sav", udb_encode(tmp));
                format(newname, sizeof(newname), "%s.dudb.sav", udb_encode(tmp));
                frenametextfile(oldname, newname);
                tmp=strtok(cmdtext,idx);
                if(!strlen(tmp))
                {
                    SendClientUsage(playerid, cmd, "[exaclty name] [new name] (case sensitive)");
                    return 1;
                }
                format(oldname, sizeof(oldname), "%s.dudb.sav", udb_encode(PlayerName(playerid)));
                format(newname, sizeof(newname), "%s.dudb.sav", udb_encode(tmp));
                frenametextfile(oldname, newname);
                SetPlayerName(playerid, tmp);
                if(dini_Exists(oldname))
                {
                    if(!dini_Exists(newname))
                    {
                        frenametextfile(oldname,newname);
                        format(stringa,sizeof(stringa),"%s renamed in %s succesfully",oldname,newname);
                        SendClientInfo(playerid,  stringa);
                        if(IsPlayerConnected(nickid))
                        {
                            SendClientMessage(playerid, COLOR_WHITE, "NickName Succesfully Changed :. ");
                            SetPlayerName(nickid,tmp);
                        }
                        format(stringa,sizeof(stringa),"Admin(%s) renamed %s in %s",PlayerName(playerid),oldname,newname);
                        AppendTo(adminlog,stringa);
                        return 1;
                    }
                    else
                    {
                        format(stringa,sizeof(stringa),"%s - ACCOUNT ALREADY EXIST",newname);
                        SendClientError(playerid,   stringa);
                        return 1;
                    }
                }
                else
                {
                    format(stringa,sizeof(stringa),"%s, Account not found",oldname);
                    SendClientError(playerid,   stringa);
                    return 1;
                }
            }
            return 1;
        }
Anyone got Idea how to fix this?
Reply
#2

A few things need to be fixed first:

pawn Код:
if(strcmp(cmd,"/changenick",true)==0)
    {
        if(PlayerInfo[playerid][power] >= 10)
        {
            new tmp[128],nickid;
            new oldname[ MAX_PLAYER_NAME +9 ], newname[ MAX_PLAYER_NAME +9 ];
            new stringa[MAX_STRING];
            tmp = strtok(cmdtext,idx);
            if(!strlen(tmp))
            {
                SendClientUsage(playerid, cmd, "[exaclty name] [new name] (case sensitive)");
                return 1;
            }
            nickid=INVALID_PLAYER_ID;
            if(IsPlayerConnected(PlayerID(tmp)))  nickid=PlayerID(tmp);
I changed the length of your "tmp" variable since the player can never type a parameter which is longer than 128.
I would also recommend you use a YCMD or ZCMD to process your commands.

pawn Код:
//continued from section above
            format(oldname, sizeof(oldname), "%s.dudb.sav", udb_encode(tmp));
            format(newname, sizeof(newname), "%s.dudb.sav", udb_encode(tmp));
            frenametextfile(oldname, newname);
Now these three lines are useless.
The first one is not needed yet.
The second one formats the new name of the file to be exactly the same as the name of the old file.
The third line is basically changing the name of the file to what it is already.
Remove these lines.

pawn Код:
//continued from section above
            tmp=strtok(cmdtext,idx);
            if(!strlen(tmp))
            {
                SendClientUsage(playerid, cmd, "[exaclty name] [new name] (case sensitive)");
                return 1;
            }
            format(oldname, sizeof(oldname), "%s.dudb.sav", udb_encode(PlayerName(playerid)));//#1
            format(newname, sizeof(newname), "%s.dudb.sav", udb_encode(tmp));
            frenametextfile(oldname, newname);//#2
            SetPlayerName(playerid, tmp);//#3
Three of the last four lines here cause problems.
The first of them, "#1", sets the old name of the file using the name of the player who TYPED the command.
The second of them, "#2", should not be used yet because of the if statement after this.
The third, "#3", changes the name of the player who TYPED the command to the new name.

pawn Код:
//continued from section above
            if(dini_Exists(oldname))
            {
                if(!dini_Exists(newname))
                {
                    frenametextfile(oldname,newname);
                    format(stringa,sizeof(stringa),"%s renamed in %s succesfully",oldname,newname);
                    SendClientInfo(playerid,  stringa);
                    if(IsPlayerConnected(nickid))
                    {
                        SendClientMessage(playerid, COLOR_WHITE, "NickName Succesfully Changed :. ");
This last message should be sent to the player who's name is being changed. You are sending it to the player who TYPED the command "playerid", not the player who's name is being changed "nickid".
pawn Код:
//continued from section above
                        SetPlayerName(nickid,tmp);
                    }
                    format(stringa,sizeof(stringa),"Admin(%s) renamed %s in %s",PlayerName(playerid),oldname,newname);
                    AppendTo(adminlog,stringa);
                    return 1;
                }
                else
                {
                    format(stringa,sizeof(stringa),"%s - ACCOUNT ALREADY EXIST",newname);
                    SendClientError(playerid,   stringa);
                    return 1;
                }
            }
            else
            {
                format(stringa,sizeof(stringa),"%s, Account not found",oldname);
                SendClientError(playerid,   stringa);
                return 1;
            }
        }
        return 1;
    }
The rest of this should be fine.
Reply
#3

The basic thing you need to do here is to get the old name variable stored, get the user account file path and then delete it. After that you need to change the name of the player to the new name and then save it.
Reply
#4

I made this but get two errors
pawn Код:
if(strcmp(cmd,"/changenick",true)==0)
    {
        if(PlayerInfo[playerid][power] >= 10)
        {
            new tmp[128],nickid;
            new oldname[ MAX_PLAYER_NAME +9 ], newname[ MAX_PLAYER_NAME +9 ];
            new stringa[MAX_STRING];
            tmp = strtok(cmdtext,idx); // line 24752
            if(!strlen(tmp))
            {
                SendClientUsage(playerid, cmd, "[exaclty name] [new name] (case sensitive)");
                return 1;
            }
            nickid=INVALID_PLAYER_ID;
            if(IsPlayerConnected(PlayerID(tmp)))  nickid=PlayerID(tmp);
            tmp=strtok(cmdtext,idx); // line 24760
            if(!strlen(tmp))
            {
                SendClientUsage(playerid, cmd, "[exaclty name] [new name] (case sensitive)");
                return 1;
            }
            format(oldname, sizeof(oldname), "%s.dudb.sav", udb_encode(PlayerName(playerid)));//#1
            format(newname, sizeof(newname), "%s.dudb.sav", udb_encode(tmp));
            frenametextfile(oldname, newname);//#2
            SetPlayerName(playerid, tmp);//#3
            if(dini_Exists(oldname))
            {
                if(!dini_Exists(newname))
                {
                    frenametextfile(oldname,newname);
                    format(stringa,sizeof(stringa),"%s renamed in %s succesfully",oldname,newname);
                    SendClientInfo(playerid,  stringa);
                    if(IsPlayerConnected(nickid))
                    {
                        SendClientMessage(playerid, COLOR_WHITE, "NickName Succesfully Changed :. ");
                          SetPlayerName(nickid,tmp);
                    }
                    format(stringa,sizeof(stringa),"Admin(%s) renamed %s in %s",PlayerName(playerid),oldname,newname);
                    AppendTo(adminlog,stringa);
                    return 1;
                }
                else
                {
                    format(stringa,sizeof(stringa),"%s - ACCOUNT ALREADY EXIST",newname);
                    SendClientError(playerid,   stringa);
                    return 1;
                }
            }
            else
            {
                format(stringa,sizeof(stringa),"%s, Account not found",oldname);
                SendClientError(playerid,   stringa);
                return 1;
            }
        }
        return 1;
    }
pawn Код:
(24752) : error 047: array sizes do not match, or destination array is too small
(24760) : error 047: array sizes do not match, or destination array is too small
Reply
#5

Bump ! Noone? I need to fix this problem fast!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)