SA-MP Forums Archive
if SetVehicleHealth? - 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 SetVehicleHealth? (/showthread.php?tid=332478)



if SetVehicleHealth? - Gooday - 08.04.2012

I would like to; If the car health is <400 the player got RemovePlayerFromVehicle....How?


Re: if SetVehicleHealth? - Jeffry - 08.04.2012

pawn Код:
new Float:health;
GetVehicleHealth(GetPlayerVehicleID(playerid), health);
if(health < 400.0) RemovePlayerFromVehicle(playerid);



Re: if SetVehicleHealth? - Gooday - 08.04.2012

Under what Callback should i Add this?


Re: if SetVehicleHealth? - Jeffry - 08.04.2012

Quote:
Originally Posted by Gooday
Посмотреть сообщение
Under what Callback should i Add this?
You want that for every player and every car?


Re: if SetVehicleHealth? - Reklez - 08.04.2012

You can add it OnPlayerUpdate or you can just create a timer


Re: if SetVehicleHealth? - Gooday - 08.04.2012

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
You want that for every player and every car?
Except the players with skin 50.... And all the cars


Re: if SetVehicleHealth? - Jeffry - 08.04.2012

Alright. Then you need a timer to put at OnGameModeInit/OnFilterScriptInit (Depending on if you use a GM or FS).
pawn Код:
SetTimer("CheckHealth", 1000, 1); //Timer which gets called every second
And then you have to add at the bottom of your GM/FS:
pawn Код:
forward CheckHealth();
public CheckHealth()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerInAnyVehicle(i) && GetPlayerSkin(i) != 50)
        {
            new Float:health;
            GetVehicleHealth(GetPlayerVehicleID(i), health));
            if(health < 400.0)
            {
                RemovePlayerFromVehicle(i);
                SendClientMessage(i, COLOR_BLUE, "[Vehicle] You were removed from your vehicle because it had less than 400 health points.");
            }
        }
    }
    return 1;
}