Is it possible to detect when two vehicles collide?
#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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)