Is it possible to detect when two vehicles collide?
#1

If so how?
Reply
#2

Using GetVhiclePos and GetVehicleVelocity, but will be inaccurate.
Reply
#3

pawn Код:
new WasDamaged[MAX_VEHICLES];

public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
    WasDamaged[vehicleid-1] = 1; //because vehicleids start with 1 and end with MAX_VEHICLES and not before that
    for (new id = 0; id < MAX_VEHICLES; id++)
    {
        if (id == vehicleid-1) continue;
        if (WasDamaged[id] == 1)
        {
            new Float:x, Float:y, Float:z;
            GetVehiclePos(id+1, x, y, z);
            if (IsVehicleInRangeOfPoint(vehicleid, 1.0, x, y, z))
            {
                printf("Vehicle with ID: %d crashed/was crashed by vehicle with ID: %d", vehicleid, id+1);
            }
        }
    }
    SetTimerEx("Reset", 1000, 0, "d", vehicleid);
    return 1;
}

forward Reset(vehicleid);
public Reset(vehicleid) WasDamaged[vehicleid-1] = 0;

IsVehicleInRangeOfPoint(vehicleid, Float:range, Float:x, Float:y, Float:z)
{
    new Float:px, Float:py, Float:pz;
    GetVehiclePos(vehicleid, px, py, pz);
    px -= x;  py -= y;  pz -= z;
    return ((px * px) + (py * py) + (pz * pz)) < (range * range);
}
Note that this can be buggy and that minor crashes probably wont get detected, only ones which make visible damage
Reply
#4

maybe a check for other players in range of <10 units in this callback would do it?
Код:
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
	new string[128];
	format(string,sizeof(string),"Vehicle ID %d damaged by playerid %d.",vehicleid,playerid);
	return 1;
}
the only small problem is: its printing out the vehicle owner of the damaged vehicle, not the causing player.
when someone shoots the car, it loses health, but the driver caused the damge. cant be real.
i tried to do an accurate solution, but i am stuck at this too.
due to that callback is called twice when cars collides, i tried to make a sort of counter for local accidents. but i failed. maybe someone else can solve that lol
Reply
#5

Checking who has shot the car for instance can be only be done with using OnPlayerKeyStateChange. If someone presses the fire button while holding a gun and aiming at the car he is the one causing the damage (only goes for weapons that turn the whole body towards the aiming direction).
Reply
#6

Quote:

When two vehicles collide?

XD, I already done the gun part
Reply
#7

Quote:

when someone shoots the car, it loses health, but the driver caused the damge. cant be real.
i tried to do an accurate solution, but i am stuck at this too.

Ehm yeah, whatever then.


When two vehicles collide they must be very close to each other. Check the range of distances between two vehicles when they are directly next to each other by doing some tests.

As soon as a two vehicles crash into each other you just check upon OnVehicleDamageStatusUpdate whether a vehicle is in direct contact. To improve inappropriate triggers you can additionally check for damages on the possibly detected nearby vehicle, connect it to timestamps or whatsoever.
Reply
#8

Quote:
Originally Posted by juice.j
Quote:

when someone shoots the car, it loses health, but the driver caused the damge. cant be real.
i tried to do an accurate solution, but i am stuck at this too.

Ehm yeah, whatever then.


When two vehicles collide they must be very close to each other. Check the range of distances between two vehicles when they are directly next to each other by doing some tests.

As soon as a two vehicles crash into each other you just check upon OnVehicleDamageStatusUpdate whether a vehicle is in direct contact. To improve inappropriate triggers you can additionally check for damages on the possibly detected nearby vehicle, connect it to timestamps or whatsoever.
You could even make an array for every vehicle / have the distance custom for every vehicle (dumper and a faggio shouldnt have thew same range). Its a lot of work, but it would make it more accurate.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)