Changing player name?
#1

Hi, I wanna a setname command which changes player name n his ini file, i using yini, i can set player name with
PHP код:
SetPlayerName(playerid""); 
But idk how to rename his file so, if someone can gimme the command with the rename thing (dcmd if possible) or even an idea how to make it, will be awesome
Reply
#2

Okay, I can tell you how you I would do.

1- Store the values that you have the file with the previous name, store these values in a string type variable and separate them with a delimiter e.g -> "value1|value2|value3.

2- Delete the file with the previous name, you can do this with the following function

PHP код:
fremove("name.ini"); 
3- Change the name of the player.

4- Use sscanf and extracting the string that contains the values and place the variables where it should go each value, e.g:

PHP код:
sscanf(mystring"p<|>iiii"var_value1varvalue2, ...); 
5- Finally you must create a file and store the value that contain the variables.

Note: I always use sql to store data, so that I do not know very well Yini, i don't know if there is a function that changes the name of a file, but it has not could do what I just wrote.
Reply
#3

i have this function, try do with this

PHP код:
CMD:changename(playeridparams[])
{
    new
        
id,
        
name[MAX_PLAYER_NAME];
    if(
sscanf(params"us[24]"idname))
        return 
SendClientMessage(playerid, -1"/changename [playerid] [newname]");
    if(
strlen(name) < || strlen(name) > MAX_PLAYER_NAME)
        return 
SendClientMessage(playerid, -1"The length of name have at least 3 characters or exceeds of 24 characters.");
    new
        
file[64];
    
format(filesizeof(file), "Accounts/%s.ini"name);
    if(
fexist(file))
        return 
SendClientMessage(playerid, -1"That name is already in use!");
    
ChangePlayerName(idname);
    return 
1;
}
stock ChangePlayerName(playeridnewname[])
{
    new
        
PlayerName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridPlayerNameMAX_PLAYER_NAME);
    
#define DIRECTORY_SIZE MAX_PLAYER_NAME+15
    
new
        
directory[2][DIRECTORY_SIZE];
    
format(directory[0], DIRECTORY_SIZE"Acconts/%s.ini"PlayerName);
    
format(directory[1], DIRECTORY_SIZE"Acconts/%s.ini"newname);
    if (!
fexist(directory[0]))
        return 
0;
    new
        
File:oldfile fopen(directory[0], io_read),
        
File:newfile fopen(directory[1], io_write),
        
line[256];
    while(
fread(oldfileline))
    {
        
fwrite(newfileline);
    }
    
fclose(oldfile);
    
fclose(newfile);
    
fremove(directory[0]);
    
SetPlayerName(playeridnewname);
    return 
1;

Reply
#4

Hmmm, thanks both i got the idea ty
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)