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