2 Questions :
#5

pawn Код:
dcmd_health(playerid, params[])
{
    new
        giveplayerid, tmp[256], tmp2[256], idx,
        amount, string[156];
        tmp=strtok(params, idx); tmp2=strtok(params, idx);
    if(!strlen(tmp) || strlen(tmp2)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /health [playerid] [amount]");
    giveplayerid=strval(tmp); amount=strval(tmp2);
    if (!IsPlayerConnected(giveplayerid)) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    if (amount > 100) SendClientMessage(playerid, 0xFF0000AA, "Invalid health");
    else
    {
        new Float:hh; GetPlayerHealth(playerid, hh);
        SetPlayerHealth(giveplayerid, amount);
        SetPlayerHealth(playerid, hh-10);
        format(string,sizeof(string),"life's й [%i]",amount);
        SendClientMessageToAll(COR_BRANCO, string);
    }
    return 1;
}

strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
That should work. Try it out.

It is the command + the "strtok" function, which is better then "sscanf". Just overpaste your command with the code upon.

Tell me if there are bugs, or errors or what else.

Greetz,
Jeffry
Reply


Messages In This Thread
2 Questions : - by felipex - 16.07.2010, 13:41
Re: 2 Questions : - by felipex - 16.07.2010, 13:59
Re: 2 Questions : - by tanush - 16.07.2010, 14:06
Re: 2 Questions : - by felipex - 16.07.2010, 14:09
Re: 2 Questions : - by Jeffry - 16.07.2010, 14:10
Re: 2 Questions : - by felipex - 16.07.2010, 14:18
Re: 2 Questions : - by Jeffry - 16.07.2010, 14:26
Re: 2 Questions : - by felipex - 16.07.2010, 14:35

Forum Jump:


Users browsing this thread: 1 Guest(s)