colandreas.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. // Used for other scripts to check if ColAndreas is being used
  2. #if defined COLANDREAS
  3. #endinput
  4. #endif
  5. #define COLANDREAS
  6. #define COLANDREAS_VERSION (10400) //a.b.c 10000*a+100*b+c
  7. // Default extra ID types
  8. #define CA_EXTRA_1 0
  9. #define CA_EXTRA_2 1
  10. #define CA_EXTRA_3 2
  11. #define CA_EXTRA_4 3
  12. #define CA_EXTRA_5 4
  13. #define CA_EXTRA_6 5
  14. #define CA_EXTRA_7 6
  15. #define CA_EXTRA_8 7
  16. #define CA_EXTRA_9 8
  17. #define CA_EXTRA_10 9
  18. // Natives
  19. native CA_Init();
  20. native CA_RemoveBuilding(modelid, Float:x, Float:y, Float:z, Float:radius);
  21. native CA_RayCastLine(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z);
  22. native CA_RayCastLineID(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z);
  23. native CA_RayCastLineExtraID(type, Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z);
  24. native CA_RayCastMultiLine(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, Float:retx[], Float:rety[], Float:retz[], Float:retdist[], ModelIDs[], size = sizeof(retx));
  25. native CA_RayCastLineAngle(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z, &Float:rx, &Float:ry, &Float:rz);
  26. native CA_RayCastReflectionVector(Float:startx, Float:starty, Float:startz, Float:endx, Float:endy, Float:endz, &Float:x, &Float:y, &Float:z, &Float:nx, &Float:ny, &Float:nz);
  27. native CA_RayCastLineNormal(Float:startx, Float:starty, Float:startz, Float:endx, Float:endy, Float:endz, &Float:x, &Float:y, &Float:z, &Float:nx, &Float:ny, &Float:nz);
  28. native CA_ContactTest(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  29. native CA_EulerToQuat(Float:rx, Float:ry, Float:rz, &Float:x, &Float:y, &Float:z, &Float:w);
  30. native CA_QuatToEuler(Float:x, Float:y, Float:z, Float:w, &Float:rx, &Float:ry, &Float:rz);
  31. native CA_GetModelBoundingSphere(modelid, &Float:offx, &Float:offy, &Float:offz, &Float:radius);
  32. native CA_GetModelBoundingBox(modelid, &Float:minx, &Float:miny, &Float:minz, &Float:maxx, &Float:maxy, &Float:maxz);
  33. native CA_SetObjectExtraID(index, type, data);
  34. native CA_GetObjectExtraID(index, type);
  35. // Extended raycast function returns internal pointer of mapobject class instead of modelid
  36. native CA_RayCastLineEx(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z, &Float:rx, &Float:ry, &Float:rz, &Float:rw, &Float:cx, &Float:cy, &Float:cz);
  37. native CA_RayCastLineAngleEx(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z, &Float:rx, &Float:ry, &Float:rz, &Float:ocx, &Float:ocy, &Float:ocz, &Float:orx, &Float:ory, &Float:orz);
  38. // Used internally
  39. native CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, bool:add = false);
  40. native CA_DestroyObject(index);
  41. native CA_SetObjectPos(index, Float:x, Float:y, Float:z);
  42. native CA_SetObjectRot(index, Float:rx, Float:ry, Float:rz);
  43. // ColAndreas currently supports 50000 user collision objects (This can be raised as needed)
  44. #if defined MAX_CA_OBJECTS
  45. #if MAX_CA_OBJECTS > 50000
  46. #error [ColAndreas] MAX_CA_OBJECTS is too high, maximum value is 50000
  47. #endif
  48. #else
  49. #define MAX_CA_OBJECTS 10000
  50. #endif
  51. // Water object ID
  52. #define WATER_OBJECT 20000
  53. // Object types (Player objects are supported as dynamic only)
  54. #define OBJECT_TYPE_OBJECT 0
  55. #define OBJECT_TYPE_DYNAMIC 1
  56. #if !defined INFINITY
  57. #define INFINITY (Float:0x7F800000)
  58. #endif
  59. #if defined _Y_ITERATE_LOCAL_VERSION
  60. static stock Iterator:CA_Objects<MAX_CA_OBJECTS>;
  61. #endif
  62. enum CAOBJECTINFO
  63. {
  64. ColdAndreadsID,
  65. ObjectID,
  66. ObjectType,
  67. #if !defined _Y_ITERATE_LOCAL_VERSION
  68. bool:ObjectUsed,
  69. #endif
  70. }
  71. static stock CA_ObjectList[MAX_CA_OBJECTS][CAOBJECTINFO];
  72. //Streamer
  73. #if defined STREAMER_TYPE_OBJECT
  74. // Static collision object functions (The index is not returned these can not be deleted!)
  75. stock CA_CreateDynamicObjectEx_SC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:streamdistance = STREAMER_OBJECT_SD, Float:drawdistance = STREAMER_OBJECT_DD, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, STREAMER_TAG_AREA areas[] = { STREAMER_TAG_AREA -1 }, priority = 0, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players, maxareas = sizeof areas)
  76. {
  77. new id = CreateDynamicObjectEx(modelid, x, y, z, rx, ry, rz, streamdistance, drawdistance, worlds, interiors, players, areas, maxworlds, maxinteriors, maxplayers, maxareas);
  78. CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  79. return id;
  80. }
  81. stock CA_CreateDynamicObject_SC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, vw = -1, interior = -1, playerid = -1, Float:streamdistance = STREAMER_OBJECT_SD, Float:drawdistance = STREAMER_OBJECT_DD, STREAMER_TAG_AREA areaid = STREAMER_TAG_AREA -1, priority = 0)
  82. {
  83. new id = CreateDynamicObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, vw, interior, playerid, streamdistance, drawdistance, areaid, priority);
  84. CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  85. return id;
  86. }
  87. stock CA_CreateObject_SC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:drawdistance = 300.0)
  88. {
  89. new id = CreateObject(modelid, x, y, z, rx, ry, rz, drawdistance);
  90. if(id != INVALID_OBJECT_ID) CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  91. return id;
  92. }
  93. // Dynamic collision object functions (Removable)
  94. stock CA_CreateDynamicObjectEx_DC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:streamdistance = STREAMER_OBJECT_SD, Float:drawdistance = STREAMER_OBJECT_DD, worlds[] = { -1 }, interiors[] = { -1 }, players[] = { -1 }, STREAMER_TAG_AREA areas[] = { STREAMER_TAG_AREA -1 }, priority = 0, maxworlds = sizeof worlds, maxinteriors = sizeof interiors, maxplayers = sizeof players, maxareas = sizeof areas)
  95. {
  96. new index = -1;
  97. #if defined _Y_ITERATE_LOCAL_VERSION
  98. index = Iter_Free(CA_Objects);
  99. #else
  100. for(new i = 0; i < MAX_CA_OBJECTS; i++)
  101. {
  102. if(CA_ObjectList[i][ObjectUsed] == false)
  103. {
  104. index = i;
  105. break;
  106. }
  107. }
  108. #endif
  109. if(index > -1)
  110. {
  111. #if defined _Y_ITERATE_LOCAL_VERSION
  112. Iter_Add(CA_Objects, index);
  113. #else
  114. CA_ObjectList[index][ObjectUsed] = true;
  115. #endif
  116. CA_ObjectList[index][ObjectID] = CreateDynamicObjectEx(modelid, x, y, z, rx, ry, rz, drawdistance, streamdistance, worlds, interiors, players, areas, maxworlds, maxinteriors, maxplayers, maxareas);
  117. CA_ObjectList[index][ColdAndreadsID] = CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, true);
  118. CA_ObjectList[index][ObjectType] = OBJECT_TYPE_DYNAMIC;
  119. }
  120. return index;
  121. }
  122. stock CA_CreateDynamicObject_DC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, vw = -1, interior = -1, playerid = -1, Float:streamdistance = STREAMER_OBJECT_SD, Float:drawdistance = STREAMER_OBJECT_DD, STREAMER_TAG_AREA areaid = STREAMER_TAG_AREA -1, priority = 0)
  123. {
  124. new index = -1;
  125. #if defined _Y_ITERATE_LOCAL_VERSION
  126. index = Iter_Free(CA_Objects);
  127. #else
  128. for(new i = 0; i < MAX_CA_OBJECTS; i++)
  129. {
  130. if(CA_ObjectList[i][ObjectUsed] == false)
  131. {
  132. index = i;
  133. break;
  134. }
  135. }
  136. #endif
  137. if(index > -1)
  138. {
  139. #if defined _Y_ITERATE_LOCAL_VERSION
  140. Iter_Add(CA_Objects, index);
  141. #else
  142. CA_ObjectList[index][ObjectUsed] = true;
  143. #endif
  144. CA_ObjectList[index][ObjectID] = CreateDynamicObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, vw, interior, playerid, streamdistance, drawdistance, areaid, priority);
  145. CA_ObjectList[index][ColdAndreadsID] = CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, true);
  146. CA_ObjectList[index][ObjectType] = OBJECT_TYPE_DYNAMIC;
  147. }
  148. return index;
  149. }
  150. #endif
  151. stock CA_CreateObject_DC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:drawdistance = 300.0)
  152. {
  153. new index = -1;
  154. #if defined _Y_ITERATE_LOCAL_VERSION
  155. index = Iter_Free(CA_Objects);
  156. #else
  157. for(new i = 0; i < MAX_CA_OBJECTS; i++)
  158. {
  159. if(CA_ObjectList[i][ObjectUsed] == false)
  160. {
  161. index = i;
  162. break;
  163. }
  164. }
  165. #endif
  166. new id = CreateObject(modelid, x, y, z, rx, ry, rz, drawdistance);
  167. if(id == INVALID_OBJECT_ID) return -1;
  168. if(index > -1)
  169. {
  170. #if defined _Y_ITERATE_LOCAL_VERSION
  171. Iter_Add(CA_Objects, index);
  172. #else
  173. CA_ObjectList[index][ObjectUsed] = true;
  174. #endif
  175. CA_ObjectList[index][ObjectID] = id;
  176. CA_ObjectList[index][ColdAndreadsID] = CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, true);
  177. CA_ObjectList[index][ObjectType] = OBJECT_TYPE_OBJECT;
  178. }
  179. return index;
  180. }
  181. stock CA_DestroyObject_DC(index)
  182. {
  183. // Out of bounds
  184. if(index < 0 || index >= MAX_CA_OBJECTS) return -1;
  185. #if defined _Y_ITERATE_LOCAL_VERSION
  186. if(Iter_Contains(CA_Objects, index))
  187. {
  188. new next;
  189. Iter_SafeRemove(CA_Objects, index, next);
  190. if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) DestroyObject(CA_ObjectList[index][ObjectID]);
  191. #if defined STREAMER_TYPE_OBJECT
  192. else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) DestroyDynamicObject(CA_ObjectList[index][ObjectID]);
  193. #endif
  194. CA_DestroyObject(CA_ObjectList[index][ColdAndreadsID]);
  195. return next;
  196. }
  197. #else
  198. if(CA_ObjectList[index][ObjectUsed])
  199. {
  200. if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) DestroyObject(CA_ObjectList[index][ObjectID]);
  201. #if defined STREAMER_TYPE_OBJECT
  202. else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) DestroyDynamicObject(CA_ObjectList[index][ObjectID]);
  203. #endif
  204. CA_ObjectList[index][ObjectUsed] = false;
  205. CA_DestroyObject(CA_ObjectList[index][ColdAndreadsID]);
  206. return 1;
  207. }
  208. #endif
  209. return -1;
  210. }
  211. stock CA_SetObjectPos_DC(index, Float:x, Float:y, Float:z)
  212. {
  213. // Out of bounds
  214. if(index < 0 || index >= MAX_CA_OBJECTS) return -1;
  215. #if defined _Y_ITERATE_LOCAL_VERSION
  216. if(Iter_Contains(CA_Objects, index))
  217. {
  218. if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  219. #if defined STREAMER_TYPE_OBJECT
  220. else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  221. #endif
  222. CA_SetObjectPos(CA_ObjectList[index][ColdAndreadsID], x, y, z);
  223. }
  224. #else
  225. if(CA_ObjectList[index][ObjectUsed])
  226. {
  227. if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  228. #if defined STREAMER_TYPE_OBJECT
  229. else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  230. #endif
  231. SetObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  232. CA_SetObjectPos(CA_ObjectList[index][ColdAndreadsID], x, y, z);
  233. return 1;
  234. }
  235. #endif
  236. return -1;
  237. }
  238. stock CA_SetObjectRot_DC(index, Float:rx, Float:ry, Float:rz)
  239. {
  240. // Out of bounds
  241. if(index < 0 || index >= MAX_CA_OBJECTS) return -1;
  242. #if defined _Y_ITERATE_LOCAL_VERSION
  243. if(Iter_Contains(CA_Objects, index))
  244. {
  245. if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  246. #if defined STREAMER_TYPE_OBJECT
  247. else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  248. #endif
  249. CA_SetObjectRot(CA_ObjectList[index][ColdAndreadsID], rx, ry, rz);
  250. }
  251. #else
  252. if(CA_ObjectList[index][ObjectUsed])
  253. {
  254. if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  255. #if defined STREAMER_TYPE_OBJECT
  256. else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  257. #endif
  258. CA_SetObjectRot(CA_ObjectList[index][ColdAndreadsID], rx, ry, rz);
  259. return 1;
  260. }
  261. #endif
  262. return -1;
  263. }
  264. // Destroy all objects
  265. stock CA_DestroyAllObjects_DC()
  266. {
  267. #if defined _Y_ITERATE_LOCAL_VERSION
  268. foreach(new i : CA_Objects)
  269. {
  270. if(CA_ObjectList[i][ObjectType] == OBJECT_TYPE_OBJECT) i = CA_DestroyObject_DC(i);
  271. }
  272. #else
  273. for(new i = 0; i < MAX_CA_OBJECTS; i++)
  274. {
  275. if(CA_ObjectList[i][ObjectUsed])
  276. {
  277. if(CA_ObjectList[i][ObjectType] == OBJECT_TYPE_OBJECT) CA_DestroyObject_DC(i);
  278. }
  279. }
  280. #endif
  281. }
  282. // MapAndreas simulation
  283. stock CA_FindZ_For2DCoord(Float:x, Float:y, &Float:z)
  284. {
  285. if(CA_RayCastLine(x, y, 700.0, x, y, -1000.0, x, y, z)) return 1;
  286. return 0;
  287. }
  288. // Explode ray casts in every direction
  289. stock CA_RayCastExplode(Float:cX, Float:cY, Float:cZ, Float:Radius, Float:intensity = 20.0, Float:collisions[][3])
  290. {
  291. if(intensity < 1.0 || intensity > 360.0 || (((360.0 / intensity) - floatround((360.0 / intensity), floatround_floor)) * intensity))
  292. return 0;
  293. new index;
  294. for(new Float:lat = -180.0; lat < 180.0; lat += (intensity * 0.75))
  295. for(new Float:lon = -90.0; lon < 90.0; lon += intensity)
  296. {
  297. new Float:LAT = lat * 3.141593 / 180.0,
  298. Float:LON = lon * 3.141593 / 180.0,
  299. Float:x = -Radius * floatcos(LAT) * floatcos(LON),
  300. Float:y = Radius * floatcos(LAT) * floatsin(LON),
  301. Float:z = Radius * floatsin(LAT);
  302. if(CA_RayCastLine(cX, cY, cZ, cX + x, cY + y, cZ + z, x, y, z))
  303. {
  304. collisions[index][0] = x;
  305. collisions[index][1] = y;
  306. collisions[index][2] = z;
  307. index++;
  308. }
  309. }
  310. return index;
  311. }
  312. // Check if a player is standing on a surface
  313. stock CA_IsPlayerOnSurface(playerid, Float:tolerance=1.5)
  314. {
  315. new Float:x, Float:y, Float:z;
  316. GetPlayerPos(playerid, x, y, z);
  317. // Check if player is actually on the ground
  318. if(!CA_RayCastLine(x, y, z, x, y, z-tolerance, x, y, z))
  319. return 0;
  320. return 1;
  321. }
  322. // remove all barries
  323. stock CA_RemoveBarriers()
  324. {
  325. static const BarrierIDS[] = {
  326. 16439, 16438, 16437, 16436, 4527, 4526, 4525, 4524,
  327. 4523, 4517, 4516, 4515, 4514, 4513, 4512, 4511, 4510,
  328. 4509, 4508, 4507, 4506, 4505, 4504, 1662
  329. };
  330. for(new i = 0; i < sizeof(BarrierIDS); i++)
  331. CA_RemoveBuilding(BarrierIDS[i], 0.0, 0.0, 0.0, 4242.6407);
  332. return 1;
  333. }
  334. // remove all breakables
  335. stock CA_RemoveBreakableBuildings()
  336. {
  337. static const BreakableIDs[] = {
  338. 625, 626, 627, 628, 629, 630, 631, 632, 633, 642, 643, 644, 646, 650, 716, 717, 737, 738, 792, 858, 881, 882, 883,
  339. 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 904, 905, 941, 955, 956, 959, 961, 990, 993, 996, 1209,
  340. 1211, 1213, 1219, 1220, 1221, 1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1235, 1238, 1244, 1251,
  341. 1255, 1257, 1262, 1264, 1265, 1270, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1293,
  342. 1294, 1297, 1300, 1302, 1315, 1328, 1329, 1330, 1338, 1350, 1351, 1352, 1370, 1373, 1374, 1375, 1407, 1408, 1409,
  343. 1410, 1411, 1412, 1413, 1414, 1415, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 1428, 1429, 1431,
  344. 1432, 1433, 1436, 1437, 1438, 1440, 1441, 1443, 1444, 1445, 1446, 1447, 1448, 1449, 1450, 1451, 1452, 1456, 1457,
  345. 1458, 1459, 1460, 1461, 1462, 1463, 1464, 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476,
  346. 1477, 1478, 1479, 1480, 1481, 1482, 1483, 1514, 1517, 1520, 1534, 1543, 1544, 1545, 1551, 1553, 1554, 1558, 1564,
  347. 1568, 1582, 1583, 1584, 1588, 1589, 1590, 1591, 1592, 1645, 1646, 1647, 1654, 1664, 1666, 1667, 1668, 1669, 1670,
  348. 1672, 1676, 1684, 1686, 1775, 1776, 1949, 1950, 1951, 1960, 1961, 1962, 1975, 1976, 1977, 2647, 2663, 2682, 2683,
  349. 2885, 2886, 2887, 2900, 2918, 2920, 2925, 2932, 2933, 2942, 2943, 2945, 2947, 2958, 2959, 2966, 2968, 2971, 2977,
  350. 2987, 2988, 2989, 2991, 2994, 3006, 3018, 3019, 3020, 3021, 3022, 3023, 3024, 3029, 3032, 3036, 3058, 3059, 3067,
  351. 3083, 3091, 3221, 3260, 3261, 3262, 3263, 3264, 3265, 3267, 3275, 3276, 3278, 3280, 3281, 3282, 3302, 3374, 3409,
  352. 3460, 3516, 3794, 3795, 3797, 3853, 3855, 3864, 3884, 11103, 12840, 16627, 16628, 16629, 16630, 16631, 16632,
  353. 16633, 16634, 16635, 16636, 16732, 17968
  354. };
  355. for(new i = 0; i < sizeof(BreakableIDs); i++)
  356. CA_RemoveBuilding(BreakableIDs[i], 0.0, 0.0, 0.0, 4242.6407);
  357. return 1;
  358. }
  359. // Checks if player is in the water
  360. stock CA_IsPlayerInWater(playerid, &Float:depth, &Float:playerdepth)
  361. {
  362. new Float:x, Float:y, Float:z, Float:retx[10], Float:rety[10], Float:retz[10], Float: retdist[10], modelids[10];
  363. GetPlayerPos(playerid, x, y, z);
  364. new collisions = CA_RayCastMultiLine(x, y, z+1000.0, x, y, z-1000.0, retx, rety, retz, retdist, modelids, 10);
  365. if(collisions)
  366. {
  367. for(new i = 0; i < collisions; i++)
  368. {
  369. if(modelids[i] == WATER_OBJECT)
  370. {
  371. depth = INFINITY;
  372. for(new j = 0; j < collisions; j++)
  373. {
  374. if(retz[j] < depth)
  375. depth = retz[j];
  376. }
  377. depth = retz[i] - depth;
  378. if(depth < 0.001 && depth > -0.001)
  379. depth = 100.0;
  380. playerdepth = retz[i] - z;
  381. if(playerdepth < -2.0)
  382. return 0;
  383. return 1;
  384. }
  385. }
  386. }
  387. return 0;
  388. }
  389. // Check if player is near water
  390. stock CA_IsPlayerNearWater(playerid, Float:dist=3.0, Float:height=3.0)
  391. {
  392. new Float:x, Float:y, Float:z, Float:tmp;
  393. GetPlayerPos(playerid, x, y, z);
  394. for(new i; i < 6; i++)
  395. if(CA_RayCastLine(x + (dist * floatsin(i * 60.0, degrees)), y + (dist * floatcos(i * 60.0, degrees)), z + height, x + (dist * floatsin(i * 60.0, degrees)), y + (dist * floatcos(i * 60.0, degrees)), z - height, tmp, tmp, tmp) == WATER_OBJECT)
  396. return 1;
  397. return 0;
  398. }
  399. // Check if player is facing water
  400. stock CA_IsPlayerFacingWater(playerid, Float:dist=3.0, Float:height=3.0)
  401. {
  402. new Float:x, Float:y, Float:z, Float:r, Float:tmp;
  403. GetPlayerPos(playerid, x, y, z);
  404. GetPlayerFacingAngle(playerid, r);
  405. if(CA_RayCastLine(x + (dist * floatsin(-r, degrees)), y + (dist * floatcos(-r, degrees)), z, x + (dist * floatsin(-r, degrees)), y + (dist * floatcos(-r, degrees)), z - height, tmp, tmp, tmp) == WATER_OBJECT)
  406. return 1;
  407. return 0;
  408. }
  409. // Checks if a player is blocked by a wall
  410. stock CA_IsPlayerBlocked(playerid, Float:dist=1.5, Float:height=0.5)
  411. {
  412. new Float:x, Float:y, Float:z, Float:endx, Float:endy, Float:fa;
  413. GetPlayerPos(playerid, x, y, z);
  414. z -= 1.0 + height;
  415. GetPlayerFacingAngle(playerid, fa);
  416. endx = (x + dist * floatsin(-fa,degrees));
  417. endy = (y + dist * floatcos(-fa,degrees));
  418. if(CA_RayCastLine(x, y, z, endx, endy, z, x, y, z))
  419. return 1;
  420. return 0;
  421. }
  422. stock Float:CA_GetRoomHeight(Float:x, Float:y, Float:z)
  423. {
  424. new Float:fx, Float:fy, Float:fz, Float:cx, Float:cy, Float:cz;
  425. if(CA_RayCastLine(x, y, z, x, y, z-1000.0, fx, fy, fz))
  426. {
  427. if(CA_RayCastLine(x, y, z, x, y, z+1000.0, cx, cy, cz))
  428. return floatsqroot(((fx-cx)*(fx-cx))+((fy-cy)*(fy-cy))+((fz-cz)*(fz-cz)));
  429. }
  430. return 0.0;
  431. }
  432. stock Float:CA_GetRoomCenter(Float:x, Float:y, Float:z, &Float:m_x, &Float:m_y)
  433. {
  434. new Float:pt1x, Float:pt1y,
  435. Float:pt2x, Float:pt2y,
  436. Float:pt3x, Float:pt3y,
  437. Float:tmp;
  438. if(!CA_RayCastLine(x, y, z, x + 1000.0 * floatcos(0.0, degrees), y + 1000.0 * floatsin(0.0, degrees), z, pt1x, pt1y, tmp) ||
  439. !CA_RayCastLine(x, y, z, x + 1000.0 * floatcos(120.0, degrees), y + 1000.0 * floatsin(120.0, degrees), z, pt2x, pt2y, tmp) ||
  440. !CA_RayCastLine(x, y, z, x + 1000.0 * floatcos(-120.0, degrees), y + 1000.0 * floatsin(-120.0, degrees), z, pt3x, pt3y, tmp))
  441. return -1.0;
  442. new Float:yDelta_a = pt2y - pt1y,
  443. Float:xDelta_a = pt2x - pt1x,
  444. Float:yDelta_b = pt3y - pt2y,
  445. Float:xDelta_b = pt3x - pt2x;
  446. if (floatabs(xDelta_a) <= 0.000000001 && floatabs(yDelta_b) <= 0.000000001) {
  447. m_x = 0.5 * (pt2x + pt3x);
  448. m_y = 0.5 * (pt1y + pt2y);
  449. return VectorSize(m_x - pt1x, m_y - pt1y, 0.0);
  450. }
  451. new Float:aSlope = yDelta_a / xDelta_a,
  452. Float:bSlope = yDelta_b / xDelta_b;
  453. if (floatabs(aSlope-bSlope) <= 0.000000001)
  454. return -1.0;
  455. m_x = (aSlope * bSlope * (pt1y - pt3y) + bSlope * (pt1x + pt2x) - aSlope * (pt2x + pt3x)) / (2.0 * (bSlope - aSlope));
  456. m_y = -1.0 * (m_x - (pt1x + pt2x) / 2.0) / aSlope + (pt1y + pt2y) / 2.0;
  457. return VectorSize(m_x - pt1x, m_y - pt1y, 0.0);
  458. }
  459. // Hooked functions
  460. public OnFilterScriptExit()
  461. {
  462. CA_DestroyAllObjects_DC();
  463. if (funcidx("CA_OnFilterScriptExit") != -1)
  464. {
  465. return CallLocalFunction("CA_OnFilterScriptExit", "");
  466. }
  467. return 1;
  468. }
  469. #if defined _ALS_OnFilterScriptExit
  470. #undef OnFilterScriptExit
  471. #else
  472. #define _ALS_OnFilterScriptExit
  473. #endif
  474. #define OnFilterScriptExit CA_OnFilterScriptExit
  475. forward CA_OnFilterScriptExit();
  476. public OnGameModeExit()
  477. {
  478. CA_DestroyAllObjects_DC();
  479. if (funcidx("CA_OnGameModeExit") != -1)
  480. {
  481. return CallLocalFunction("CA_OnGameModeExit", "");
  482. }
  483. return 1;
  484. }
  485. #if defined _ALS_OnGameModeExit
  486. #undef OnGameModeExit
  487. #else
  488. #define _ALS_OnGameModeExit
  489. #endif
  490. #define OnGameModeExit CA_OnGameModeExit
  491. forward CA_OnGameModeExit();