Lose HP when car crashe
#1

I'm trying to do a system to when player crashes the car he loses life...
But i'm failed

What i tried?
PHP код:
public OnDynamicVehDamageStatusUpdate(vehicleidplayerid) {
    
// comp 1
    
GetDynamicVehicleHealth(vehicleidvHPcintoA[vehicleid]);
    if(
vHPcintoA[vehicleid] < vHPcintoB[vehicleid])
    {
        
// losing life
        
new Float:danoplayerbatida = (vHPcintoB[vehicleid] - vHPcintoA[vehicleid]) / 100;
        
vida[playerid] -= danoplayerbatida;
        new 
dmgstring[20];
        
format(dmgstringsizeof(dmgstring), "~r~%i.0"danoplayerbatida );
        
GameTextForPlayer(playeriddmgstring10003);
    }
    
// comp 2
    
GetDynamicVehicleHealth(vehicleidvHPcintoB[vehicleid]);

So if player loses 500 vehicle hp, vida[playerid] -= 50;
But its not happen...

GameTextForPlayer is showing a value like:
Something like 106150650

And nothing happen...
Reply
#2

Float:danoplayerbatida

%i.0


An integer with 0 decimals, but in reality is a float with decimals? Rip errors if format would've returned errors.


%f.0 instead of %i.0
Reply
#3

Quote:
Originally Posted by Meller
Посмотреть сообщение
Float:danoplayerbatida

%i.0


An integer with 0 decimals, but in reality is a float with decimals? Rip errors if format would've returned errors.


%f.0 instead of %i.0
I'm don't got, I'm sorry, what are you mean?
Reply
#4

he meant that you are formatting in a wrong way.
PHP код:
new Float:danoplayerbatida = (vHPcintoB[vehicleid] - vHPcintoA[vehicleid]) / 100
//here you have declared it as a float
format(dmgstringsizeof(dmgstring), "~r~%i.0"danoplayerbatida ); 
//and here in this line you are formatting as a integer but instead the proper way would be formatting it as a float with 0 decimal places. 
Here is the corrected line
PHP код:
format(dmgstringsizeof(dmgstring), "~r~%.0f"danoplayerbatida ); 
Reply
#5

Try this?

Код:
public OnPlayerUpdate(playerid)
{
	if(GetPlayerState(playerid) == 2)
	{
		new Float:vehHealth;// we create a new var (type Float value 0.0)
		new Float:playerArmour;//we create a new var (type floatvalue 0.0)
		new curentVeh = GetPlayerVehicleID(playerid);//Get the vehicle (id) of the player (and store it in curentVeh)
		GetVehicleHealth(curentVeh, vehHealth);//Get the vehicle health and store it in vehHealth(value returned e.g: 2500.2)
		vehHealth = vehHealth/10;// we divide the value of vehHealth per 10
		SetPlayerHealth(playerid, vehHealth);//Set the health of the vehicle at the health of the player(value e.g : 250)
		if(GetPlayerArmour(playerid,playerArmour) != 0)// if the armour of the playerArmour is not equal at 0 (player have armour)
		{
		SetPlayerArmour(playerid,0);//Set the armour ofthe player at 0 ("delete his armour")
		SetPlayerHealth(playerid, vehHealth);//Set the health of the vehicle at the health of the player
		}
	}

}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)