OnVehicleDeath - Getting vehicle killer -
Michael@Belgium - 09.03.2013
I have a kind of an issue here... I'm trying to get the vehicle killer - the problem is, the killer is
always in a car. (Derby server) My question is: how to get that driver/killer who pushed/exploded someone in the water or someone in another vehicle ?
Using OnVehicleDeath don't work.
pawn Код:
#define Loop(%0,%1) for(new %0 = 0; %0 < %1; %0++)
public OnVehicleDeath(vehicleid, killerid)
{
new string[128];
if (killerid != GetVehicleDriver(vehicleid) && (GetVehicleDriver(vehicleid) != INVALID_PLAYER_ID || killerid != INVALID_PLAYER_ID))
{
format(string, sizeof(string), "[KILL] - %s was killed by %s.", PlayerName(GetVehicleDriver(vehicleid)), PlayerName(killerid));
SendClientMessageToAll(COLOR_RED,string);
}
return 1;
}
stock GetVehicleDriver(vehicleid)
{
new vehicleDriver = INVALID_PLAYER_ID;
Loop(i,MAX_PLAYERS)
{
if(IsPlayerConnected(i))
{
if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
{
if(GetPlayerVehicleID(i) == vehicleid) vehicleDriver = i; break;
}
}
}
return vehicleDriver;
}
99% i get this:
Quote:
[14:54:18] [KILL] - was killed by person1.
|
How can the driver
be the killer anyway ?!
Re: OnVehicleDeath - Getting vehicle killer -
MP2 - 10.03.2013
I've been waititing since 2007 for this to be supported by SA-MP. Perhaps in 0.4.
Re: OnVehicleDeath - Getting vehicle killer -
Marco_Valentine - 10.03.2013
You could try code it with OnVehicleDamageStatusUpdate.
Like when a players vehicle gets damaged, store the closests players id, then on vehicle death the last id stored for who damaged that vehicle is declared the killer of the vehicle.
Re: OnVehicleDeath - Getting vehicle killer -
MP2 - 10.03.2013
That is only called for visual damage. Players will only visually damage a vehicle if they crash in to them. It won't do anything for weapons.
It would actually be very possible to script this using keys, camera vectors and OPU or a timer, but not exactly straightforward or reliable.
Re: OnVehicleDeath - Getting vehicle killer -
Sinner - 10.03.2013
There really is no way of knowing who destroyed a vehicle. You can make a (pretty accurate) guess though. For a dery server, try contstantly storing the last player to be closest to the player who died -- in 80% of the cases this player was the one that caused the explosion/push. When the player then dies, you can easily see who was the killer.
Native support would be nice though.
Re: OnVehicleDeath - Getting vehicle killer -
RajatPawar - 10.03.2013
You could probably loop and see GetVehicleHealth repeatedly and subtract the health from the damage and if it's below 0 or 0, get the closest player nearby in a vehicle. It will be inaccurate, but, okie dokie !
(Use something like OnPlayerVehicleDamage)
Re: OnVehicleDeath - Getting vehicle killer -
Michael@Belgium - 10.03.2013
Quote:
Originally Posted by MP2
That is only called for visual damage. Players will only visually damage a vehicle if they crash in to them. It won't do anything for weapons.
It would actually be very possible to script this using keys, camera vectors and OPU or a timer, but not exactly straightforward or reliable.
|
Woah, don't make it to hard with keys, vectors, timers etc
![Tongue](images/smilies/razz.gif)
The less code, the better :3
Quote:
Originally Posted by Sinner
There really is no way of knowing who destroyed a vehicle. You can make a (pretty accurate) guess though. For a dery server, try contstantly storing the last player to be closest to the player who died -- in 80% of the cases this player was the one that caused the explosion/push. When the player then dies, you can easily see who was the killer.
Native support would be nice though.
|
Hmm, not a bad idea...
Quote:
Originally Posted by Rajat_Pawar
You could probably loop and see GetVehicleHealth repeatedly and subtract the health from the damage and if it's below 0 or 0, get the closest player nearby in a vehicle. It will be inaccurate, but, okie dokie ! (Use something like OnPlayerVehicleDamage)
|
I think this is slower than Sinners idea.