SA-MP Forums Archive
Make OnPlayerGiveDamage be called from vehicles - 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: Make OnPlayerGiveDamage be called from vehicles (/showthread.php?tid=491761)



Make OnPlayerGiveDamage be called from vehicles - Gryphus One - 01.02.2014

Just like 0.3z adds as a new feature that OnPlayerGiveDamage is called when you hit NPC's, this callback should also be called when you hit someone with the guns of armed vehicles (like Rustler, Seasparrow, RC Baron, Hunter and Predator), and also when you hit him directly with your vehicle and with helicopter blades. As far as I know, the only situation in which your client calls OnPlayerGiveDamage while driving a vehicle is when driveby shooting.
I think my suggestion should be perfectly possible because you can see in your screen the animation of the other player being hit and dropping blood.


Re: Make OnPlayerGiveDamage be called from vehicles - Danny - 01.02.2014

I fully support your suggestion. This is yet another 'hole' in the SA:MP callback system that can confuse the hell out of people.


Re: Make OnPlayerGiveDamage be called from vehicles - OKStyle - 01.02.2014

Can't you use ...WeaponShot for this?


Re: Make OnPlayerGiveDamage be called from vehicles - Mandrakke - 01.02.2014

with OnPlayerWeaponShot you can detect it and can do, for example, allow players to destroy vehicles without drivers.


pawn Код:
new Float:armaDano;

// Weapons damage, taken from sa-mp wiki.
armasDano[22] = 25;
armasDano[23] = 40;
armasDano[24] = 70;
armasDano[25] = 30;
armasDano[26] = 30;
armasDano[27] = 25;
armasDano[28] = 20;
armasDano[29] = 25;
armasDano[30] = 30;
armasDano[31] = 30;
armasDano[32] = 20;
armasDano[33] = 75;
armasDano[34] = 125;
armasDano[38] = 140;

public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    switch(hittype) {
        case 2: { // When a vehicle hit happens
            new Float:veiculoHp;
            GetVehicleHealth(hitid, veiculoHp);

            if(armasDano[weaponid] > 0 && IsVehicleEmpty(hitid)) {
                new Float:novoHp = veiculoHp - armasDano[weaponid];

                // It is not good to let vehicles explode with nobody driving it because of desync problems.
                if(novoHp > 251) {
                    SetVehicleHealth(hitid, novoHp);
                }
            }
        }
    }
}

stock IsVehicleEmpty(vehicleid)
{
  for(new i; i < MAX_PLAYERS; i++)
  {
    if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i) && GetPlayerVehicleID(i) == vehicleid) return 0;
  }
  return 1;
}



Respuesta: Re: Make OnPlayerGiveDamage be called from vehicles - Gryphus One - 03.02.2014

Quote:
Originally Posted by OKStyle
Посмотреть сообщение
Can't you use ...WeaponShot for this?
No, that callback is not called when you drive vehicles.

Quote:
Originally Posted by Mandrakke
Посмотреть сообщение
with OnPlayerWeaponShot you can detect it and can do, for example, allow players to destroy vehicles without drivers.
Thanks for the code but that's a different matter.


Re: Make OnPlayerGiveDamage be called from vehicles - Scenario - 03.02.2014

Or, the alternative, let "OnPlayerWeaponShot" work when players are in a vehicle.


Respuesta: Re: Make OnPlayerGiveDamage be called from vehicles - Gryphus One - 03.02.2014

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
Or, the alternative, let "OnPlayerWeaponShot" work when players are in a vehicle.
That would be the best thing, and it has already been reported here, but I think there's a reason why that won't be possible.