2 Questions : -
felipex - 16.07.2010
what's wrong here ?
Код:
dcmd_health(playerid, params[])
{
new
giveplayerid,
amount;
if (sscanf(params, "ud", giveplayerid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid/partname] [amount]");
else if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
else if (amount > 100) SendClientMessage(playerid, 0xFF0000AA, "Invalid health");
else
{
SetPlayerHealth(giveplayerid, amount);
format(string,sizeof(string),"life's й [%i]",GetPlayerHealth(giveplayerid));// %d or %i = shows 1 of hp -.-'
SendClientMessageToAll(COR_BRANCO, string);
}
return 1;
}
And How do I do for everytime that I uses a command, the player lose -10hp from his life?
Re: 2 Questions : -
felipex - 16.07.2010
Someone please......
Re: 2 Questions : -
tanush - 16.07.2010
erm ill try to find out, i was thinking of setplayerhealth then i relize that if i put 10 it will always be 10
Re: 2 Questions : -
felipex - 16.07.2010
lol, I do SetPlayerHealth 4 4 and yet this bullshit shows as 1 ... pawno bugs really are a bullshit senseless..
Re: 2 Questions : -
Jeffry - 16.07.2010
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
Re: 2 Questions : -
felipex - 16.07.2010
ye, works, but I think you mixed my 2 questions , cause everytime I use this , the player lose 10hp, and shows on string the his life I put down x: . And also showed it " Usage: /health [playerid] [amount]", same although the player is connected and I've used the string complete /health id amount
Re: 2 Questions : -
Jeffry - 16.07.2010
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;
}
Try this.
And I did not get the thing with the -10 HP. I just made that if you set someones health, your own health will be set 10 lower.
Re: 2 Questions : -
felipex - 16.07.2010
hehe Thanx, had some bugs, but I fixed, for who wants also, it's :
Код:
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]");
else if (IsPlayerConnected(giveplayerid) == 0) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
else if (amount > 100) SendClientMessage(playerid, 0xFF0000AA, "Invalid health");
else
{
giveplayerid=strval(tmp); amount=strval(tmp2);
SetPlayerHealth(giveplayerid, amount);
format(string,sizeof(string),"life's й [%i]",amount);
SendClientMessageToAll(COR_BRANCO, string);
}
return 1;
}