31.07.2013, 12:24
This is what I presume is happening inside the SAMP server when I execute GetPlayerHealth:
Surely it would be just as simple to do this:
This is what I presume is happening inside the SAMP server when I execute GetPlayerHealth:
This would be a lot more useful because then everything could be in one line.
If you want to store the value:
If you want to use the value:
I just really can't see why it was programmed the other way.
I know that most functions either return 0 or 1 to indicate the success of the action but they could easily just return -1 in the event of a failure, 0 to indicate that the player is dead and otherwise return their health.
pawn Code:
stock GetPlayerHealth(playerid, &health)
{
RequestUpdateFromClient(playerid);
health = playerHealth[playerid];
}
This is what I presume is happening inside the SAMP server when I execute GetPlayerHealth:
pawn Code:
stock Float:GetPlayerHealth(playerid, &health)
{
RequestUpdateFromClient(playerid);
return playerHealth[playerid];
}
If you want to store the value:
pawn Code:
pHealth = GetPlayerHealth(playerid);
pawn Code:
format(string, sizeof(string), "Your health is: %f", GetPlayerHealth(playerid));
Quote:
Despite what the wiki might say, most functions do also have a return value. Most of them return 1 on success and 0 on failure (i.e. not connected or invalid vehicleid). GetPlayerHealth is no exception. This means that doing something like this (common practice) is redundant;
|