How to get the Killer of a victim in vehicle? -
PawnoQ - 06.10.2014
hi,
as the title says, how can i determine the killer when someone dies in a vehicle.
Lets assume the folowing case:
Player A is the driver of a vehicle.
player B is on foot or also in a vehicle and shots Player A that is in a vehicle.
The vehicle of Player A is on fire (due to high damage) and explodes.
In this case there would be no killer detected by the script.
The killer would be an INVALID_KILLERID.
So how could i get the player ID of the killer of Player A that caused the vehicle of Player A to explode?
Please help me with that issue as i really dont know how to do that.
I already played around with an include from this forum that added a callback called OnVehicleDamage but no success.
Also i tried the Callback OnPlayerWeaponShot but as the wiki page states, this callback doesnt work when the driver is the shooter.
Please, i hope someone can help me with this.
thank you a lot in advance
best regards, pawnoQ
Re: How to get the Killer of a victim in vehicle? -
Ari - 06.10.2014
https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage
or
https://sampwiki.blast.hk/wiki/OnPlayerGiveDamage
or
https://sampwiki.blast.hk/wiki/OnPlayerWeaponShot (BULLET_HIT_TYPE_VEHICLE)
Re: How to get the Killer of a victim in vehicle? -
PawnoQ - 06.10.2014
thx for answer but this isnt solving my problem...
When the players vehicle explodes and the driver dies cause of this, he is taking damage, ok.
And can you please tell me how to determine the killer now?
How to get the ID of the player that actually shot this vehicle and caused it to explode?
Thats the important think i cant get.
I already tried around with those callbacks and distance checking etc but never was really statisfied with the result.
Please help
Re: How to get the Killer of a victim in vehicle? -
Rudy_ - 06.10.2014
OnPlayerGiveDamage - playerid = The ID of the player that gave damage. (Shooter or killer in your sense)
Re: How to get the Killer of a victim in vehicle? -
PawnoQ - 06.10.2014
This callback also works when a player is in vehicle?
So when a player drive bys anohter player in a vehicle and ONLY the vehicle gets damaged this callback would be able to determine the shooter of that vehicle?
I thought this works only for players on foot.
Re: How to get the Killer of a victim in vehicle? -
XStormiest - 06.10.2014
1. I rather prefer use of OnPlayerGiveDamage, instead of OnPlayerTakeDamage.
2. In this case create a global variable with initial value = 0;
3. Check on OnPlayerGiveDamage, if the damagedid is in an vehicle, set the variable that you created with the damagedid, then do whatever you want with that variable.
TIPS: A car explode if vehicle health <= 300 (This may give you an ideea).
Re: How to get the Killer of a victim in vehicle? -
PawnoQ - 06.10.2014
thank you so much
But one question left: If a player sits in a vehicle that is shot, only the vehicle is taking damage, not the player in it!
So does this callback also work for that purpose?
Or is it only called when the player itself takes damage?
Re: How to get the Killer of a victim in vehicle? -
XStormiest - 06.10.2014
IsPlayerInAnyVehicle, checks if the player is in an vehicle, no matter the seat.
It is called when the player takes damage.
Try to check if the player is in an vehicle, but is not an actual driver
pawn Код:
if((IsPlayerInAnyVehicle(damagedid)) && (GetPlayerState(damagedid) != PLAYER_STATE_DRIVER))
{
// if the player is in an car, but not a driver!
// try to work with Health local float variable, since OnPlayerGiveDamage supports a amount float parameter
// Increease health of the player everytime he gets damage +=amount;
// Decrease vehicle health of the vehicle of the player.
}
Im saying this assuming you already know how to script that, if not, learn.
Re: How to get the Killer of a victim in vehicle? -
PawnoQ - 06.10.2014
thanks.
Dont worry about my scripting abbility, i know exactly what you want to tell me
BUT i dont get your method (the idea behind this) as as far as i know, the Callback OnPlayerGiveDamage is ONLY called when a PLAYER is damaged. But a player simply is does NOT take any damage when he is in a vehicle.
Only the vehicle is but the player doesnt take any damage.
Thats the point i do not get.
I really appreciate your help so far
I especially need this for the driver so it isnt helping me if it doesnt work when the driver is the killer.
I need it for a derby mode where all players drive vehicles and are drive bying each other.
Or did i missunderstand you?
Re: How to get the Killer of a victim in vehicle? -
Michael@Belgium - 13.10.2014
You could try to use OnVehicleDeath. And you can find the GetVehicleDriver function around here.
pawn Код:
public OnVehicleDeath(vehicleid, killerid)
{
new string[64];
format(string, sizeof(string), "%s's vehicle (%i) was destroyed by %s (%i).", GetVehicleDriver(vehicleid), vehicleid, pName(killerid), killerid);
SendClientMessageToAll(-1, string);
return 1;
}