SA-MP Forums Archive
If the vehicle health lower than 250, remove the player - 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: If the vehicle health lower than 250, remove the player (/showthread.php?tid=548356)



If the vehicle health lower than 250, remove the player - Lucky™ - 29.11.2014

Well I was trying to do this with no luck.

I want to detect if the vehicle health is lower than 300, then remove the player from that vehicle. It sounds easy but I can't make it work with this.

Can I add it into this function? or should I write a new one?

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
    if(IsABumperCar(vehicleid))
    {
        new string[128];
        if(!pChip[playerid])
        {
            format(string,sizeof(string),"* You need a chip to drive a Bumper Car");
            TogglePlayerControllable(playerid,0);
            ClearAnimations(playerid);
            TogglePlayerControllable(playerid,1);
            SendClientMessage(playerid,0xFFFFFFAA,string);
        }
        if(IsVehicleOccupied(vehicleid))
        {
            format(string,sizeof(string),"* This Bumper Car is occupied! Please take another one.");
            TogglePlayerControllable(playerid,0);
            ClearAnimations(playerid);
            TogglePlayerControllable(playerid,1);
            SendClientMessage(playerid,0xFFFFFFAA,string);
        }
    }
    return 1;
}



Re: If the vehicle health lower than 250, remove the player - Raweresh - 29.11.2014

You can add this into your callback.
Код:
new Float:Health;
GetVehicleHealth(vehicleid,Health);
if(Health < 300.0)
{
	new Float:X;
	new Float:Y;
	new Float:Z;
	GetPlayerPos(playerid,X,Y,Z);
	SetPlayerPos(playerid,X,Y,Z);
}



Re: If the vehicle health lower than 250, remove the player - Lucky™ - 29.11.2014

Not working. I tried that before.
Any idea?


Re: If the vehicle health lower than 250, remove the player - Raweresh - 29.11.2014

Maybe something like that?
Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
	if(newstate == PLAYER_STATE_DRIVER)
	{
		new Float:Health;
		GetVehicleHealth(GetPlayerVehicleID(playerid),Health);
		if(Health < 300.0)
		{
			new Float:X;
			new Float:Y;
			new Float:Z;
			GetPlayerPos(playerid,X,Y,Z);
			SetPlayerPos(playerid,X,Y,Z);
		}
		return 1;
	}
}



Re: If the vehicle health lower than 250, remove the player - LivingLikeYouDo - 29.11.2014

@Raweresh - Why not RemovePlayerFromVehicle?

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new Float:health;
        GetVehicleHealth(GetPlayerVehicleID(playerid), health);
        if(health < 300.0)
        {
            printf("DEBUG: Removed player %d from vehicle due to low health", playerid); //For debug purposes (optional)
            RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;
}
Should work^^ If the player is not removed from the vehicle and the debug is shown, please post below.


Re: If the vehicle health lower than 250, remove the player - Lucky™ - 29.11.2014

Quote:
Originally Posted by LivingLikeYouDo
Посмотреть сообщение
@Raweresh - Why not RemovePlayerFromVehicle?

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new Float:health;
        GetVehicleHealth(GetPlayerVehicleID(playerid), health);
        if(health < 300.0)
        {
            printf("DEBUG: Removed player %d from vehicle due to low health", playerid); //For debug purposes (optional)
            RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;
}
Should work^^ If the player is not removed from the vehicle and the debug is shown, please post below.
Thanks but still it's not removing the player from the vehicle.

Here's my current OnPlayerStateChange, if you want it.

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if((newstate == PLAYER_STATE_DRIVER) && IsABumperCar(GetPlayerVehicleID(playerid)))
    {
        if(!pChip[playerid] || bRoundStarted) { RemovePlayerFromVehicle(playerid); }
        else
        {
            SendClientMessage(playerid,0xFFFFFFAA,"* You inserted your chip into the car");
            SendClientMessage(playerid,0xFFFFFFAA,"* Please wait for the next round.");
            pChip[playerid]=0;
            TogglePlayerControllable(playerid,0);
        }
    }
    return 1;
}



Re: If the vehicle health lower than 250, remove the player - biker122 - 29.11.2014

maybe this:
pawn Код:
public OnPlayerUpdate(playerid)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new id = GetPlayerVehicleID(playerid);
        if(GetVehicleHealth(id) < 300)
        {
            SendClientMessage(playerid, 0xFFFFFFAA, "* You're being removed from your vehicle as it has less health!");
            RemovePlayerFromVehicle(playerid);
        }  
    }
    return 1;
}