Stop a player dying
#1

I have a problem that is really bugging me, and ****** doesn't seem to have answers.

I want to prevent a player dying when they are in a rhino (tank), because if you shoot a HS missile at the tank, it will kill the player, despite them being in the vehicle. I have "OnPlayerTakeDamage" set up so that when a player takes damage, and they are inside a rhino, their health will be restored to what it was.

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    print("damage taken");
    new vehicleid = GetPlayerVehicleID(playerid);
    if(vehicleid != INVALID_VEHICLE_ID){
        new modelid = GetVehicleModel(vehicleid);
        if(modelid == 432){
            print("in vehicle");
            new Float: health;
            GetPlayerHealth(playerid, health);
            SetPlayerHealth(playerid, (health + amount));
        }
    }

    return 1;
}
However, if the HS missile is well aimed, it will take all of the players health in one go, and the player will die before their health is restored, despite the fact that the rhino may not have blown up.

Effectively, what I wan't to do is make it such that when a player is in a rhino, they are untouchable until either they exit it, or someone blows the rhino.

This problem is really bugging me, and I will rep++ anyone who can help me find a decent solution.
Reply
#2

Try this code
Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    print("Demage Taken");
	if (IsPlayerInVehicle(playerid, 432))
	{
	    print("In Vehicle");
        new
			Float: health,
			seat = GetPlayerVehicleSeat(playerid),
			vehicleid = GetPlayerVehicleID(playerid);
			
        GetPlayerHealth(playerid, health);
        SetPlayerHealth(playerid, health + amount);

		if (GetPlayerState(playerid) != PLAYER_STATE_DRIVER || GetPlayerState(playerid) != PLAYER_STATE_PASSENGER)
		{
			PutPlayerInVehicle(playerid, vehicleid, seat);
		}
	}
    return 1;
}
Reply
#3

why don't you just check when the player enters a rhino and set their health to 9999999?

Like this

Global variable (Goes at the top of the gamemode)
PHP код:
new Health[MAX_PLAYERS]; 
PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    if(
GetVehicleModel(vehicleid) == 432)
    {
         
Health[playerid] == GetPlayerHealth(playerid);
         
SetPlayerHealth(playerid9999999);
    }
    return 
1;

Then check when the player exits the vehicle and set back their health.

PHP код:
public OnPlayerExitVehicle(playeridvehicleid)
{
    if(
GetVehicleModel(vehicleid) == 432)
    {
         
SetPlayerHealth(playeridHealth[playerid]);
     }
    return 
1;

**Untested code.
Reply
#4

If the player dies it doesn't matter if you set their health back they are dead I'm pretty sure this happens when the vehicle it's self blows up so you should try setting the vehicle health really high.

@[CG]Milito Doesn't matter how much health the player has if the vehicle explodes the player dies.
Reply
#5

Set the vehicle health to infinity(?) - Not sure if this'll work..
Reply
#6

Thanks team, for your replies, I just did some testing with the ideas you suggested, and it turns out that as soon as another player can cause the rhino to catch fire (it doesn't have to explode immediately) it will stop protecting the player in it, and they will die even if they have infinite health, and they will be vulnerable when the rhino catches fire, they don't have to wait until it explodes.

Quote:

If the player dies it doesn't matter if you set their health back they are dead I'm pretty sure this happens when the vehicle it's self blows up so you should try setting the vehicle health really high.

The solution was, as Pottus suggested, to set the vehicle health to something excessive (but not infinity, as I don't want to make the rhino invulnerable, just a little harder to kill), and my problem is solved

Once again, thanks all for your help!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)