24.06.2012, 22:11
A few things need to be fixed first:
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.
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.
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.
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".
The rest of this should be fine.
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 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);
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
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 :. ");
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;
}