SA-MP Forums Archive
Rounding a certain float. - 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: Rounding a certain float. (/showthread.php?tid=588081)



Rounding a certain float. - BleverCastard - 05.09.2015

I have a variable for the players Health.
(PlayerInfo[playerid][Health]).

It loads perfectly when they log in, however, when they take damage, this happens:


I've tried using floatround, but that doesn't work.
floatround(PlayerInfo[playerid][Health] -= floatround(amount));

I've never really used floatround so please let me know if I'm using it incorrectly.


Re: Rounding a certain float. - fordawinzz - 05.09.2015

floatround converts the value to an integer.
as the amount variable is a float you can do this:
pawn Код:
PlayerInfo[playerid][Health] -= amount;
or floatsub


Re: Rounding a certain float. - Freezo - 05.09.2015

Quote:
Originally Posted by fordawinzz
Посмотреть сообщение
floatround converts the value to an integer.
as the amount variable is a float you can do this:
pawn Код:
PlayerInfo[playerid][Health] -= amount;
or floatsub
Or, check the specifier in the print, %f to -> %d


Re: Rounding a certain float. - BleverCastard - 05.09.2015

I guess I didn't read up about floatround properly then. However, tried that as well.. It spazzes it out as per the image.

I tried floatsub - floatsub(PlayerInfo[playerid][Health], amount); - and it takes down the client health(good) but not the server health.


Re: Rounding a certain float. - xVIP3Rx - 05.09.2015

Show "OnPlayerTakeDamage" or "OnPlayerGiveDamage"


