If the vehicle health lower than 250, remove the player
#1

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;
}
Reply
#2

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);
}
Reply
#3

Not working. I tried that before.
Any idea?
Reply
#4

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;
	}
}
Reply
#5

@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.
Reply
#6

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;
}
Reply
#7

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)