Custom vehicle damage
#1

I find deagle and combat shotgun very unrealistic while shooting other vehicles.
So is there a way to make a custom damage system on vehicles? Like OnPlayerShootVehicle(playerid, issuerid, Float:damage) or something like that?
Reply
#2

You could use this callback:

pawn Код:
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
and use GetPlayerWeapon and SetVehicleHealth and/or UpdateVehicleDamageStatus
Reply
#3

But how can i retrieve the damage that ha been dealt to the vehicle?
Reply
#4

I think that the weapon deals the same damage to both the player and the vehicle.
So, calculate how much damage does a shotgun to the player and then when you shoot with a shotgun on the car
+- veh hp... Or something like that
Reply
#5

Shotguns does different amounts of damage depending how many bullets hit the vehicle, and it would take a very long time to calculate this for every weapon.
It's very easy having a custom damage script for players.
pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid, bodypart)
{
    new Float:health;
    GetPlayerHealth(playerid, health);
    SetPlayerHealth(playerid, health + amount);
    return 1;
}
This will just give them the health back they were damaged of, and then you can set new values of damage for each weapon.
But how do you do this with vehicles? There must be a way, or maybe an include someone has made for this?
Reply
#6

Quote:
Originally Posted by Schneider
Посмотреть сообщение
You could use this callback:

pawn Код:
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
and use GetPlayerWeapon and SetVehicleHealth and/or UpdateVehicleDamageStatus
OnVehicleDamageStatusUpdate is called when a vehicle takes 'visual damage'... as the wiki clearly states:
Quote:
Originally Posted by SA-MP Wiki
This callback is called when a vehicle element such as doors, tires, panels, or lights get damaged.

NOTE: This does not include vehicle health changes
There is a callback for this...
OnPlayerWeaponShot which is called when a player fires a weapon that can be 'shot'. I believe this excludes rocket launchers, fire extinguishers, melee weapons etc.

There are two ways to approach this. You can do a loop every time OnPlayerWeaponShot is called for a vehicle hit (which is not recommended in my opinion), or you can simply update a variable when it's necessary like OnPlayerStateChange for example.

pawn Код:
new bool:VehicleOccupied[MAX_VEHICLES] = false;
new LastVehicle[MAX_PLAYERS] = INVALID_VEHICLE_ID;

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new vid = GetPlayerVehicleID(playerid);
        VehicleOccupied[vid - 1] = true;
        LastVehicle[playerid] = vid;
    }
    if(oldstate == PLAYER_STATE_DRIVER)
    {
        VehicleOccupied[LastVehicle[playerid] - 1] = false;
        LastVehicle[playerid] = INVALID_VEHICLE_ID;
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(LastVehicle[playerid] != INVALID_VEHICLE_ID) VehicleOccupied[LastVehicle[playerid] - 1] = false;
    return 1;
}

public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(!(22 <= weaponid <= 38)) return 1; //Small anti to prevent hackers crashing other clients.
    if(hittype == BULLET_HIT_TYPE_VEHICLE) //Player hit a vehicle
    {
        if(1 <= hitid <= MAX_VEHICLES)
        {
            if(!VehicleOccupied[(hitid - 1)])
            {
                new Float:VehHealth, Float:damage = 25.0;
                GetVehicleHealth(hitid, VehHealth);
                switch(weaponid)
                {
                    case 24: damage = 100.0; //If shot with desert eagle (24), do 100.0 damage.
                    case 31: damage = 75.0; //If shot with an M4 (31), do 75.0 damage.
                    case 34: damage = 150.0; //If shot with a sniper (34) do 150.0 damage.
                }
                //Damage is 25.0 by default when declared, this can be changed.
                SetVehicleHealth(hitid, VehHealth - damage);
                return 0;
            }
        }
    }
    return 1;
}
Sorry, I got carried away... but this should work. You can change the damages however you want.

References:
https://sampwiki.blast.hk/wiki/Weapons
https://sampwiki.blast.hk/wiki/OnPlayerWeaponShot
https://sampwiki.blast.hk/wiki/OnPlayerStateChange

EDIT: I think this filterscript covers realistic weapon damage:
https://sampforum.blast.hk/showthread.php?tid=488131
Reply
#7

Oh yeah, thanks Threshold.
I also totally forgot about returning 0 to stop the damage, i was too obsessed thinking how to + the damage given, to negate the damage.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)