SA-MP Forums Archive
Give - health when car collides - 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: Give - health when car collides (/showthread.php?tid=358725)



[SOLVED - Give - health when car collides] (solved code in last post) - Jstylezzz - 11.07.2012

Hi everyone,

I would like to give -2 health when a car collides and a variable is not 1.
I made a seatbelt system mysself already, and, i am Using FALLOUTS Players Damage on Car Damage function.
Problem is with this functions, it kills you when car health is set to 250, and also dies when the car respawns and the player is in it.

Does anyone know hot o give player - health ONLY when driving into something?

Thanks

((I Used search already, so don't tell me i have to search and stuff..))


Re: Give - health when car collides - Captain_Mani - 11.07.2012

Код:
new Float:health;
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	new playerstate = GetPlayerState(playerid);
	if (playerstate == PLAYER_STATE_ONFOOT)
	GetPlayerHealth(playerid, health);
	
	
	SetPlayerHealth(playerid, 100);
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
   SetPlayerHealth(playerid, health);
	return 1;
}
+Rep me if I helped you.


Re: Give - health when car collides - clarencecuzz - 11.07.2012

1) That code would do nothing but heal the player.
2) The posted is asking if you can damage the player if the car crashes or runs into an object, like in GTA IV.

My opinion on this is, I don't actually think there's a code to detect if a car has hit an object, the only thing I can think of is using GetVehicleHealth and SetPlayerHealth.


Re: Give - health when car collides - Andregood - 11.07.2012

You can do this actually, I've seen it before.


Re: Give - health when car collides - clarencecuzz - 11.07.2012

Feel free to post links if you've seen it...


Re: Give - health when car collides - Jstylezzz - 11.07.2012

Quote:
Originally Posted by clarencecuzz
Посмотреть сообщение
1) That code would do nothing but heal the player.
2) The posted is asking if you can damage the player if the car crashes or runs into an object, like in GTA IV.

My opinion on this is, I don't actually think there's a code to detect if a car has hit an object, the only thing I can think of is using GetVehicleHealth and SetPlayerHealth.
That's the problem, i already have something that gives player -health when the car gets -health, but the problem is when i SetCarHealth, it kills the player, also when the car respawns when the player is in it, it kills the player...

EDIT: For people interested, I fixed it, and this is the code:
pawn Код:
//Credits to FALLOUT for this code, credits to Jari_Johnson* for finding out that if you just place it inside this //callback that it also works lol
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
    if(IsPlayerInAnyVehicle(playerid) == 1 && Seatbelt[playerid] == 0)
    {
        new Float:TempCarHealth;
        GetVehicleHealth(GetPlayerVehicleID(playerid), TempCarHealth);
        new Float:Difference = floatsub(CarHealth[playerid], TempCarHealth);
        if((floatcmp(CarHealth[playerid], TempCarHealth) == 1) && (floatcmp(Difference,100.0) == 1))
        {
            Difference = floatdiv(Difference, 10.0);
            new Float:OldHealth;
            GetPlayerHealth(playerid, OldHealth);
            SetPlayerHealth(playerid, floatsub(OldHealth, Difference));
        }
        CarHealth[playerid] = TempCarHealth;
    }
    else
    {
        CarHealth[playerid] = 0.0; //To aviod that a player dies when he enters a vehicle
    }
    return 1;
}