command for /changename?
#1

How do I make my own changename command? because in my admin system it doesn't have /changename command and more info it should remain its stats only name must change.

Before I forgot also check if name is already taken so their stats wouldn't conflict.
Reply
#2

Use the function SetPlayerName to change a user's name when they are currently in game.
As for detecting if the username is already taken, format the path of the new name and use fexist to determine if it's taken or not.
(If your using MySQL, fexist will not work obviously). If the user's file currently exists and they are registered, you can use this custom stock function:


pawn Code:
stock frename(oldname[], newname[])
{
    if(!fexist(oldname)) return false;
    new string[128], File:old, File:neww;
    old = fopen(oldname, io_read);
    neww = fopen(newname, io_write);
    while(fread(old, string))
    {
        StripNewLine(string);
        format(string, sizeof(string), "%s\r\n", string);
        fwrite(neww, string);
    }
    fclose(old);
    fclose(neww);
    fremove(oldname);
    return true;
}
To modify and re-name their userfile to the new username.
Reply
#3

Quote:
Originally Posted by West X
View Post
Use the function SetPlayerName to change a user's name when they are currently in game.
As for detecting if the username is already taken, format the path of the new name and use fexist to determine if it's taken or not.
(If your using MySQL, fexist will not work obviously). If the user's file currently exists and they are registered, you can use this custom stock function:


pawn Code:
stock frename(oldname[], newname[])
{
    if(!fexist(oldname)) return false;
    new string[128], File:old, File:neww;
    old = fopen(oldname, io_read);
    neww = fopen(newname, io_write);
    while(fread(old, string))
    {
        StripNewLine(string);
        format(string, sizeof(string), "%s\r\n", string);
        fwrite(neww, string);
    }
    fclose(old);
    fclose(neww);
    fremove(oldname);
    return true;
}
To modify and re-name their userfile to the new username.
Thanks for this man.. But how could I start the command for change name?

Like this?

pawn Code:
CMD:changename(playerid,params[])
{
        SendClientMessage(playerid, white, "{FFFF00}Usage: /changename [NewName]");
        if(length < 3 || length > MAX_PLAYER_NAME) return SendClientMessage(playerid,white,"{FF0000}>> Incorrect Name Length");
        new string[64];
        format(string,sizeof(string),"Your have been changed your current Name to %s, ", tmp);
        SendClientMessage(playerid, LIGHTBLUE, string);
        SetPlayerName(playerid, );
        return OnPlayerConnect(playerid);
}
Reply
#4

<The content in this post has been removed.>
Reply
#5

Got 2 warnings

Code:
warning 219: local variable "pName" shadows a variable at a preceding level
error 017: undefined symbol "StripNewLine"
I've got the 2nd pName. What should I remove or change?
Code:
stock pName(playerid)
{
	new paname[MAX_PLAYER_NAME];
	GetPlayerName(playerid, paname, sizeof(paname));
	return paname;
}
Reply
#6

<The content in this post has been removed.>
Reply
#7

Quote:
Originally Posted by West X
View Post
Here is the fix:

pawn Code:
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_WHITE 0xFFFFFFAA

CMD:changename(playerid, params[])
{
    new newname[MAX_PLAYER_NAME], file1[128], file2[128];
    if(sscanf(params, "s[24]", newname)) return SendClientMessage(playerid, COLOR_GREY, "Usage: /changename [New Username]");
    if(strlen(newname) < 3 || strlen(newname) > MAX_PLAYER_NAME) return SendClientMessage(playerid, COLOR_GREY, "Invalid username length.");
    format(file2, sizeof(file2), "/Users/%s.ini", newname);
    if(fexist(file2)) return SendClientMessage(playerid, COLOR_GREY, "The specified username is already taken.");
    format(file1, sizeof(file1), "/Users/%s.ini", pName(playerid));
    format(file2, sizeof(file2), "/Users/%s.ini", newname);
    frename(file1, file2);
    SetPlayerName(playerid, newname);
    format(file1, sizeof(file1), "You have changed your name to %s.", newname);
    SendClientMessage(playerid, COLOR_WHITE, file1);
    return 1;
}
You will also need this stock function:

pawn Code:
stock StripNewLine(string[])
{
    new len = strlen(string);
    if(string[0] == 0) return;
    if((string[len - 1] == '\n') || (string[len - 1] == '\r'))
    {
        string[len - 1] = 0;
        if(string[0]==0) return ;
        if((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
    }
}
Thanks +rep it's all working now. Also it deletes the old account and replaced it with the new one and that is great! And lastly could you help me with Unban command? just like changename command.
Reply
#8

Exactly what file saving system does your game-mode use?
Reply
#9

I'm using a filterscript MellAdmin and it use Dini for saving.

This is the stock..

pawn Code:
stock DiniBanPlayer(playerid, admin[], reason[])
{
    new file[128], date[16], year, month, day;
    getdate(year, month, day);
    format(date, sizeof(date), "%d/%d/%d", day, month, year);
    format(file, sizeof(file), "/%s/%s.ini", DINI_PATH, GetName(playerid));
    dini_IntSet(file, "Status", 2);
    dini_Set(file, "BannedBy", admin);
    dini_Set(file, "BanReason", reason);
    dini_Set(file, "BanDate", date);
    Kick(player);
    return 1;
}
In the thread is says
pawn Code:
Status (0 = offline, 1 = online, 2 = banned)
If I do /unban [Exact Name]

Status=2 must change to Status=0
Reply
#10

<The content in this post has been removed.>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)