Command with ID
#1

Hello, how can i make this that i type the Player ID to change his name?

Код:
CMD:changename(playerid, params[])
{
    if(pInfo[playerid][pLogged] == 1)
    {
    if(pInfo[playerid][pAdminLevel] >= 5)
    {
    new oldname[24], newname[24];
    if(sscanf(params,"s[24]s[24]",oldname, newname)) return SendClientMessage(playerid,-1,""chat""COL_RED" Usage: /changename [oldname] [newname]");
    new filestring2[128];
    format(filestring2, sizeof(filestring2), "/Users/%s.ini", oldname);
    if(!fexist(filestring2)) return SendClientMessage(playerid,-1,""chat""COL_RED" That account name doesn't exist!");
    new filestring[128];
    format(filestring, sizeof(filestring), "/Users/%s.ini", newname);
    if(fexist(filestring)) return SendClientMessage(playerid,-1,""chat""COL_RED" The new name you've chosen is already taken");
    frename(filestring2, filestring);
    new string[128];
    format(string, sizeof(string), "» {F7B533}You have successfully renamed %s's account to %s" ,oldname, newname);
    SendClientMessage(playerid, -1, string);
	}
	else {
		SendClientMessage(playerid,-1,""chat""COL_RED" You do not have the sufficient privileges to use this command.");
			}
	}
	else {
	    SendClientMessage(playerid,-1,""chat" You are not logged in!");
	    Kick(playerid);
	}
    return 1;
}
Reply
#2

How about this instead:

pawn Код:
YCMD:changename(playerid, params[], help){
    if(pInfo[playerid][pLogged] == 1 && pInfo[playerid][pAdminLevel] >= 5){
    new name[MAX_PLAYER_NAME];
    new PlayerID;
    if(sscanf(params, "is[MAX_PLAYER_NAME]", name, PlayerID)) return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /changename [id] [name]")
    new oldname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, oldname);
    new filestring[128];
    format(filestring, sizeof(filestring), "/Users/%s.ini", oldname);
    new filestring2[128];
    format(filestring, sizeof(filestring), "/Users/%s.ini", name);
    frename(filestring, filestring2);
    SetPlayerName(PlayerID, name);
    }
    else{
    SendClientMessage(playerid, 0xFFFFFFFF, "Not logged in or whatever.");
    }
    return 1;
}
Just something I wrote real quick through a quick reply here on SA-MP forums, so there might be errors. However, hopefully you'll get an idea of how to do it.
Reply
#3

pawn Код:
CMD:changename(playerid, params[])
{
    if(pInfo[playerid][pLogged] == 1)
    {
        if(pInfo[playerid][pAdminLevel] >= 5)
        {
            new userid, newname[MAX_PLAYER_NAME + 1];
            if(sscanf(params,"us[" #MAX_PLAYER_NAME "]",userid, newname)) SendClientMessage(playerid,-1,""chat""COL_RED" Usage: /changename [ID / Nick] [newname]");
            else if(userid == INVALID_PLAYER_ID || !IsPlayerConnected(userid)) SendClientMessage(playerid,-1,""chat""COL_RED" ID is not connected.");
            else{
                new str[2][40],Nick[MAX_PLAYER_NAME + 1];
                GetPlayerName(userid,Nick,MAX_PLAYER_NAME);
                format(str[0], sizeof(str[]), "/Users/%s.ini", Nick);
                if(!fexist(str[0])) return SendClientMessage(playerid,-1,""chat""COL_RED" That account name doesn't exist!");
                format(str[1], sizeof(str[]), "/Users/%s.ini", newname);
                if(fexist(str[1])) return SendClientMessage(playerid,-1,""chat""COL_RED" The new name you've chosen is already taken");
                frename(str[0], str[1]);
                new string[128];
                format(string, sizeof(string), "» {F7B533}You have successfully renamed %s's account to %s" ,Nick, newname);
                SendClientMessage(playerid, -1, string);
                SetPlayerName(userid, newname);
            }
        }
        else
            SendClientMessage(playerid,-1,""chat""COL_RED" You do not have the sufficient privileges to use this command.");
    }
    else {
        SendClientMessage(playerid,-1,""chat" You are not logged in!");
        Kick(playerid);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)