diff --git a/Server/include/colandreas.inc b/Server/include/colandreas.inc index 6fce4d7..ad540ab 100644 --- a/Server/include/colandreas.inc +++ b/Server/include/colandreas.inc @@ -893,6 +893,51 @@ stock CA_RemoveBreakableBuildings() return 1; } +/**--------------------------------------------------------------------------**\ + + CA_IsPointInWater + +Point to be checked +The lowest collision point found +How deep the point is below the surface + + 0 if the point is not in water + 1 if the point is in water + +\**--------------------------------------------------------------------------**/ +stock CA_IsPointInWater(Float:x, Float:y, Float:z, &Float:depth = 0.0, &Float:pointdepth = 0.0) +{ + new Float:retx[10], Float:rety[10], Float:retz[10], Float: retdist[10], modelids[10]; + new collisions = CA_RayCastMultiLine(x, y, z+1000.0, x, y, z-1000.0, retx, rety, retz, retdist, modelids, 10); + if(collisions > 0) + { + for(new i = 0, j = 0; i < collisions; i++) + { + if(modelids[i] == WATER_OBJECT) + { + depth = FLOAT_INFINITY; + + for(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; + pointdepth = retz[i] - z; + + if(pointdepth < -2.0) + return 0; + + return 1; + } + } + } + return 0; +} + /**--------------------------------------------------------------------------**\ CA_IsPlayerInWater @@ -905,7 +950,7 @@ stock CA_RemoveBreakableBuildings() 1 if the player is in water \**--------------------------------------------------------------------------**/ -stock CA_IsPlayerInWater(playerid, &Float:depth, &Float:playerdepth) +stock CA_IsPlayerInWater(playerid, &Float:depth = 0.0, &Float:playerdepth = 0.0) { new Float:x, Float:y, Float:z, Float:retx[10], Float:rety[10], Float:retz[10], Float: retdist[10], modelids[10]; GetPlayerPos(playerid, x, y, z); @@ -951,7 +996,7 @@ stock CA_IsPlayerInWater(playerid, &Float:depth, &Float:playerdepth) 1 if the vehicle is in water \**--------------------------------------------------------------------------**/ -stock CA_IsVehicleInWater(vehicleid, &Float:depth, &Float:vehicledepth) +stock CA_IsVehicleInWater(vehicleid, &Float:depth = 0.0, &Float:vehicledepth = 0.0) { 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); @@ -1362,6 +1407,9 @@ CA_RemoveBarriers() Removes all dynamic breakable objects, also only works BEFORE using CA_Init() CA_RemoveBreakableBuildings() +Checks if a point is in the water +CA_IsPointInWater(Float:x, Float:y, Float:z, &Float:depth, &Float:pointdepth) + Checks if a player is in the water CA_IsPlayerInWater(playerid, &Float:depth, &Float:playerdepth) @@ -1397,4 +1445,4 @@ Recommended loading order There is currently no support for virtual worlds / interior or per player with streamer objects -*/ +*/ \ No newline at end of file