Advertisement
Guest User

Colandreas Output

a guest
Sep 24th, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 63.49 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // ColAndreas Plugin Include ///////////////////////////////////////////////////
  3. ////////////////////////////////////////////////////////////////////////////////
  4.  
  5. #if defined COLANDREAS_VERSION
  6.     #endinput
  7. #endif
  8. #define COLANDREAS_VERSION (10400) //a.b.c 10000*a+100*b+c
  9.  
  10. // Default extra ID types
  11. #define CA_EXTRA_1  0
  12. #define CA_EXTRA_2  1
  13. #define CA_EXTRA_3  2
  14. #define CA_EXTRA_4  3
  15. #define CA_EXTRA_5  4
  16. #define CA_EXTRA_6  5
  17. #define CA_EXTRA_7  6
  18. #define CA_EXTRA_8  7
  19. #define CA_EXTRA_9  8
  20. #define CA_EXTRA_10 9
  21.  
  22. // ColAndreas currently supports 50000 user collision objects (This can be raised as needed)
  23. #if defined MAX_CA_OBJECTS
  24.     #if MAX_CA_OBJECTS > 50000
  25.         #error [ColAndreas] MAX_CA_OBJECTS is too high, maximum value is 50000
  26.     #endif
  27. #else
  28.    #define MAX_CA_OBJECTS 10000
  29. #endif
  30.  
  31. // Water object ID
  32. #define     WATER_OBJECT        20000
  33.  
  34. // Object types (Player objects are supported as dynamic only)
  35. #define     OBJECT_TYPE_OBJECT  0
  36. #define     OBJECT_TYPE_DYNAMIC 1
  37.  
  38.  
  39. #if !defined INFINITY
  40.     #define INFINITY (Float:0x7F800000)
  41. #endif
  42.  
  43. /**--------------------------------------------------------------------------**\
  44. <summary>
  45.     CA_Init
  46. </summary>
  47. <returns>
  48.     0 when there is no data loaded (ex. when you don't have the data file)
  49.     1 when loaded map successfully or was already loaded
  50. </returns>
  51. \**--------------------------------------------------------------------------**/
  52. native CA_Init();
  53.  
  54. /**--------------------------------------------------------------------------**\
  55. <summary>
  56.     CA_RemoveBuilding
  57. </summary>
  58. <param name="modelid">The model to be removed</param>
  59. <param name="Float:x, Float:y, Float:z">The coordinates in which the objects will be removed</param>
  60. <param name="Float:radius">The radius around the specified point to remove from</param>
  61. <returns>
  62.     0 when the map is already initialized
  63.     1 when successfully removed
  64. </returns>
  65. <remarks>
  66.     You must use this function before using `CA_Init`
  67. </remarks>
  68. \**--------------------------------------------------------------------------**/
  69. native CA_RemoveBuilding(modelid, Float:x, Float:y, Float:z, Float:radius);
  70.  
  71. /**--------------------------------------------------------------------------**\
  72. <summary>
  73.     CA_RayCastLine
  74. </summary>
  75. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  76. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  77. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  78. <returns>
  79.     0 if the ray didn't collide with anything
  80.     WATER_OBJECT if the ray collided with water
  81.     The model of the object the ray collided
  82. </returns>
  83. \**--------------------------------------------------------------------------**/
  84. native CA_RayCastLine(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z);
  85.  
  86. /**--------------------------------------------------------------------------**\
  87. <summary>
  88.     CA_RayCastLineID
  89. </summary>
  90. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  91. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  92. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  93. <returns>
  94.     -1 if the ray collided with a static object or water
  95.     0 if the ray didn't collide with anything
  96.     The index of the object the ray collided
  97. </returns>
  98. <remarks>
  99.     This only works with objects created with `add` enabled in `CA_CreateObject`, such as the objects created by the "_DC" functions
  100. </remarks>
  101. \**--------------------------------------------------------------------------**/
  102. native CA_RayCastLineID(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z);
  103.  
  104. /**--------------------------------------------------------------------------**\
  105. <summary>
  106.     CA_RayCastLineExtraID
  107. </summary>
  108. <param name="type">The extra ID index</param>
  109. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  110. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  111. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  112. <returns>
  113.     -1 if the ray collided with a static object or water
  114.     -1 if the extra ID is unmodified
  115.     0 if the ray didn't collide with anything
  116.     The index of the object the ray collided
  117. </returns>
  118. <remarks>
  119.     This only works with objects created with `add` enabled in `CA_CreateObject`, such as the objects created by the "_DC" functions
  120. </remarks>
  121. \**--------------------------------------------------------------------------**/
  122. native CA_RayCastLineExtraID(type, Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z);
  123.  
  124. /**--------------------------------------------------------------------------**\
  125. <summary>
  126.     CA_RayCastMultiLine
  127. </summary>
  128. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  129. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  130. <param name="Float:retx[], Float:rety[], Float:retz[]">The points that the ray collided</param>
  131. <param name="Float:retdist[]">The distances between the beginning point and the point collided</param>
  132. <param name="ModelIDs[]">The object models that the ray collided</param>
  133. <param name="size = sizeof(retx)">The maximum number of points to collide</param>
  134. <returns>
  135.     -1 if the ray collided with more points than than permitted by the `size` parameter
  136.     0 if the ray didn't collide with anything
  137.     The number of points collided
  138. </returns>
  139. \**--------------------------------------------------------------------------**/
  140. 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));
  141.  
  142. /**--------------------------------------------------------------------------**\
  143. <summary>
  144.     CA_RayCastLineAngle
  145. </summary>
  146. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  147. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  148. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  149. <param name="&Float:rx, &Float:ry, &Float:rz">The rotation of the face that the ray collided</param>
  150. <returns>
  151.     0 if the ray didn't collide with anything
  152.     WATER_OBJECT if the ray collided with water
  153.     The model of the object the ray collided
  154. </returns>
  155. \**--------------------------------------------------------------------------**/
  156. 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);
  157.  
  158. /**--------------------------------------------------------------------------**\
  159. <summary>
  160.     CA_RayCastReflectionVector
  161. </summary>
  162. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  163. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  164. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  165. <param name="&Float:nx, &Float:ny, &Float:nz">The reflection vector of the face that the ray collided</param>
  166. <returns>
  167.     0 if the ray didn't collide with anything
  168.     WATER_OBJECT if the ray collided with water
  169.     The model of the object the ray collided
  170. </returns>
  171. \**--------------------------------------------------------------------------**/
  172. 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);
  173.  
  174. /**--------------------------------------------------------------------------**\
  175. <summary>
  176.     CA_RayCastLineNormal
  177. </summary>
  178. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  179. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  180. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  181. <param name="&Float:nx, &Float:ny, &Float:nz">The surface normal of the face that the ray collided</param>
  182. <returns>
  183.     0 if the ray didn't collide with anything
  184.     WATER_OBJECT if the ray collided with water
  185.     The model of the object the ray collided
  186. </returns>
  187. \**--------------------------------------------------------------------------**/
  188. 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);
  189.  
  190. /**--------------------------------------------------------------------------**\
  191. <summary>
  192.     CA_ContactTest
  193. </summary>
  194. <param name="modelid">The object model to be tested</param>
  195. <param name="Float:x, Float:y, Float:z">The object position to test</param>
  196. <param name="Float:rx, Float:ry, Float:rz">The object rotation to test</param>
  197. <returns>
  198.     0 if the object model doesn't collide with the world with the specified
  199.     1 otherwise
  200. </returns>
  201. \**--------------------------------------------------------------------------**/
  202. native CA_ContactTest(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  203.  
  204. /**--------------------------------------------------------------------------**\
  205. <summary>
  206.     CA_EulerToQuat
  207. </summary>
  208. <param name="Float:rx, Float:ry, Float:rz">GTA euler rotations to be converted</param>
  209. <param name="&Float:x, &Float:y, &Float:z, &Float:w">The quaternion angles returned</param>
  210. <returns>
  211.     Always 1
  212. </returns>
  213. \**--------------------------------------------------------------------------**/
  214. native CA_EulerToQuat(Float:rx, Float:ry, Float:rz, &Float:x, &Float:y, &Float:z, &Float:w);
  215.  
  216. /**--------------------------------------------------------------------------**\
  217. <summary>
  218.     CA_QuatToEuler
  219. </summary>
  220. <param name="&Float:x, &Float:y, &Float:z, &Float:w">The quaternion angles to be converted</param>
  221. <param name="Float:rx, Float:ry, Float:rz">GTA euler rotations returned</param>
  222. <returns>
  223.     Always 1
  224. </returns>
  225. \**--------------------------------------------------------------------------**/
  226. native CA_QuatToEuler(Float:x, Float:y, Float:z, Float:w, &Float:rx, &Float:ry, &Float:rz);
  227.  
  228. /**--------------------------------------------------------------------------**\
  229. <summary>
  230.     CA_GetModelBoundingSphere
  231. </summary>
  232. <param name="modelid">The object model</param>
  233. <param name="&Float:offx, &Float:offy, &Float:offz">The offset of the model's bounding sphere</param>
  234. <param name="&Float:radius">The radius of the model's bounding sphere</param>
  235. <returns>
  236.     0 if the model is invalid
  237.     1 otherwise
  238. </returns>
  239. \**--------------------------------------------------------------------------**/
  240. native CA_GetModelBoundingSphere(modelid, &Float:offx, &Float:offy, &Float:offz, &Float:radius);
  241.  
  242. /**--------------------------------------------------------------------------**\
  243. <summary>
  244.     CA_GetModelBoundingBox
  245. </summary>
  246. <param name="modelid">The object model</param>
  247. <param name="&Float:minx, &Float:miny, &Float:minz">The "minimum" point of the model's bounding box</param>
  248. <param name="&Float:maxx, &Float:maxy, &Float:maxz">The "maximum" point of the model's bounding box</param>
  249. <returns>
  250.     0 if the model is invalid
  251.     1 otherwise
  252. </returns>
  253. \**--------------------------------------------------------------------------**/
  254. native CA_GetModelBoundingBox(modelid, &Float:minx, &Float:miny, &Float:minz, &Float:maxx, &Float:maxy, &Float:maxz);
  255.  
  256. /**--------------------------------------------------------------------------**\
  257. <summary>
  258.     CA_SetObjectExtraID
  259. </summary>
  260. <param name="index">The index of the ColAndreas object</param>
  261. <param name="type">The index of the extra ID to be set</param>
  262. <param name="data">The data stored in the extra ID</param>
  263. <returns>
  264.     Always 1 (which needs to be changed to be like CA_GetObjectExtraID's returns...)
  265. </returns>
  266. \**--------------------------------------------------------------------------**/
  267. native CA_SetObjectExtraID(index, type, data);
  268.  
  269. /**--------------------------------------------------------------------------**\
  270. <summary>
  271.     CA_GetObjectExtraID
  272. </summary>
  273. <param name="index">The index of the ColAndreas object</param>
  274. <param name="type">The index of the extra ID to be set</param>
  275. <returns>
  276.     -1 if the index or type is invalid
  277.     The data stored in the extra ID
  278. </returns>
  279. \**--------------------------------------------------------------------------**/
  280. native CA_GetObjectExtraID(index, type);
  281.  
  282. /**--------------------------------------------------------------------------**\
  283. <summary>
  284.     CA_RayCastLineEx
  285. </summary>
  286. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  287. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  288. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  289. <param name="&Float:rx, &Float:ry, &Float:rz, &Float:rw">The quaternion rotation of the object that the ray collided</param>
  290. <param name="&Float:cx, &Float:cy, &Float:cz">The position of the object that the ray collided</param>
  291. <returns>
  292.     0 if the ray didn't collide with anything
  293.     WATER_OBJECT if the ray collided with water
  294.     The model of the object the ray collided
  295. </returns>
  296. \**--------------------------------------------------------------------------**/
  297. 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);
  298.  
  299. /**--------------------------------------------------------------------------**\
  300. <summary>
  301.     CA_RayCastLineAngleEx
  302. </summary>
  303. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  304. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  305. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  306. <param name="&Float:rx, &Float:ry, &Float:rz">The rotation of the face that the ray collided</param>
  307. <param name="&Float:ocx, &Float:ocy, &Float:ocz">The position of the object that the ray collided</param>
  308. <param name="&Float:orx, &Float:ory, &Float:orz">The rotation of the object that the ray collided</param>
  309. <returns>
  310.     0 if the ray didn't collide with anything
  311.     WATER_OBJECT if the ray collided with water
  312.     The model of the object the ray collided
  313. </returns>
  314. \**--------------------------------------------------------------------------**/
  315. 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);
  316.  
  317. // Internal Functions:
  318.  
  319. /**--------------------------------------------------------------------------**\
  320. <summary>
  321.     CA_CreateObject
  322. </summary>
  323. <param name="modelid">The collision model to create</param>
  324. <param name="Float:x, Float:y, Float:z">The position in which to create the collision model</param>
  325. <param name="Float:rx, Float:ry, Float:rz">The rotation of the collision model</param>
  326. <param name="bool:add = false">Whether or not to store this objects index for manual management</param>
  327. <returns>
  328.     -1 if the specified model has no collision (should be changed to -2, to avoid confusion with unmanaged objects)
  329.     -1 if `add` is false
  330.     The index of the created collision object
  331. </returns>
  332. <remarks>
  333.     ONLY CREATES THE COLLISION, NOT THE IN-GAME OBJECT
  334. </remarks>
  335. \**--------------------------------------------------------------------------**/
  336. native CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, bool:add = false);
  337.  
  338. /**--------------------------------------------------------------------------**\
  339. <summary>
  340.     CA_DestroyObject
  341. </summary>
  342. <param name="index">The index of the object to be destroyed</param>
  343. <returns>
  344.     -1 if the specified model has no collision (should be changed to -2, to avoid confusion with unmanaged objects)
  345.     -1 if `add` is false
  346.     The index of the created collision object
  347. </returns>
  348. \**--------------------------------------------------------------------------**/
  349. native CA_DestroyObject(index);
  350.  
  351. /**--------------------------------------------------------------------------**\
  352. <summary>
  353.     CA_SetObjectPos
  354. </summary>
  355. <param name="index">The index of the object to be moved</param>
  356. <param name="Float:x, Float:y, Float:z">The new position</param>
  357. <returns>
  358.     0 if the object doesn't exist
  359.     1 if the new position was set successfully
  360. </returns>
  361. \**--------------------------------------------------------------------------**/
  362. native CA_SetObjectPos(index, Float:x, Float:y, Float:z);
  363.  
  364. /**--------------------------------------------------------------------------**\
  365. <summary>
  366.     CA_SetObjectRot
  367. </summary>
  368. <param name="index">The index of the object to be moved</param>
  369. <param name="Float:rx, Float:ry, Float:rz">The new rotation</param>
  370. <returns>
  371.     0 if the object doesn't exist
  372.     1 if the new rotation was set successfully
  373. </returns>
  374. \**--------------------------------------------------------------------------**/
  375. native CA_SetObjectRot(index, Float:rx, Float:ry, Float:rz);
  376.  
  377. #if defined _Y_ITERATE_LOCAL_VERSION
  378.     static stock Iterator:CA_Objects<MAX_CA_OBJECTS>;
  379. #endif
  380.  
  381. enum CAOBJECTINFO
  382. {
  383.     ColdAndreadsID,
  384.     ObjectID,
  385.     ObjectType,
  386.  
  387.     #if !defined _Y_ITERATE_LOCAL_VERSION
  388.         bool:ObjectUsed,
  389.     #endif
  390. }
  391.  
  392. static stock CA_ObjectList[MAX_CA_OBJECTS][CAOBJECTINFO];
  393.  
  394. //Streamer
  395. #if defined STREAMER_TYPE_OBJECT
  396.  
  397.     // Static collision object functions (The index is not returned these can not be deleted!)
  398.     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)
  399.     {
  400.         new id = CreateDynamicObjectEx(modelid, x, y, z, rx, ry, rz, streamdistance, drawdistance, worlds, interiors, players, areas, maxworlds, maxinteriors, maxplayers, maxareas);
  401.         CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  402.         return id;
  403.     }
  404.  
  405.     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)
  406.     {
  407.         new id = CreateDynamicObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, vw, interior, playerid, streamdistance, drawdistance, areaid, priority);
  408.         CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  409.         return id;
  410.     }
  411.  
  412.     stock CA_CreateObject_SC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:drawdistance = 300.0)
  413.     {
  414.         new id = CreateObject(modelid, x, y, z, rx, ry, rz, drawdistance);
  415.         if(id != INVALID_OBJECT_ID) CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  416.         return id;
  417.     }
  418.  
  419.     // Dynamic collision object functions (Removable)
  420.     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)
  421.     {
  422.         new index = -1;
  423.         #if defined _Y_ITERATE_LOCAL_VERSION
  424.             index = Iter_Free(CA_Objects);
  425.         #else
  426.             for(new i = 0; i < MAX_CA_OBJECTS; i++)
  427.             {
  428.                 if(CA_ObjectList[i][ObjectUsed] == false)
  429.                 {
  430.                     index = i;
  431.                     break;
  432.                 }
  433.             }
  434.         #endif
  435.  
  436.         if(index > -1)
  437.         {
  438.             #if defined _Y_ITERATE_LOCAL_VERSION
  439.                 Iter_Add(CA_Objects, index);
  440.             #else
  441.                 CA_ObjectList[index][ObjectUsed] = true;
  442.             #endif
  443.             CA_ObjectList[index][ObjectID] = CreateDynamicObjectEx(modelid, x, y, z, rx, ry, rz, drawdistance, streamdistance, worlds, interiors, players, areas, maxworlds, maxinteriors, maxplayers, maxareas);
  444.             CA_ObjectList[index][ColdAndreadsID] = CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, true);
  445.             CA_ObjectList[index][ObjectType] = OBJECT_TYPE_DYNAMIC;
  446.         }
  447.         return index;
  448.     }
  449.  
  450.  
  451.     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)
  452.     {
  453.         new index = -1;
  454.         #if defined _Y_ITERATE_LOCAL_VERSION
  455.             index = Iter_Free(CA_Objects);
  456.         #else
  457.             for(new i = 0; i < MAX_CA_OBJECTS; i++)
  458.             {
  459.                 if(CA_ObjectList[i][ObjectUsed] == false)
  460.                 {
  461.                     index = i;
  462.                     break;
  463.                 }
  464.             }
  465.         #endif
  466.  
  467.         if(index > -1)
  468.         {
  469.             #if defined _Y_ITERATE_LOCAL_VERSION
  470.                 Iter_Add(CA_Objects, index);
  471.             #else
  472.                 CA_ObjectList[index][ObjectUsed] = true;
  473.             #endif
  474.             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);
  475.             CA_ObjectList[index][ColdAndreadsID] = CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, true);
  476.             CA_ObjectList[index][ObjectType] = OBJECT_TYPE_DYNAMIC;
  477.         }
  478.         return index;
  479.     }
  480. #endif
  481.  
  482. /**--------------------------------------------------------------------------**\
  483. <summary>
  484.     CA_CreateObject_DC
  485. </summary>
  486. <param name="modelid">The model to create</param>
  487. <param name="Float:x, Float:y, Float:z">The position in which to create the object</param>
  488. <param name="Float:rx, Float:ry, Float:rz">The rotation of the object</param>
  489. <param name="Float:drawdistance = 300.0">Whether or not to store this objects index for manual management</param>
  490. <returns>
  491.     -1 if the object couldn't be created
  492.     -1 if there are too many "DC" objects
  493.     The "DC" index of the created object
  494. </returns>
  495. <remarks>
  496.     The index returned by this function can only be used by "DC" functions
  497. </remarks>
  498. \**--------------------------------------------------------------------------**/
  499. stock CA_CreateObject_DC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:drawdistance = 300.0)
  500. {
  501.     new index = -1;
  502.     #if defined _Y_ITERATE_LOCAL_VERSION
  503.         index = Iter_Free(CA_Objects);
  504.     #else
  505.         for(new i = 0; i < MAX_CA_OBJECTS; i++)
  506.         {
  507.             if(CA_ObjectList[i][ObjectUsed] == false)
  508.             {
  509.                 index = i;
  510.                 break;
  511.             }
  512.         }
  513.     #endif
  514.  
  515.     new id = CreateObject(modelid, x, y, z, rx, ry, rz, drawdistance);
  516.     if(id == INVALID_OBJECT_ID) return -1;
  517.     if(index > -1)
  518.     {
  519.         #if defined _Y_ITERATE_LOCAL_VERSION
  520.             Iter_Add(CA_Objects, index);
  521.         #else
  522.             CA_ObjectList[index][ObjectUsed] = true;
  523.         #endif
  524.         CA_ObjectList[index][ObjectID] = id;
  525.         CA_ObjectList[index][ColdAndreadsID] = CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, true);
  526.         CA_ObjectList[index][ObjectType] = OBJECT_TYPE_OBJECT;
  527.     }
  528.     return index;
  529. }
  530.  
  531. /**--------------------------------------------------------------------------**\
  532. <summary>
  533.     CA_DestroyObject_DC
  534. </summary>
  535. <param name="index">The DC index of the object to destroy</param>
  536. <returns>
  537.     -1 if the index is invalid
  538.     -1 if the object doesn't exist
  539.     1 or next interator index if the object was destroyed
  540. </returns>
  541. \**--------------------------------------------------------------------------**/
  542. stock CA_DestroyObject_DC(index)
  543. {
  544.     // Out of bounds
  545.     if(index < 0 || index >= MAX_CA_OBJECTS) return -1;
  546.     #if defined _Y_ITERATE_LOCAL_VERSION
  547.         if(Iter_Contains(CA_Objects, index))
  548.         {
  549.             new next;
  550.             Iter_SafeRemove(CA_Objects, index, next);
  551.             if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) DestroyObject(CA_ObjectList[index][ObjectID]);
  552.             #if defined STREAMER_TYPE_OBJECT
  553.             else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) DestroyDynamicObject(CA_ObjectList[index][ObjectID]);
  554.             #endif
  555.             CA_DestroyObject(CA_ObjectList[index][ColdAndreadsID]);
  556.             return next;
  557.         }
  558.     #else
  559.     if(CA_ObjectList[index][ObjectUsed])
  560.     {
  561.         if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) DestroyObject(CA_ObjectList[index][ObjectID]);
  562.         #if defined STREAMER_TYPE_OBJECT
  563.         else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) DestroyDynamicObject(CA_ObjectList[index][ObjectID]);
  564.         #endif
  565.         CA_ObjectList[index][ObjectUsed] = false;
  566.         CA_DestroyObject(CA_ObjectList[index][ColdAndreadsID]);
  567.         return 1;
  568.     }
  569.     #endif
  570.     return -1;
  571. }
  572.  
  573. /**--------------------------------------------------------------------------**\
  574. <summary>
  575.     CA_SetObjectPos_DC
  576. </summary>
  577. <param name="index">The DC index of the object to be moved</param>
  578. <param name="Float:x, Float:y, Float:z">The new position</param>
  579. <returns>
  580.     -1 if the index is invalid
  581.     -1 if the object doesn't exist
  582.     1 if the new position was set successfully
  583. </returns>
  584. \**--------------------------------------------------------------------------**/
  585. stock CA_SetObjectPos_DC(index, Float:x, Float:y, Float:z)
  586. {
  587.     // Out of bounds
  588.     if(index < 0 || index >= MAX_CA_OBJECTS) return -1;
  589.     #if defined _Y_ITERATE_LOCAL_VERSION
  590.         if(Iter_Contains(CA_Objects, index))
  591.         {
  592.             if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  593.             #if defined STREAMER_TYPE_OBJECT
  594.                 else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  595.             #endif
  596.             CA_SetObjectPos(CA_ObjectList[index][ColdAndreadsID], x, y, z);
  597.         }
  598.     #else
  599.     if(CA_ObjectList[index][ObjectUsed])
  600.     {
  601.         if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  602.         #if defined STREAMER_TYPE_OBJECT
  603.         else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  604.         #endif
  605.         SetObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  606.         CA_SetObjectPos(CA_ObjectList[index][ColdAndreadsID], x, y, z);
  607.         return 1;
  608.     }
  609.     #endif
  610.     return -1;
  611. }
  612.  
  613. /**--------------------------------------------------------------------------**\
  614. <summary>
  615.     CA_SetObjectRot_DC
  616. </summary>
  617. <param name="index">The DC index of the object to be moved</param>
  618. <param name="Float:rx, Float:ry, Float:rz">The new rotation</param>
  619. <returns>
  620.     -1 if the index is invalid
  621.     -1 if the object doesn't exist
  622.     1 if the new rotation was set successfully
  623. </returns>
  624. \**--------------------------------------------------------------------------**/
  625. stock CA_SetObjectRot_DC(index, Float:rx, Float:ry, Float:rz)
  626. {
  627.     // Out of bounds
  628.     if(index < 0 || index >= MAX_CA_OBJECTS) return -1;
  629.     #if defined _Y_ITERATE_LOCAL_VERSION
  630.         if(Iter_Contains(CA_Objects, index))
  631.         {
  632.             if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  633.             #if defined STREAMER_TYPE_OBJECT
  634.                 else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  635.             #endif
  636.             CA_SetObjectRot(CA_ObjectList[index][ColdAndreadsID], rx, ry, rz);
  637.         }
  638.     #else
  639.     if(CA_ObjectList[index][ObjectUsed])
  640.     {
  641.         if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  642.         #if defined STREAMER_TYPE_OBJECT
  643.             else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  644.         #endif
  645.         CA_SetObjectRot(CA_ObjectList[index][ColdAndreadsID], rx, ry, rz);
  646.         return 1;
  647.     }
  648.     #endif
  649.     return -1;
  650. }
  651.  
  652. /**--------------------------------------------------------------------------**\
  653. <summary>
  654.     CA_DestroyAllObjects_DC
  655. </summary>
  656. <remarks>
  657.     Destroys all DC objects
  658. </remarks>
  659. \**--------------------------------------------------------------------------**/
  660. stock CA_DestroyAllObjects_DC()
  661. {
  662.     #if defined _Y_ITERATE_LOCAL_VERSION
  663.         foreach(new i : CA_Objects)
  664.         {
  665.             if(CA_ObjectList[i][ObjectType] == OBJECT_TYPE_OBJECT) i = CA_DestroyObject_DC(i);
  666.         }
  667.     #else
  668.         for(new i = 0; i < MAX_CA_OBJECTS; i++)
  669.         {
  670.             if(CA_ObjectList[i][ObjectUsed])
  671.             {
  672.                 if(CA_ObjectList[i][ObjectType] == OBJECT_TYPE_OBJECT) CA_DestroyObject_DC(i);
  673.             }
  674.         }
  675.  
  676.     #endif
  677. }
  678.  
  679. /**--------------------------------------------------------------------------**\
  680. <summary>
  681.     CA_FindZ_For2DCoord
  682. </summary>
  683. <remarks>
  684.     The ColAndreas alternative for MapAndreas's entire function
  685.     This function does everything MapAndreas is capable of doing, and without the ground limit
  686. </remarks>
  687. \**--------------------------------------------------------------------------**/
  688. stock CA_FindZ_For2DCoord(Float:x, Float:y, &Float:z)
  689. {
  690.     if(CA_RayCastLine(x, y, 700.0, x, y, -1000.0, x, y, z)) return 1;
  691.     return 0;
  692. }
  693.  
  694. // Explode ray casts in every direction
  695. stock CA_RayCastExplode(Float:cX, Float:cY, Float:cZ, Float:Radius, Float:intensity = 20.0, Float:collisions[][3])
  696. {
  697.     if(intensity < 1.0 || intensity > 360.0 || (((360.0 / intensity) - floatround((360.0 / intensity), floatround_floor)) * intensity))
  698.         return 0;
  699.  
  700.     new index;
  701.     for(new Float:lat = -180.0; lat < 180.0; lat += (intensity * 0.75))
  702.     for(new Float:lon = -90.0; lon < 90.0; lon += intensity)
  703.     {
  704.         new Float:LAT = lat * 3.141593 / 180.0,
  705.             Float:LON = lon * 3.141593 / 180.0,
  706.             Float:x = -Radius * floatcos(LAT) * floatcos(LON),
  707.             Float:y = Radius * floatcos(LAT) * floatsin(LON),
  708.             Float:z = Radius * floatsin(LAT);
  709.        
  710.         if(CA_RayCastLine(cX, cY, cZ, cX + x, cY + y, cZ + z, x, y, z))
  711.         {
  712.             collisions[index][0] = x;
  713.             collisions[index][1] = y;
  714.             collisions[index][2] = z;
  715.             index++;
  716.         }
  717.     }
  718.    
  719.     return index;
  720. }
  721.  
  722. /**--------------------------------------------------------------------------**\
  723. <summary>
  724.     CA_IsPlayerOnSurface
  725. </summary>
  726. <param name="playerid">The playerid to check</param>
  727. <param name="Float:tolerance = 1.5">The distance to check for the ground</param>
  728. <returns>
  729.     0 if the player is not on the ground
  730.     1 if the player is on the ground
  731. </returns>
  732. \**--------------------------------------------------------------------------**/
  733. stock CA_IsPlayerOnSurface(playerid, Float:tolerance=1.5)
  734. {
  735.     new Float:x, Float:y, Float:z;
  736.     GetPlayerPos(playerid, x, y, z);
  737.  
  738.     // Check if player is actually on the ground
  739.     if(!CA_RayCastLine(x, y, z, x, y, z-tolerance, x, y, z))
  740.         return 0;
  741.     return 1;
  742. }
  743.  
  744. /**--------------------------------------------------------------------------**\
  745. <summary>
  746.     CA_RemoveBarriers
  747. </summary>
  748. <returns>
  749.     Always 1
  750. </returns>
  751. <remarks>
  752.     Removes all of the barrier object collisions
  753.     You must use this function before using `CA_Init`
  754. </remarks>
  755. \**--------------------------------------------------------------------------**/
  756. stock CA_RemoveBarriers()
  757. {
  758.     static const BarrierIDS[] = {
  759.         16439, 16438, 16437, 16436, 4527, 4526, 4525, 4524,
  760.         4523, 4517, 4516, 4515, 4514, 4513, 4512, 4511, 4510,
  761.         4509, 4508, 4507, 4506, 4505, 4504, 1662
  762.     };
  763.    
  764.     for(new i = 0; i < sizeof(BarrierIDS); i++)
  765.         CA_RemoveBuilding(BarrierIDS[i], 0.0, 0.0, 0.0, 4242.6407);
  766.  
  767.     return 1;
  768. }
  769.  
  770. /**--------------------------------------------------------------------------**\
  771. <summary>
  772.     CA_RemoveBreakableBuildings
  773. </summary>
  774. <returns>
  775.     Always 1
  776. </returns>
  777. <remarks>
  778.     Removes all of the breakable object collisions
  779.     You must use this function before using `CA_Init`
  780. </remarks>
  781. \**--------------------------------------------------------------------------**/
  782. stock CA_RemoveBreakableBuildings()
  783. {
  784.     static const BreakableIDs[] = {
  785.         625, 626, 627, 628, 629, 630, 631, 632, 633, 642, 643, 644, 646, 650, 716, 717, 737, 738, 792, 858, 881, 882, 883,
  786.         884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 904, 905, 941, 955, 956, 959, 961, 990, 993, 996, 1209,
  787.         1211, 1213, 1219, 1220, 1221, 1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1235, 1238, 1244, 1251,
  788.         1255, 1257, 1262, 1264, 1265, 1270, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1293,
  789.         1294, 1297, 1300, 1302, 1315, 1328, 1329, 1330, 1338, 1350, 1351, 1352, 1370, 1373, 1374, 1375, 1407, 1408, 1409,
  790.         1410, 1411, 1412, 1413, 1414, 1415, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 1428, 1429, 1431,
  791.         1432, 1433, 1436, 1437, 1438, 1440, 1441, 1443, 1444, 1445, 1446, 1447, 1448, 1449, 1450, 1451, 1452, 1456, 1457,
  792.         1458, 1459, 1460, 1461, 1462, 1463, 1464, 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476,
  793.         1477, 1478, 1479, 1480, 1481, 1482, 1483, 1514, 1517, 1520, 1534, 1543, 1544, 1545, 1551, 1553, 1554, 1558, 1564,
  794.         1568, 1582, 1583, 1584, 1588, 1589, 1590, 1591, 1592, 1645, 1646, 1647, 1654, 1664, 1666, 1667, 1668, 1669, 1670,
  795.         1672, 1676, 1684, 1686, 1775, 1776, 1949, 1950, 1951, 1960, 1961, 1962, 1975, 1976, 1977, 2647, 2663, 2682, 2683,
  796.         2885, 2886, 2887, 2900, 2918, 2920, 2925, 2932, 2933, 2942, 2943, 2945, 2947, 2958, 2959, 2966, 2968, 2971, 2977,
  797.         2987, 2988, 2989, 2991, 2994, 3006, 3018, 3019, 3020, 3021, 3022, 3023, 3024, 3029, 3032, 3036, 3058, 3059, 3067,
  798.         3083, 3091, 3221, 3260, 3261, 3262, 3263, 3264, 3265, 3267, 3275, 3276, 3278, 3280, 3281, 3282, 3302, 3374, 3409,
  799.         3460, 3516, 3794, 3795, 3797, 3853, 3855, 3864, 3884, 11103, 12840, 16627, 16628, 16629, 16630, 16631, 16632,
  800.         16633, 16634, 16635, 16636, 16732, 17968
  801.     };
  802.    
  803.     for(new i = 0; i < sizeof(BreakableIDs); i++)
  804.         CA_RemoveBuilding(BreakableIDs[i], 0.0, 0.0, 0.0, 4242.6407);
  805.  
  806.     return 1;
  807. }
  808.  
  809. /**--------------------------------------------------------------------------**\
  810. <summary>
  811.     CA_IsPlayerInWater
  812. </summary>
  813. <param name="playerid">The playerid to check</param>
  814. <param name="&Float:depth">The depth</param>
  815. <param name="&Float:playerdepth">The depth of the player</param>
  816. <returns>
  817.     0 if the player is not in water
  818.     1 if the player is in water
  819. </returns>
  820. \**--------------------------------------------------------------------------**/
  821. stock CA_IsPlayerInWater(playerid, &Float:depth, &Float:playerdepth)
  822. {
  823.     new Float:x, Float:y, Float:z, Float:retx[10], Float:rety[10], Float:retz[10], Float: retdist[10], modelids[10];
  824.     GetPlayerPos(playerid, x, y, z);
  825.     new collisions = CA_RayCastMultiLine(x, y, z+1000.0, x, y, z-1000.0, retx, rety, retz, retdist, modelids, 10);
  826.     if(collisions)
  827.     {
  828.         for(new i = 0; i < collisions; i++)
  829.         {
  830.             if(modelids[i] == WATER_OBJECT)
  831.             {
  832.                 depth = INFINITY;
  833.  
  834.                 for(new j = 0; j < collisions; j++)
  835.                 {
  836.                     if(retz[j] < depth)
  837.                     depth = retz[j];
  838.                 }
  839.  
  840.                 depth = retz[i] - depth;
  841.                 if(depth < 0.001 && depth > -0.001)
  842.                     depth = 100.0;
  843.                 playerdepth = retz[i] - z;
  844.  
  845.                 if(playerdepth < -2.0)
  846.                     return 0;
  847.  
  848.                 return 1;
  849.             }
  850.         }
  851.     }
  852.     return 0;
  853. }
  854.  
  855. /**--------------------------------------------------------------------------**\
  856. <summary>
  857.     CA_IsPlayerNearWater
  858. </summary>
  859. <param name="playerid">The playerid to check</param>
  860. <param name="Float:dist = 3.0">The distance to check for water</param>
  861. <param name="Float:height = 3.0">The height the player can be from the water</param>
  862. <returns>
  863.     0 if the player is not in water
  864.     1 if the player is in water
  865. </returns>
  866. <remarks>
  867.     Checks for water all around the player
  868. </remarks>
  869. \**--------------------------------------------------------------------------**/
  870. stock CA_IsPlayerNearWater(playerid, Float:dist=3.0, Float:height=3.0)
  871. {
  872.     new Float:x, Float:y, Float:z, Float:tmp;
  873.     GetPlayerPos(playerid, x, y, z);
  874.    
  875.     for(new i; i < 6; i++)
  876.         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)
  877.             return 1;
  878.     return 0;
  879. }
  880.  
  881. /**--------------------------------------------------------------------------**\
  882. <summary>
  883.     CA_IsPlayerFacingWater
  884. </summary>
  885. <param name="playerid">The playerid to check</param>
  886. <param name="Float:dist = 3.0">The distance to check for water</param>
  887. <param name="Float:height = 3.0">The height the player can be from the water</param>
  888. <returns>
  889.     0 if the player is not in water
  890.     1 if the player is in water
  891. </returns>
  892. <remarks>
  893.     Checks for water only in front of the player
  894. </remarks>
  895. \**--------------------------------------------------------------------------**/
  896. stock CA_IsPlayerFacingWater(playerid, Float:dist=3.0, Float:height=3.0)
  897. {
  898.     new Float:x, Float:y, Float:z, Float:r, Float:tmp;
  899.     GetPlayerPos(playerid, x, y, z);
  900.     GetPlayerFacingAngle(playerid, r);
  901.  
  902.     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)
  903.         return 1;
  904.     return 0;
  905. }
  906.  
  907. /**--------------------------------------------------------------------------**\
  908. <summary>
  909.     CA_IsPlayerBlocked
  910. </summary>
  911. <param name="playerid">The playerid to check</param>
  912. <param name="Float:dist = 1.5">The distance to check for a wall</param>
  913. <param name="Float:height = 0.5">The height the wall can be from the ground</param>
  914. <returns>
  915.     0 if the player is not blocked
  916.     1 if the player is blocked
  917. </returns>
  918. \**--------------------------------------------------------------------------**/
  919. stock CA_IsPlayerBlocked(playerid, Float:dist=1.5, Float:height=0.5)
  920. {
  921.     new Float:x, Float:y, Float:z, Float:endx, Float:endy, Float:fa;
  922.     GetPlayerPos(playerid, x, y, z);
  923.     z -= 1.0 + height;
  924.     GetPlayerFacingAngle(playerid, fa);
  925.  
  926.     endx = (x + dist * floatsin(-fa,degrees));
  927.     endy = (y + dist * floatcos(-fa,degrees));
  928.     if(CA_RayCastLine(x, y, z, endx, endy, z, x, y, z))
  929.         return 1;
  930.     return 0;
  931. }
  932.  
  933. /**--------------------------------------------------------------------------**\
  934. <summary>
  935.     Float:CA_GetRoomHeight
  936. </summary>
  937. <param name="Float:x, Float:y, Float:z">A point in the area to be checked</param>
  938. <returns>
  939.     0.0 if there is either no floor or no ceiling
  940.     The distance from the ceiling to the floor
  941. </returns>
  942. \**--------------------------------------------------------------------------**/
  943. stock Float:CA_GetRoomHeight(Float:x, Float:y, Float:z)
  944. {
  945.     new Float:fx, Float:fy, Float:fz, Float:cx, Float:cy, Float:cz;
  946.     if(CA_RayCastLine(x, y, z, x, y, z-1000.0, fx, fy, fz))
  947.     {
  948.         if(CA_RayCastLine(x, y, z, x, y, z+1000.0, cx, cy, cz))
  949.             return floatsqroot(((fx-cx)*(fx-cx))+((fy-cy)*(fy-cy))+((fz-cz)*(fz-cz)));
  950.     }
  951.     return 0.0;
  952. }
  953.  
  954. /**--------------------------------------------------------------------------**\
  955. <summary>
  956.     Float:CA_GetRoomCenter
  957. </summary>
  958. <param name="Float:x, Float:y, Float:z">A point in the area to be checked</param>
  959. <param name="&Float:m_x, &Float:m_y">The center X and Y of the area</param>
  960. <returns>
  961.     -1.0 if there isn't enough collisions to determine the center
  962.     The radius of the circle formed by the test
  963. </returns>
  964. \**--------------------------------------------------------------------------**/
  965. stock Float:CA_GetRoomCenter(Float:x, Float:y, Float:z, &Float:m_x, &Float:m_y)
  966. {
  967.     new Float:pt1x, Float:pt1y,
  968.         Float:pt2x, Float:pt2y,
  969.         Float:pt3x, Float:pt3y,
  970.         Float:tmp;
  971.  
  972.     if(!CA_RayCastLine(x, y, z, x + 1000.0 * floatcos(0.0, degrees), y + 1000.0 * floatsin(0.0, degrees), z, pt1x, pt1y, tmp) ||
  973.         !CA_RayCastLine(x, y, z, x + 1000.0 * floatcos(120.0, degrees), y + 1000.0 * floatsin(120.0, degrees), z, pt2x, pt2y, tmp) ||
  974.         !CA_RayCastLine(x, y, z, x + 1000.0 * floatcos(-120.0, degrees), y + 1000.0 * floatsin(-120.0, degrees), z, pt3x, pt3y, tmp))
  975.         return -1.0;
  976.    
  977.     new Float:yDelta_a = pt2y - pt1y,
  978.         Float:xDelta_a = pt2x - pt1x,
  979.         Float:yDelta_b = pt3y - pt2y,
  980.         Float:xDelta_b = pt3x - pt2x;
  981.    
  982.     if (floatabs(xDelta_a) <= 0.000000001 && floatabs(yDelta_b) <= 0.000000001) {
  983.         m_x = 0.5 * (pt2x + pt3x);
  984.         m_y = 0.5 * (pt1y + pt2y);
  985.         return VectorSize(m_x - pt1x, m_y - pt1y, 0.0);
  986.     }
  987.    
  988.     new Float:aSlope = yDelta_a / xDelta_a,
  989.         Float:bSlope = yDelta_b / xDelta_b;
  990.    
  991.     if (floatabs(aSlope-bSlope) <= 0.000000001)
  992.         return -1.0;
  993.  
  994.     m_x = (aSlope * bSlope * (pt1y - pt3y) + bSlope * (pt1x + pt2x) - aSlope * (pt2x + pt3x)) / (2.0 * (bSlope - aSlope));
  995.     m_y = -1.0 * (m_x - (pt1x + pt2x) / 2.0) / aSlope + (pt1y + pt2y) / 2.0;
  996.  
  997.     return VectorSize(m_x - pt1x, m_y - pt1y, 0.0);
  998. }
  999.  
  1000.  
  1001. // Hooked functions
  1002. public OnFilterScriptExit()
  1003. {
  1004.     CA_DestroyAllObjects_DC();
  1005.     if (funcidx("CA_OnFilterScriptExit") != -1)
  1006.     {
  1007.         return CallLocalFunction("CA_OnFilterScriptExit", "");
  1008.     }
  1009.     return 1;
  1010.  }
  1011.  
  1012. #if defined _ALS_OnFilterScriptExit
  1013.     #undef OnFilterScriptExit
  1014. #else
  1015.     #define _ALS_OnFilterScriptExit
  1016. #endif
  1017. #define OnFilterScriptExit CA_OnFilterScriptExit
  1018.  
  1019. forward CA_OnFilterScriptExit();
  1020.  
  1021.  
  1022. public OnGameModeExit()
  1023. {
  1024.     CA_DestroyAllObjects_DC();
  1025.     if (funcidx("CA_OnGameModeExit") != -1)
  1026.     {
  1027.         return CallLocalFunction("CA_OnGameModeExit", "");
  1028.     }
  1029.     return 1;
  1030.  }
  1031.  
  1032. #if defined _ALS_OnGameModeExit
  1033.     #undef OnGameModeExit
  1034. #else
  1035.     #define _ALS_OnGameModeExit
  1036. #endif
  1037. #define OnGameModeExit CA_OnGameModeExit
  1038.  
  1039. forward CA_OnGameModeExit();
  1040.  
  1041. Create a object with collision in ColAndreas dynamic
  1042. CA_CreateObject_DC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:drawdistance = 300.0)
  1043.  
  1044. Destroy a object with collision in ColAndreas
  1045. CA_DestroyObject_DC(index)
  1046.  
  1047. Destoys all objects streamer/regular
  1048. CA_DestroyAllObjects_DC()
  1049.  
  1050. MapAndreas replacement function
  1051. CA_FindZ_For2DCoord(Float:x, Float:y, &Float:z)
  1052.  
  1053. Explode ray casts in every direction
  1054. CA_RayCastExplode(Float:cX, Float:cY, Float:cZ, Float:Radius, Float:intensity = 20.0, Float:collisions[][3])
  1055.  
  1056. Checks if a player is standing on any surface (prevent animation exploit when falling)
  1057. CA_IsOnSurface(playerid, Float:tolerance=1.5)
  1058.  
  1059. Removes all barries this function only works BEFORE using CA_Init()
  1060. CA_RemoveBarriers()
  1061.  
  1062. Removes all dynamic breakable objects, also only works BEFORE using CA_Init()
  1063. CA_RemoveBreakableBuildings()
  1064.  
  1065. Checks if a player is in the water depth returns the lowest collision point found playerdepth returns
  1066. how deep the player is below the surface
  1067. CA_IsPlayerInWater(playerid, &Float:depth, &Float:playerdepth)
  1068.  
  1069. Checks if a player is near water (returns 0 if they are actually in the water) distance is the radius to check
  1070. Height is how high above the water to detect
  1071. CA_IsNearWater(playerid, Float:dist=3.0, Float:height=3.0)
  1072.  
  1073. // Check if a player is blocked by a wall
  1074. CA_IsBlocked(playerid, Float:dist=1.5, Float:height=0.5)
  1075.  
  1076.  
  1077. Notes:
  1078.  
  1079. Recommended loading order
  1080. - RemoveBuildings
  1081. - Init static map
  1082. - Add static objects
  1083.  
  1084. There is currently no support for virtual worlds / interior or per player with streamer objects
  1085.  
  1086. */
  1087.  
  1088. // Used for other scripts to check if ColAndreas is being used
  1089. #if defined COLANDREAS
  1090.     #endinput
  1091. #endif
  1092. #define COLANDREAS
  1093.  
  1094. #define COLANDREAS_VERSION  (10400) //a.b.c 10000*a+100*b+c
  1095.  
  1096. // Default extra ID types
  1097. #define CA_EXTRA_1  0
  1098. #define CA_EXTRA_2  1
  1099. #define CA_EXTRA_3  2
  1100. #define CA_EXTRA_4  3
  1101. #define CA_EXTRA_5  4
  1102. #define CA_EXTRA_6  5
  1103. #define CA_EXTRA_7  6
  1104. #define CA_EXTRA_8  7
  1105. #define CA_EXTRA_9  8
  1106. #define CA_EXTRA_10 9
  1107.  
  1108. // Natives
  1109. native CA_Init();
  1110. native CA_RemoveBuilding(modelid, Float:x, Float:y, Float:z, Float:radius);
  1111. native CA_RayCastLine(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z);
  1112. native CA_RayCastLineID(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z);
  1113. native CA_RayCastLineExtraID(type, Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z);
  1114. 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));
  1115. 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);
  1116. 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);
  1117. 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);
  1118. native CA_ContactTest(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  1119. native CA_EulerToQuat(Float:rx, Float:ry, Float:rz, &Float:x, &Float:y, &Float:z, &Float:w);
  1120. native CA_QuatToEuler(Float:x, Float:y, Float:z, Float:w, &Float:rx, &Float:ry, &Float:rz);
  1121. native CA_GetModelBoundingSphere(modelid, &Float:offx, &Float:offy, &Float:offz, &Float:radius);
  1122. native CA_GetModelBoundingBox(modelid, &Float:minx, &Float:miny, &Float:minz, &Float:maxx, &Float:maxy, &Float:maxz);
  1123. native CA_SetObjectExtraID(index, type, data);
  1124. native CA_GetObjectExtraID(index, type);
  1125.  
  1126. // Extended raycast function returns internal pointer of mapobject class instead of modelid
  1127. 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);
  1128. 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);
  1129.  
  1130. // Used internally
  1131. native CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, bool:add = false);
  1132. native CA_DestroyObject(index);
  1133. native CA_SetObjectPos(index, Float:x, Float:y, Float:z);
  1134. native CA_SetObjectRot(index, Float:rx, Float:ry, Float:rz);
  1135.  
  1136. // ColAndreas currently supports 50000 user collision objects (This can be raised as needed)
  1137. #if defined MAX_CA_OBJECTS
  1138.     #if MAX_CA_OBJECTS > 50000
  1139.         #error [ColAndreas] MAX_CA_OBJECTS is too high, maximum value is 50000
  1140.     #endif
  1141. #else
  1142.    #define MAX_CA_OBJECTS 10000
  1143. #endif
  1144.  
  1145. // Water object ID
  1146. #define     WATER_OBJECT        20000
  1147.  
  1148. // Object types (Player objects are supported as dynamic only)
  1149. #define     OBJECT_TYPE_OBJECT  0
  1150. #define     OBJECT_TYPE_DYNAMIC 1
  1151.  
  1152.  
  1153. #if !defined INFINITY
  1154.     #define INFINITY (Float:0x7F800000)
  1155. #endif
  1156.  
  1157.  
  1158.  
  1159. #if defined _Y_ITERATE_LOCAL_VERSION
  1160.     static stock Iterator:CA_Objects<MAX_CA_OBJECTS>;
  1161. #endif
  1162.  
  1163. enum CAOBJECTINFO
  1164. {
  1165.     ColdAndreadsID,
  1166.     ObjectID,
  1167.     ObjectType,
  1168.  
  1169.     #if !defined _Y_ITERATE_LOCAL_VERSION
  1170.         bool:ObjectUsed,
  1171.     #endif
  1172. }
  1173.  
  1174. static stock CA_ObjectList[MAX_CA_OBJECTS][CAOBJECTINFO];
  1175.  
  1176. //Streamer
  1177. #if defined STREAMER_TYPE_OBJECT
  1178.  
  1179.     // Static collision object functions (The index is not returned these can not be deleted!)
  1180.     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)
  1181.     {
  1182.         new id = CreateDynamicObjectEx(modelid, x, y, z, rx, ry, rz, streamdistance, drawdistance, worlds, interiors, players, areas, maxworlds, maxinteriors, maxplayers, maxareas);
  1183.         CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  1184.         return id;
  1185.     }
  1186.  
  1187.     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)
  1188.     {
  1189.         new id = CreateDynamicObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, vw, interior, playerid, streamdistance, drawdistance, areaid, priority);
  1190.         CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  1191.         return id;
  1192.     }
  1193.  
  1194.     stock CA_CreateObject_SC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:drawdistance = 300.0)
  1195.     {
  1196.         new id = CreateObject(modelid, x, y, z, rx, ry, rz, drawdistance);
  1197.         if(id != INVALID_OBJECT_ID) CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  1198.         return id;
  1199.     }
  1200.  
  1201.     // Dynamic collision object functions (Removable)
  1202.     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)
  1203.     {
  1204.         new index = -1;
  1205.         #if defined _Y_ITERATE_LOCAL_VERSION
  1206.             index = Iter_Free(CA_Objects);
  1207.         #else
  1208.             for(new i = 0; i < MAX_CA_OBJECTS; i++)
  1209.             {
  1210.                 if(CA_ObjectList[i][ObjectUsed] == false)
  1211.                 {
  1212.                     index = i;
  1213.                     break;
  1214.                 }
  1215.             }
  1216.         #endif
  1217.  
  1218.         if(index > -1)
  1219.         {
  1220.             #if defined _Y_ITERATE_LOCAL_VERSION
  1221.                 Iter_Add(CA_Objects, index);
  1222.             #else
  1223.                 CA_ObjectList[index][ObjectUsed] = true;
  1224.             #endif
  1225.             CA_ObjectList[index][ObjectID] = CreateDynamicObjectEx(modelid, x, y, z, rx, ry, rz, drawdistance, streamdistance, worlds, interiors, players, areas, maxworlds, maxinteriors, maxplayers, maxareas);
  1226.             CA_ObjectList[index][ColdAndreadsID] = CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, true);
  1227.             CA_ObjectList[index][ObjectType] = OBJECT_TYPE_DYNAMIC;
  1228.         }
  1229.         return index;
  1230.     }
  1231.  
  1232.  
  1233.     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)
  1234.     {
  1235.         new index = -1;
  1236.         #if defined _Y_ITERATE_LOCAL_VERSION
  1237.             index = Iter_Free(CA_Objects);
  1238.         #else
  1239.             for(new i = 0; i < MAX_CA_OBJECTS; i++)
  1240.             {
  1241.                 if(CA_ObjectList[i][ObjectUsed] == false)
  1242.                 {
  1243.                     index = i;
  1244.                     break;
  1245.                 }
  1246.             }
  1247.         #endif
  1248.  
  1249.         if(index > -1)
  1250.         {
  1251.             #if defined _Y_ITERATE_LOCAL_VERSION
  1252.                 Iter_Add(CA_Objects, index);
  1253.             #else
  1254.                 CA_ObjectList[index][ObjectUsed] = true;
  1255.             #endif
  1256.             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);
  1257.             CA_ObjectList[index][ColdAndreadsID] = CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, true);
  1258.             CA_ObjectList[index][ObjectType] = OBJECT_TYPE_DYNAMIC;
  1259.         }
  1260.         return index;
  1261.     }
  1262. #endif
  1263.  
  1264. stock CA_CreateObject_DC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:drawdistance = 300.0)
  1265. {
  1266.     new index = -1;
  1267.     #if defined _Y_ITERATE_LOCAL_VERSION
  1268.         index = Iter_Free(CA_Objects);
  1269.     #else
  1270.         for(new i = 0; i < MAX_CA_OBJECTS; i++)
  1271.         {
  1272.             if(CA_ObjectList[i][ObjectUsed] == false)
  1273.             {
  1274.                 index = i;
  1275.                 break;
  1276.             }
  1277.         }
  1278.     #endif
  1279.  
  1280.     new id = CreateObject(modelid, x, y, z, rx, ry, rz, drawdistance);
  1281.     if(id == INVALID_OBJECT_ID) return -1;
  1282.     if(index > -1)
  1283.     {
  1284.         #if defined _Y_ITERATE_LOCAL_VERSION
  1285.             Iter_Add(CA_Objects, index);
  1286.         #else
  1287.             CA_ObjectList[index][ObjectUsed] = true;
  1288.         #endif
  1289.         CA_ObjectList[index][ObjectID] = id;
  1290.         CA_ObjectList[index][ColdAndreadsID] = CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, true);
  1291.         CA_ObjectList[index][ObjectType] = OBJECT_TYPE_OBJECT;
  1292.     }
  1293.     return index;
  1294. }
  1295.  
  1296.  
  1297. stock CA_DestroyObject_DC(index)
  1298. {
  1299.     // Out of bounds
  1300.     if(index < 0 || index >= MAX_CA_OBJECTS) return -1;
  1301.     #if defined _Y_ITERATE_LOCAL_VERSION
  1302.         if(Iter_Contains(CA_Objects, index))
  1303.         {
  1304.             new next;
  1305.             Iter_SafeRemove(CA_Objects, index, next);
  1306.             if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) DestroyObject(CA_ObjectList[index][ObjectID]);
  1307.             #if defined STREAMER_TYPE_OBJECT
  1308.             else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) DestroyDynamicObject(CA_ObjectList[index][ObjectID]);
  1309.             #endif
  1310.             CA_DestroyObject(CA_ObjectList[index][ColdAndreadsID]);
  1311.             return next;
  1312.         }
  1313.     #else
  1314.     if(CA_ObjectList[index][ObjectUsed])
  1315.     {
  1316.         if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) DestroyObject(CA_ObjectList[index][ObjectID]);
  1317.         #if defined STREAMER_TYPE_OBJECT
  1318.         else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) DestroyDynamicObject(CA_ObjectList[index][ObjectID]);
  1319.         #endif
  1320.         CA_ObjectList[index][ObjectUsed] = false;
  1321.         CA_DestroyObject(CA_ObjectList[index][ColdAndreadsID]);
  1322.         return 1;
  1323.     }
  1324.     #endif
  1325.     return -1;
  1326. }
  1327.  
  1328. stock CA_SetObjectPos_DC(index, Float:x, Float:y, Float:z)
  1329. {
  1330.     // Out of bounds
  1331.     if(index < 0 || index >= MAX_CA_OBJECTS) return -1;
  1332.     #if defined _Y_ITERATE_LOCAL_VERSION
  1333.         if(Iter_Contains(CA_Objects, index))
  1334.         {
  1335.             if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  1336.             #if defined STREAMER_TYPE_OBJECT
  1337.                 else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  1338.             #endif
  1339.             CA_SetObjectPos(CA_ObjectList[index][ColdAndreadsID], x, y, z);
  1340.         }
  1341.     #else
  1342.     if(CA_ObjectList[index][ObjectUsed])
  1343.     {
  1344.         if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  1345.         #if defined STREAMER_TYPE_OBJECT
  1346.         else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  1347.         #endif
  1348.         SetObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  1349.         CA_SetObjectPos(CA_ObjectList[index][ColdAndreadsID], x, y, z);
  1350.         return 1;
  1351.     }
  1352.     #endif
  1353.     return -1;
  1354. }
  1355.  
  1356. stock CA_SetObjectRot_DC(index, Float:rx, Float:ry, Float:rz)
  1357. {
  1358.     // Out of bounds
  1359.     if(index < 0 || index >= MAX_CA_OBJECTS) return -1;
  1360.     #if defined _Y_ITERATE_LOCAL_VERSION
  1361.         if(Iter_Contains(CA_Objects, index))
  1362.         {
  1363.             if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  1364.             #if defined STREAMER_TYPE_OBJECT
  1365.                 else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  1366.             #endif
  1367.             CA_SetObjectRot(CA_ObjectList[index][ColdAndreadsID], rx, ry, rz);
  1368.         }
  1369.     #else
  1370.     if(CA_ObjectList[index][ObjectUsed])
  1371.     {
  1372.         if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  1373.         #if defined STREAMER_TYPE_OBJECT
  1374.             else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  1375.         #endif
  1376.         CA_SetObjectRot(CA_ObjectList[index][ColdAndreadsID], rx, ry, rz);
  1377.         return 1;
  1378.     }
  1379.     #endif
  1380.     return -1;
  1381. }
  1382.  
  1383. // Destroy all objects
  1384. stock CA_DestroyAllObjects_DC()
  1385. {
  1386.     #if defined _Y_ITERATE_LOCAL_VERSION
  1387.         foreach(new i : CA_Objects)
  1388.         {
  1389.             if(CA_ObjectList[i][ObjectType] == OBJECT_TYPE_OBJECT) i = CA_DestroyObject_DC(i);
  1390.         }
  1391.     #else
  1392.         for(new i = 0; i < MAX_CA_OBJECTS; i++)
  1393.         {
  1394.             if(CA_ObjectList[i][ObjectUsed])
  1395.             {
  1396.                 if(CA_ObjectList[i][ObjectType] == OBJECT_TYPE_OBJECT) CA_DestroyObject_DC(i);
  1397.             }
  1398.         }
  1399.  
  1400.     #endif
  1401. }
  1402.  
  1403. // MapAndreas simulation
  1404. stock CA_FindZ_For2DCoord(Float:x, Float:y, &Float:z)
  1405. {
  1406.     if(CA_RayCastLine(x, y, 700.0, x, y, -1000.0, x, y, z)) return 1;
  1407.     return 0;
  1408. }
  1409.  
  1410. // Explode ray casts in every direction
  1411. stock CA_RayCastExplode(Float:cX, Float:cY, Float:cZ, Float:Radius, Float:intensity = 20.0, Float:collisions[][3])
  1412. {
  1413.     if(intensity < 1.0 || intensity > 360.0 || (((360.0 / intensity) - floatround((360.0 / intensity), floatround_floor)) * intensity))
  1414.         return 0;
  1415.  
  1416.     new index;
  1417.     for(new Float:lat = -180.0; lat < 180.0; lat += (intensity * 0.75))
  1418.     for(new Float:lon = -90.0; lon < 90.0; lon += intensity)
  1419.     {
  1420.         new Float:LAT = lat * 3.141593 / 180.0,
  1421.             Float:LON = lon * 3.141593 / 180.0,
  1422.             Float:x = -Radius * floatcos(LAT) * floatcos(LON),
  1423.             Float:y = Radius * floatcos(LAT) * floatsin(LON),
  1424.             Float:z = Radius * floatsin(LAT);
  1425.        
  1426.         if(CA_RayCastLine(cX, cY, cZ, cX + x, cY + y, cZ + z, x, y, z))
  1427.         {
  1428.             collisions[index][0] = x;
  1429.             collisions[index][1] = y;
  1430.             collisions[index][2] = z;
  1431.             index++;
  1432.         }
  1433.     }
  1434.    
  1435.     return index;
  1436. }
  1437.  
  1438. // Check if a player is standing on a surface
  1439. stock CA_IsPlayerOnSurface(playerid, Float:tolerance=1.5)
  1440. {
  1441.     new Float:x, Float:y, Float:z;
  1442.     GetPlayerPos(playerid, x, y, z);
  1443.  
  1444.     // Check if player is actually on the ground
  1445.     if(!CA_RayCastLine(x, y, z, x, y, z-tolerance, x, y, z))
  1446.         return 0;
  1447.     return 1;
  1448. }
  1449.  
  1450. // remove all barries
  1451. stock CA_RemoveBarriers()
  1452. {
  1453.     static const BarrierIDS[] = {
  1454.         16439, 16438, 16437, 16436, 4527, 4526, 4525, 4524,
  1455.         4523, 4517, 4516, 4515, 4514, 4513, 4512, 4511, 4510,
  1456.         4509, 4508, 4507, 4506, 4505, 4504, 1662
  1457.     };
  1458.    
  1459.     for(new i = 0; i < sizeof(BarrierIDS); i++)
  1460.         CA_RemoveBuilding(BarrierIDS[i], 0.0, 0.0, 0.0, 4242.6407);
  1461.  
  1462.     return 1;
  1463. }
  1464.  
  1465. // remove all breakables
  1466. stock CA_RemoveBreakableBuildings()
  1467. {
  1468.     static const BreakableIDs[] = {
  1469.         625, 626, 627, 628, 629, 630, 631, 632, 633, 642, 643, 644, 646, 650, 716, 717, 737, 738, 792, 858, 881, 882, 883,
  1470.         884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 904, 905, 941, 955, 956, 959, 961, 990, 993, 996, 1209,
  1471.         1211, 1213, 1219, 1220, 1221, 1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1235, 1238, 1244, 1251,
  1472.         1255, 1257, 1262, 1264, 1265, 1270, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1293,
  1473.         1294, 1297, 1300, 1302, 1315, 1328, 1329, 1330, 1338, 1350, 1351, 1352, 1370, 1373, 1374, 1375, 1407, 1408, 1409,
  1474.         1410, 1411, 1412, 1413, 1414, 1415, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 1428, 1429, 1431,
  1475.         1432, 1433, 1436, 1437, 1438, 1440, 1441, 1443, 1444, 1445, 1446, 1447, 1448, 1449, 1450, 1451, 1452, 1456, 1457,
  1476.         1458, 1459, 1460, 1461, 1462, 1463, 1464, 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476,
  1477.         1477, 1478, 1479, 1480, 1481, 1482, 1483, 1514, 1517, 1520, 1534, 1543, 1544, 1545, 1551, 1553, 1554, 1558, 1564,
  1478.         1568, 1582, 1583, 1584, 1588, 1589, 1590, 1591, 1592, 1645, 1646, 1647, 1654, 1664, 1666, 1667, 1668, 1669, 1670,
  1479.         1672, 1676, 1684, 1686, 1775, 1776, 1949, 1950, 1951, 1960, 1961, 1962, 1975, 1976, 1977, 2647, 2663, 2682, 2683,
  1480.         2885, 2886, 2887, 2900, 2918, 2920, 2925, 2932, 2933, 2942, 2943, 2945, 2947, 2958, 2959, 2966, 2968, 2971, 2977,
  1481.         2987, 2988, 2989, 2991, 2994, 3006, 3018, 3019, 3020, 3021, 3022, 3023, 3024, 3029, 3032, 3036, 3058, 3059, 3067,
  1482.         3083, 3091, 3221, 3260, 3261, 3262, 3263, 3264, 3265, 3267, 3275, 3276, 3278, 3280, 3281, 3282, 3302, 3374, 3409,
  1483.         3460, 3516, 3794, 3795, 3797, 3853, 3855, 3864, 3884, 11103, 12840, 16627, 16628, 16629, 16630, 16631, 16632,
  1484.         16633, 16634, 16635, 16636, 16732, 17968
  1485.     };
  1486.    
  1487.     for(new i = 0; i < sizeof(BreakableIDs); i++)
  1488.         CA_RemoveBuilding(BreakableIDs[i], 0.0, 0.0, 0.0, 4242.6407);
  1489.  
  1490.     return 1;
  1491. }
  1492.  
  1493. // Checks if player is in the water
  1494. stock CA_IsPlayerInWater(playerid, &Float:depth, &Float:playerdepth)
  1495. {
  1496.     new Float:x, Float:y, Float:z, Float:retx[10], Float:rety[10], Float:retz[10], Float: retdist[10], modelids[10];
  1497.     GetPlayerPos(playerid, x, y, z);
  1498.     new collisions = CA_RayCastMultiLine(x, y, z+1000.0, x, y, z-1000.0, retx, rety, retz, retdist, modelids, 10);
  1499.     if(collisions)
  1500.     {
  1501.         for(new i = 0; i < collisions; i++)
  1502.         {
  1503.             if(modelids[i] == WATER_OBJECT)
  1504.             {
  1505.                 depth = INFINITY;
  1506.  
  1507.                 for(new j = 0; j < collisions; j++)
  1508.                 {
  1509.                     if(retz[j] < depth)
  1510.                     depth = retz[j];
  1511.                 }
  1512.  
  1513.                 depth = retz[i] - depth;
  1514.                 if(depth < 0.001 && depth > -0.001)
  1515.                     depth = 100.0;
  1516.                 playerdepth = retz[i] - z;
  1517.  
  1518.                 if(playerdepth < -2.0)
  1519.                     return 0;
  1520.  
  1521.                 return 1;
  1522.             }
  1523.         }
  1524.     }
  1525.     return 0;
  1526. }
  1527.  
  1528. // Check if player is near water
  1529. stock CA_IsPlayerNearWater(playerid, Float:dist=3.0, Float:height=3.0)
  1530. {
  1531.     new Float:x, Float:y, Float:z, Float:tmp;
  1532.     GetPlayerPos(playerid, x, y, z);
  1533.    
  1534.     for(new i; i < 6; i++)
  1535.         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)
  1536.             return 1;
  1537.     return 0;
  1538. }
  1539.  
  1540. // Check if player is facing water
  1541. stock CA_IsPlayerFacingWater(playerid, Float:dist=3.0, Float:height=3.0)
  1542. {
  1543.     new Float:x, Float:y, Float:z, Float:r, Float:tmp;
  1544.     GetPlayerPos(playerid, x, y, z);
  1545.     GetPlayerFacingAngle(playerid, r);
  1546.  
  1547.     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)
  1548.         return 1;
  1549.     return 0;
  1550. }
  1551.  
  1552. // Checks if a player is blocked by a wall
  1553. stock CA_IsPlayerBlocked(playerid, Float:dist=1.5, Float:height=0.5)
  1554. {
  1555.     new Float:x, Float:y, Float:z, Float:endx, Float:endy, Float:fa;
  1556.     GetPlayerPos(playerid, x, y, z);
  1557.     z -= 1.0 + height;
  1558.     GetPlayerFacingAngle(playerid, fa);
  1559.  
  1560.     endx = (x + dist * floatsin(-fa,degrees));
  1561.     endy = (y + dist * floatcos(-fa,degrees));
  1562.     if(CA_RayCastLine(x, y, z, endx, endy, z, x, y, z))
  1563.         return 1;
  1564.     return 0;
  1565. }
  1566.  
  1567. stock Float:CA_GetRoomHeight(Float:x, Float:y, Float:z)
  1568. {
  1569.     new Float:fx, Float:fy, Float:fz, Float:cx, Float:cy, Float:cz;
  1570.     if(CA_RayCastLine(x, y, z, x, y, z-1000.0, fx, fy, fz))
  1571.     {
  1572.         if(CA_RayCastLine(x, y, z, x, y, z+1000.0, cx, cy, cz))
  1573.             return floatsqroot(((fx-cx)*(fx-cx))+((fy-cy)*(fy-cy))+((fz-cz)*(fz-cz)));
  1574.     }
  1575.     return 0.0;
  1576. }
  1577.  
  1578. stock Float:CA_GetRoomCenter(Float:x, Float:y, Float:z, &Float:m_x, &Float:m_y)
  1579. {
  1580.     new Float:pt1x, Float:pt1y,
  1581.         Float:pt2x, Float:pt2y,
  1582.         Float:pt3x, Float:pt3y,
  1583.         Float:tmp;
  1584.  
  1585.     if(!CA_RayCastLine(x, y, z, x + 1000.0 * floatcos(0.0, degrees), y + 1000.0 * floatsin(0.0, degrees), z, pt1x, pt1y, tmp) ||
  1586.         !CA_RayCastLine(x, y, z, x + 1000.0 * floatcos(120.0, degrees), y + 1000.0 * floatsin(120.0, degrees), z, pt2x, pt2y, tmp) ||
  1587.         !CA_RayCastLine(x, y, z, x + 1000.0 * floatcos(-120.0, degrees), y + 1000.0 * floatsin(-120.0, degrees), z, pt3x, pt3y, tmp))
  1588.         return -1.0;
  1589.    
  1590.     new Float:yDelta_a = pt2y - pt1y,
  1591.         Float:xDelta_a = pt2x - pt1x,
  1592.         Float:yDelta_b = pt3y - pt2y,
  1593.         Float:xDelta_b = pt3x - pt2x;
  1594.    
  1595.     if (floatabs(xDelta_a) <= 0.000000001 && floatabs(yDelta_b) <= 0.000000001) {
  1596.         m_x = 0.5 * (pt2x + pt3x);
  1597.         m_y = 0.5 * (pt1y + pt2y);
  1598.         return VectorSize(m_x - pt1x, m_y - pt1y, 0.0);
  1599.     }
  1600.    
  1601.     new Float:aSlope = yDelta_a / xDelta_a,
  1602.         Float:bSlope = yDelta_b / xDelta_b;
  1603.    
  1604.     if (floatabs(aSlope-bSlope) <= 0.000000001)
  1605.         return -1.0;
  1606.  
  1607.     m_x = (aSlope * bSlope * (pt1y - pt3y) + bSlope * (pt1x + pt2x) - aSlope * (pt2x + pt3x)) / (2.0 * (bSlope - aSlope));
  1608.     m_y = -1.0 * (m_x - (pt1x + pt2x) / 2.0) / aSlope + (pt1y + pt2y) / 2.0;
  1609.  
  1610.     return VectorSize(m_x - pt1x, m_y - pt1y, 0.0);
  1611. }
  1612.  
  1613.  
  1614. // Hooked functions
  1615. public OnFilterScriptExit()
  1616. {
  1617.     CA_DestroyAllObjects_DC();
  1618.     if (funcidx("CA_OnFilterScriptExit") != -1)
  1619.     {
  1620.         return CallLocalFunction("CA_OnFilterScriptExit", "");
  1621.     }
  1622.     return 1;
  1623.  }
  1624.  
  1625. #if defined _ALS_OnFilterScriptExit
  1626.     #undef OnFilterScriptExit
  1627. #else
  1628.     #define _ALS_OnFilterScriptExit
  1629. #endif
  1630. #define OnFilterScriptExit CA_OnFilterScriptExit
  1631.  
  1632. forward CA_OnFilterScriptExit();
  1633.  
  1634.  
  1635. public OnGameModeExit()
  1636. {
  1637.     CA_DestroyAllObjects_DC();
  1638.     if (funcidx("CA_OnGameModeExit") != -1)
  1639.     {
  1640.         return CallLocalFunction("CA_OnGameModeExit", "");
  1641.     }
  1642.     return 1;
  1643.  }
  1644.  
  1645. #if defined _ALS_OnGameModeExit
  1646.     #undef OnGameModeExit
  1647. #else
  1648.     #define _ALS_OnGameModeExit
  1649. #endif
  1650. #define OnGameModeExit CA_OnGameModeExit
  1651.  
  1652. forward CA_OnGameModeExit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement