SA-MP Forums Archive
/sethp command shows 1203102301 health. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: /sethp command shows 1203102301 health. (/showthread.php?tid=582961)



/sethp command shows 1203102301 health. - whando - 24.07.2015

Hello, I created a /sethp command, it works fine, it just shows my HP has been set to 3284234928, while it gives the right amount of HP.

Код:
CMD:sethp(playerid, params[])
{
	static
		userid,
	    Float:amount;

	if (PlayerData[playerid][pAdmin] < 2)
	    return SendErrorMessage(playerid, "You don't have permission to use this command.");

	if (sscanf(params, "uf", userid, amount))
		return SendSyntaxMessage(playerid, "/sethp [PlayerName/PlayerID] [0-100]");

	if (userid == INVALID_PLAYER_ID)
	    return SendErrorMessage(playerid, "You have specified an invalid player.");

	SetPlayerHealth(userid, amount);
	SendBlueColorMessage(playerid, "> You have set %s's Health to %d.", ReturnName(userid, 0), amount);
	SendBlueColorMessage(userid, "> Admin %s has set your Health to %d.", ReturnName(playerid, 0), amount);
	return 1;
}
What did I do wrong?


Re: /sethp command shows 1203102301 health. - liquor - 24.07.2015

Because you're using the wrong specifier.


When using %f, you'll get the entire float amount, e.g "97.319495", to avoid this you can use %.0f for no decimals, %.1f for 1 decimal (e.g. 97.3)


Re: /sethp command shows 1203102301 health. - whando - 24.07.2015

Thanks worked!