Map Icon/Car damage help
#9

Quote:
Originally Posted by Threshold
Посмотреть сообщение
You can use the callback 'OnPlayerWeaponShot' for that. Although take note that weapons such as baseball bats and chainsaws and weapons that aren't necessarily "Shot" will not be valid for use in this callback.

An example:
pawn Код:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(hittype == BULLET_HIT_TYPE_VEHICLE) //If the player's shot hit a vehicle
    {
        new bool:occupied = false, Float:HIT_DAMAGE = 25.0; //Vehicle is NOT occupied by default. If we do hit the vehicle, hit damage will do 25.0 damage.
        for(new i = 0; i < MAX_PLAYERS; i++) //Loop through all players.
        {
            if(!IsPlayerConnected(i)) continue; //Skip players that aren't connected.
            if(IsPlayerInVehicle(i, hitid) && GetPlayerState(i) == PLAYER_STATE_DRIVER) //If the player is driving the vehicle we shot.
            {
                occupied = true; //The vehicle we shot was occupied by a driver.
                break; //Break the loop, as we already know someone was driving.
            }
        }
        if(!occupied) //If the vehicle was not occupied by a driver...
        {
            new Float:CarHealth; //A variable to store the vehicle's original health.
            GetVehicleHealth(hitid, CarHealth); //Get the vehicle's current health.
            if((CarHealth - HIT_DAMAGE) > 0) SetVehicleHealth(hitid, CarHealth - HIT_DAMAGE); //Apply the hit damage to the vehicle to reduce its health.
        }
    }
    return 1;
}
Note that 'HIT_DAMAGE' is the amount of damage that each bullet will do to the vehicle. Feel free to change this as you wish, as you can also do variable damages depending on what weapon the player is using.

References:
https://sampwiki.blast.hk/wiki/OnPlayerWeaponShot
THANKS!
Reply


Messages In This Thread
Map Icon/Car damage help - by Thoma - 13.01.2015, 10:51
Re: Map Icon/Car damage help - by ATGOggy - 13.01.2015, 10:56
Re: Map Icon/Car damage help - by Thoma - 13.01.2015, 11:05
Re: Map Icon/Car damage help - by ATGOggy - 13.01.2015, 11:08
Re: Map Icon/Car damage help - by Thoma - 13.01.2015, 11:14
Re: Map Icon/Car damage help - by ATGOggy - 13.01.2015, 11:19
Re: Map Icon/Car damage help - by Thoma - 13.01.2015, 11:26
Re: Map Icon/Car damage help - by Threshold - 13.01.2015, 11:57
Re: Map Icon/Car damage help - by Thoma - 13.01.2015, 11:59

Forum Jump:


Users browsing this thread: 1 Guest(s)