Problem with sscanf
#4

pawn Код:
CMD:akill(playerid,params[])
{
    new Name[MAX_PLAYER_NAME], pname[MAX_PLAYER_NAME], str[128];
    new ID = ReturnUser(params));
    if(sscanf(params,"u",ID)) return SendClientMessage(playerid,COLOR_GREY,"USAGE: /akill [playerid / Partofname]");
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,COLOR_RED,"ERROR: This user is not connected!");
    GetPlayerName(playerid,Name,sizeof(Name));
    GetPlayerName(ID,pname,sizeof(pname));
    format(str,sizeof(str),"Administrator %s has killed you",Nam);
    SendClientMessage(ID,COLOR_ORANGE,str);
    format(str,sizeof(str),"You have admin killed %s",pname);
    SendClientMessage(playerid,COLOR_ORANGE,str);
    SetPlayerHealth(ID,0);
    return 1;
}
Also you are going to need this stock (Put it at the end of your script):
pawn Код:
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
    new pos = 0;
    while (text[pos] < 0x21)
    {
        if (text[pos] == 0) return INVALID_PLAYER_ID;
        pos++;
    }
    new userid = INVALID_PLAYER_ID;
    if (IsNumeric(text[pos]))
    {
        userid = strval(text[pos]);
        if (userid >=0 && userid < MAX_PLAYERS)
        {
            if(!IsPlayerConnected(userid))
            {
                if (playerid != INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "User not connected");
                userid = INVALID_PLAYER_ID;
            }
            else return userid;
        }
        else
        {
            if (playerid != INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Invalid user ID");
            userid = INVALID_PLAYER_ID;
        }
        return userid;
    }
    new len = strlen(text[pos]);
    new count = 0;
    new name[MAX_PLAYER_NAME];
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i, name, sizeof (name));
            if (strcmp(name, text[pos], true, len) == 0)
            {
                if (len == strlen(name)) return i;
                else
                {
                    count++;
                    userid = i;
                }
            }
        }
    }
    if (count != 1)
    {
        if (playerid != INVALID_PLAYER_ID)
        {
            if (count) SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
            else SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
        }
        userid = INVALID_PLAYER_ID;
    }
    return userid;
}
Reply


Messages In This Thread
Problem with sscanf - by bustern - 04.09.2013, 08:56
Re: Problem with sscanf - by Misiur - 04.09.2013, 09:11
Re: Problem with sscanf - by FabianoC - 04.09.2013, 09:28
Re: Problem with sscanf - by Dragonsaurus - 04.09.2013, 10:43

Forum Jump:


Users browsing this thread: 1 Guest(s)