05.12.2017, 07:30
Using ColAndreas in this case will be more accurate.
Code:
public OnVehicleDeath(vehicleid, killerid) { new Float:health, Float:depth, Float:vehicledepth; GetVehicleHealth(vehicleid, health); if(health >= 250.0 && !CA_IsVehicleInWater(vehicleid, depth, vehicledepth)) { return 0; // we prevent respawn } return 1; }
Code:
stock CA_IsVehicleInWater(vehicleid, &Float:depth, &Float:vehicledepth) { new Float:x, Float:y, Float:z, Float:retx[10], Float:rety[10], Float:retz[10], Float:retdist[10], modelids[10]; GetVehiclePos(vehicleid, x, y, z); new collisions = CA_RayCastMultiLine(x, y, z + 1000.0, x, y, z - 1000.0, retx, rety, retz, retdist, modelids, 10); if(collisions) { for(new i = 0; i < collisions; i++) { if(modelids[i] == WATER_OBJECT) { depth = INFINITY; for(new j = 0; j < collisions; j++) { if(retz[j] < depth) depth = retz[j]; } depth = retz[i] - depth; if(depth < 0.001 && depth > -0.001) depth = 100.0; vehicledepth = retz[i] - z; if(vehicledepth < -2.0) return 0; return 1; } } } return 0; }