16.07.2010, 14:10
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;
}
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