Re: Rounding a certain float. - BleverCastard - 05.09.2015

Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
{
	floatsub(PlayerInfo[playerid][Health], amount);
    if(weaponid == 4) floatsub(PlayerInfo[playerid][Health], 30);
    if(weaponid == 22) { if(PlayerInfo[playerid][Armour] > 1) { floatround(PlayerInfo[playerid][Armour] -= 25); } else { floatsub(PlayerInfo[playerid][Health], 25); }}
    if(weaponid == 24) { if(PlayerInfo[playerid][Armour] > 1) { floatround(PlayerInfo[playerid][Armour] -= 50); } else { floatsub(PlayerInfo[playerid][Health], 50); }}
    if(weaponid == 30) { if(PlayerInfo[playerid][Armour] > 1) { floatround(PlayerInfo[playerid][Armour] -= 30); } else { floatsub(PlayerInfo[playerid][Health], 30); }}
    if(weaponid == 31) { if(PlayerInfo[playerid][Armour] > 1) { floatround(PlayerInfo[playerid][Armour] -= 45); } else { floatsub(PlayerInfo[playerid][Health], 45); }}
    if(weaponid == 34) { if(PlayerInfo[playerid][Armour] > 1) { floatround(PlayerInfo[playerid][Armour] -= 100); } else { floatsub(PlayerInfo[playerid][Health], 70); }}
    if(weaponid == 29) { if(PlayerInfo[playerid][Armour] > 1) { floatround(PlayerInfo[playerid][Armour] -= 100); } else { floatsub(PlayerInfo[playerid][Health], 70); }}

    if(weaponid == 25) floatsub(PlayerInfo[playerid][Health], 40);
    if(issuerid != INVALID_PLAYER_ID)
   	{
   	    if(weaponid == 0 || weaponid == 1 || weaponid == 2 || weaponid == 3 || weaponid == 4 || weaponid == 5 ||
		    weaponid == 6 || weaponid == 7 || weaponid == 8 || weaponid == 15)
   	    {
   			sInfo[playerid][Misc] += 1;
		}
   	}
  	if(issuerid != INVALID_PLAYER_ID && weaponid == 34 && bodypart == 9)
   	{
		PlayerInfo[playerid][Health] = 0.0;
		SetPlayerHealth(playerid, PlayerInfo[playerid][Health]);
   	}
  	if(issuerid != INVALID_PLAYER_ID && bodypart == 3)
   	{
   		if(weaponid == 22 || weaponid == 23 || weaponid == 24 || weaponid == 25 || weaponid == 26 || weaponid == 27 ||
		    weaponid == 28 || weaponid == 29 || weaponid == 30 || weaponid == 31 || weaponid == 32 || weaponid == 33 || weaponid == 34)
   	    {
   			sInfo[playerid][Chest] += 1;
		}
   	}
  	if(issuerid != INVALID_PLAYER_ID && bodypart == 4)
   	{
   		if(weaponid == 22 || weaponid == 23 || weaponid == 24 || weaponid == 25 || weaponid == 26 || weaponid == 27 ||
		    weaponid == 28 || weaponid == 29 || weaponid == 30 || weaponid == 31 || weaponid == 32 || weaponid == 33 || weaponid == 34)
   	    {
   			sInfo[playerid][Crotch] += 1;
		}
   	}
  	if(issuerid != INVALID_PLAYER_ID && bodypart == 5)
   	{
   		if(weaponid == 22 || weaponid == 23 || weaponid == 24 || weaponid == 25 || weaponid == 26 || weaponid == 27 ||
		    weaponid == 28 || weaponid == 29 || weaponid == 30 || weaponid == 31 || weaponid == 32 || weaponid == 33 || weaponid == 34)
   	    {
   			sInfo[playerid][LArm] += 1;
		}
   	}
  	if(issuerid != INVALID_PLAYER_ID && bodypart == 6)
   	{
   		if(weaponid == 22 || weaponid == 23 || weaponid == 24 || weaponid == 25 || weaponid == 26 || weaponid == 27 ||
		    weaponid == 28 || weaponid == 29 || weaponid == 30 || weaponid == 31 || weaponid == 32 || weaponid == 33 || weaponid == 34)
   	    {
   			sInfo[playerid][RArm] += 1;
		}
   	}
  	if(issuerid != INVALID_PLAYER_ID && bodypart == 7)
   	{
   		if(weaponid == 22 || weaponid == 23 || weaponid == 24 || weaponid == 25 || weaponid == 26 || weaponid == 27 ||
		    weaponid == 28 || weaponid == 29 || weaponid == 30 || weaponid == 31 || weaponid == 32 || weaponid == 33 || weaponid == 34)
   	    {
   			sInfo[playerid][LLeg] += 1;
		}
   	}
  	if(issuerid != INVALID_PLAYER_ID && bodypart == 8)
   	{
   		if(weaponid == 22 || weaponid == 23 || weaponid == 24 || weaponid == 25 || weaponid == 26 || weaponid == 27 ||
		    weaponid == 28 || weaponid == 29 || weaponid == 30 || weaponid == 31 || weaponid == 32 || weaponid == 33 || weaponid == 34)
   	    {
   			sInfo[playerid][RLeg] += 1;
		}
   	}
  	if(issuerid != INVALID_PLAYER_ID && bodypart == 9)
   	{
   		if(weaponid == 22 || weaponid == 23 || weaponid == 24 || weaponid == 25 || weaponid == 26 || weaponid == 27 ||
		    weaponid == 28 || weaponid == 29 || weaponid == 30 || weaponid == 31 || weaponid == 32 || weaponid == 33 || weaponid == 34)
   	    {
         	PlayerInfo[playerid][Health] -= 70;
   			sInfo[playerid][Head] += 1;
		}
   	}
    return 1;
}



Re: Rounding a certain float. - KrazyKidd - 05.09.2015

bump. I want this as well.


Re: Rounding a certain float. - BleverCastard - 06.09.2015

Anyone?


Re: Rounding a certain float. - xVIP3Rx - 06.09.2015

Debug the health value before and after changing it, you're probably doing something wrong in there.


Re: Rounding a certain float. - BleverCastard - 07.09.2015

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
Debug the health value before and after changing it, you're probably doing something wrong in there.
I haven't. Is there any way to convert it to a string to save it as %0.02f? I haven't converted a float to a string before so any help is appreciated.