[REQUEST]/changename commands for players
#1

Dear senior scripter.

i want to request a script to make /changename possible without losing status.

thanks.
Reply
#2

i will tell u a minute when i getg on my desktop pc im on my internet pc not scripting one
Reply
#3

By the way, if you're requesting a code you should post it into: http://forum.sa-mp.com/index.php?topic=144062.0
If you want to know how to do it instead, use:
pawn Код:
SetPlayerName(playerid, "newname");
Reply
#4

Without losing stats? you would have to rename the file.
Reply
#5

I wonder how to do this too..

I have /changename [id] [name] command. Everything works fine, but it kind of Copy's the Account and renames other one to name that is wanted. So if the player logs with old name, he succeeds. He haves like 2 accounts with same stats etc.

Any suggestions?

EDIT:

Is it possible that it Deletes the old account after it makes the "copy" ? Its annoying to go FTP and delete it manually...
Reply
#6

you shouldnt copy the file, just use the function:

frename(oldname[], newname[]);

thats it

if you dont have frename use this:

pawn Код:
stock frename(oldname[], newname[])
{
    if (!fexist(oldname)) return 0;
    new File:oldfile = fopen(oldname, io_read);
    new File:newfile = fopen(newname, io_write);
    new line[256];
    while (fread(oldfile, line))
    {
        fwrite(newfile, line);
    }
    fclose(oldfile);
    fclose(newfile);
    fremove(oldname);
    return 1;
}
Reply
#7

thx for the help everyone but is this work with database?
Reply
#8

Quote:
Originally Posted by ДitisOnHuora
Is it possible that it Deletes the old account after it makes the "copy" ? Its annoying to go FTP and delete it manually...
https://sampwiki.blast.hk/wiki/Fremove

Quote:
Originally Posted by LUCAGRABACR
thx for the help everyone but is this work with database?
If you're using MySQL then you can just rename the username.
Reply
#9

Im not so professional scripter so i have no idea how to do it...

Could anyone help ? Here is the cmd:

pawn Код:
if(strcmp(cmd, "/changename", true) == 0)
    {
      GetPlayerName(playerid, sendername, sizeof(sendername));
        new tmpp[256];
        tmpp = strtok(cmdtext, idx);
        if(!strlen(tmpp))
        {
            SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /changename [playerid] [new_nick]");
            SendClientMessage(playerid, COLOR_GRAD2, "USAGE: Remember to ban/delete old Firstname_Lastname from 'accounts' folder!!");
            return 1;
        }
        giveplayerid = strval(tmpp);
        tmp = strtok(cmdtext, idx);
        GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
        GetPlayerName(playerid, sendername, sizeof(sendername));
        if(IsPlayerConnected(playerid))
        {
          if(PlayerInfo[playerid][pAdmin] >= 1337)
          {
            if(IsPlayerConnected(giveplayerid))
            {
                    SetPlayerName(giveplayerid, tmp);
                    format(string, sizeof(string), "[SERVER]: %s(%i) has changed Your name to %s", sendername, playerid, tmp);
                    SendClientMessage(giveplayerid, COLOR_GREEN, string);
                    format(string, sizeof(string), "[SERVER]: You have changed ID %i's name to %s", giveplayerid, tmp);
                    SendClientMessage(playerid, COLOR_GREEN, string);
                    format(string, sizeof(string), "[SERVER]: Remember to ban/delete %s's old Firstname_Lastname!", tmp);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    format(string, 256, "[SERVER]: %s has changed %s's his name to %s.", sendername,giveplayer, tmp);
                    ABroadCast(COLOR_RED,string,1);
                }
                else
                {
                  format(string, sizeof(string), "%d is not an active player.", giveplayerid);
                    SendClientMessage(playerid, COLOR_GREY, string);
                }
            }
            else
            {
              SendClientMessage(playerid, COLOR_GREY, "You do not have permission to use that command!");
            }
        }
        else
        {
          SendClientMessage(playerid, COLOR_GREY, "You Must be logged in to use this command!");
        }
        return 1;
    }
Reply
#10

What is the function you use to save player's data to file?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)