colandreas.inc 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // ColAndreas Plugin Include ///////////////////////////////////////////////////
  3. ////////////////////////////////////////////////////////////////////////////////
  4. #if defined COLANDREAS_VERSION
  5. #endinput
  6. #endif
  7. #define COLANDREAS_VERSION (10400) //a.b.c 10000*a+100*b+c
  8. // Default extra ID types
  9. #define CA_EXTRA_1 0
  10. #define CA_EXTRA_2 1
  11. #define CA_EXTRA_3 2
  12. #define CA_EXTRA_4 3
  13. #define CA_EXTRA_5 4
  14. #define CA_EXTRA_6 5
  15. #define CA_EXTRA_7 6
  16. #define CA_EXTRA_8 7
  17. #define CA_EXTRA_9 8
  18. #define CA_EXTRA_10 9
  19. // ColAndreas currently supports 50000 user collision objects (This can be raised as needed)
  20. #if defined MAX_CA_OBJECTS
  21. #if MAX_CA_OBJECTS > 50000
  22. #error [ColAndreas] MAX_CA_OBJECTS is too high, maximum value is 50000
  23. #endif
  24. #else
  25. #define MAX_CA_OBJECTS 10000
  26. #endif
  27. // Water object ID
  28. #define WATER_OBJECT 20000
  29. // Object types (Player objects are supported as dynamic only)
  30. #define OBJECT_TYPE_OBJECT 0
  31. #define OBJECT_TYPE_DYNAMIC 1
  32. #if !defined INFINITY
  33. #define INFINITY (Float:0x7F800000)
  34. #endif
  35. /**--------------------------------------------------------------------------**\
  36. <summary>
  37. CA_Init
  38. </summary>
  39. <returns>
  40. 0 when there is no data loaded (ex. when you don't have the data file)
  41. 1 when loaded map successfully or was already loaded
  42. </returns>
  43. \**--------------------------------------------------------------------------**/
  44. native CA_Init();
  45. /**--------------------------------------------------------------------------**\
  46. <summary>
  47. CA_RemoveBuilding
  48. </summary>
  49. <param name="modelid">The model to be removed</param>
  50. <param name="Float:x, Float:y, Float:z">The coordinates in which the objects will be removed</param>
  51. <param name="Float:radius">The radius around the specified point to remove from</param>
  52. <returns>
  53. 0 when the map is already initialized
  54. 1 when successfully removed
  55. </returns>
  56. <remarks>
  57. You must use this function before using `CA_Init`
  58. </remarks>
  59. \**--------------------------------------------------------------------------**/
  60. native CA_RemoveBuilding(modelid, Float:x, Float:y, Float:z, Float:radius);
  61. /**--------------------------------------------------------------------------**\
  62. <summary>
  63. CA_RayCastLine
  64. </summary>
  65. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  66. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  67. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  68. <returns>
  69. 0 if the ray didn't collide with anything
  70. WATER_OBJECT if the ray collided with water
  71. The model of the object the ray collided
  72. </returns>
  73. \**--------------------------------------------------------------------------**/
  74. native CA_RayCastLine(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z);
  75. /**--------------------------------------------------------------------------**\
  76. <summary>
  77. CA_RayCastLineID
  78. </summary>
  79. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  80. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  81. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  82. <returns>
  83. -1 if the ray collided with a static object or water
  84. 0 if the ray didn't collide with anything
  85. The index of the object the ray collided
  86. </returns>
  87. <remarks>
  88. This only works with objects created with `add` enabled in `CA_CreateObject`, such as the objects created by the "_DC" functions
  89. </remarks>
  90. \**--------------------------------------------------------------------------**/
  91. native CA_RayCastLineID(Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z);
  92. /**--------------------------------------------------------------------------**\
  93. <summary>
  94. CA_RayCastLineExtraID
  95. </summary>
  96. <param name="type">The extra ID index</param>
  97. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  98. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  99. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  100. <returns>
  101. -1 if the ray collided with a static object or water
  102. -1 if the extra ID is unmodified
  103. 0 if the ray didn't collide with anything
  104. The index of the object the ray collided
  105. </returns>
  106. <remarks>
  107. This only works with objects created with `add` enabled in `CA_CreateObject`, such as the objects created by the "_DC" functions
  108. </remarks>
  109. \**--------------------------------------------------------------------------**/
  110. native CA_RayCastLineExtraID(type, Float:StartX, Float:StartY, Float:StartZ, Float:EndX, Float:EndY, Float:EndZ, &Float:x, &Float:y, &Float:z);
  111. /**--------------------------------------------------------------------------**\
  112. <summary>
  113. CA_RayCastMultiLine
  114. </summary>
  115. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  116. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  117. <param name="Float:retx[], Float:rety[], Float:retz[]">The points that the ray collided</param>
  118. <param name="Float:retdist[]">The distances between the beginning point and the point collided</param>
  119. <param name="ModelIDs[]">The object models that the ray collided</param>
  120. <param name="size = sizeof(retx)">The maximum number of points to collide</param>
  121. <returns>
  122. -1 if the ray collided with more points than than permitted by the `size` parameter
  123. 0 if the ray didn't collide with anything
  124. The number of points collided
  125. </returns>
  126. \**--------------------------------------------------------------------------**/
  127. 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));
  128. /**--------------------------------------------------------------------------**\
  129. <summary>
  130. CA_RayCastLineAngle
  131. </summary>
  132. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  133. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  134. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  135. <param name="&Float:rx, &Float:ry, &Float:rz">The rotation of the face that the ray collided</param>
  136. <returns>
  137. 0 if the ray didn't collide with anything
  138. WATER_OBJECT if the ray collided with water
  139. The model of the object the ray collided
  140. </returns>
  141. \**--------------------------------------------------------------------------**/
  142. 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);
  143. /**--------------------------------------------------------------------------**\
  144. <summary>
  145. CA_RayCastReflectionVector
  146. </summary>
  147. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  148. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  149. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  150. <param name="&Float:nx, &Float:ny, &Float:nz">The reflection vector of the face that the ray collided</param>
  151. <returns>
  152. 0 if the ray didn't collide with anything
  153. WATER_OBJECT if the ray collided with water
  154. The model of the object the ray collided
  155. </returns>
  156. \**--------------------------------------------------------------------------**/
  157. 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);
  158. /**--------------------------------------------------------------------------**\
  159. <summary>
  160. CA_RayCastLineNormal
  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 surface normal 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_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);
  173. /**--------------------------------------------------------------------------**\
  174. <summary>
  175. CA_ContactTest
  176. </summary>
  177. <param name="modelid">The object model to be tested</param>
  178. <param name="Float:x, Float:y, Float:z">The object position to test</param>
  179. <param name="Float:rx, Float:ry, Float:rz">The object rotation to test</param>
  180. <returns>
  181. 0 if the object model doesn't collide with the world with the specified
  182. 1 otherwise
  183. </returns>
  184. \**--------------------------------------------------------------------------**/
  185. native CA_ContactTest(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  186. /**--------------------------------------------------------------------------**\
  187. <summary>
  188. CA_EulerToQuat
  189. </summary>
  190. <param name="Float:rx, Float:ry, Float:rz">GTA euler rotations to be converted</param>
  191. <param name="&Float:x, &Float:y, &Float:z, &Float:w">The quaternion angles returned</param>
  192. <returns>
  193. Always 1
  194. </returns>
  195. \**--------------------------------------------------------------------------**/
  196. native CA_EulerToQuat(Float:rx, Float:ry, Float:rz, &Float:x, &Float:y, &Float:z, &Float:w);
  197. /**--------------------------------------------------------------------------**\
  198. <summary>
  199. CA_QuatToEuler
  200. </summary>
  201. <param name="&Float:x, &Float:y, &Float:z, &Float:w">The quaternion angles to be converted</param>
  202. <param name="Float:rx, Float:ry, Float:rz">GTA euler rotations returned</param>
  203. <returns>
  204. Always 1
  205. </returns>
  206. \**--------------------------------------------------------------------------**/
  207. native CA_QuatToEuler(Float:x, Float:y, Float:z, Float:w, &Float:rx, &Float:ry, &Float:rz);
  208. /**--------------------------------------------------------------------------**\
  209. <summary>
  210. CA_GetModelBoundingSphere
  211. </summary>
  212. <param name="modelid">The object model</param>
  213. <param name="&Float:offx, &Float:offy, &Float:offz">The offset of the model's bounding sphere</param>
  214. <param name="&Float:radius">The radius of the model's bounding sphere</param>
  215. <returns>
  216. 0 if the model is invalid
  217. 1 otherwise
  218. </returns>
  219. \**--------------------------------------------------------------------------**/
  220. native CA_GetModelBoundingSphere(modelid, &Float:offx, &Float:offy, &Float:offz, &Float:radius);
  221. /**--------------------------------------------------------------------------**\
  222. <summary>
  223. CA_GetModelBoundingBox
  224. </summary>
  225. <param name="modelid">The object model</param>
  226. <param name="&Float:minx, &Float:miny, &Float:minz">The "minimum" point of the model's bounding box</param>
  227. <param name="&Float:maxx, &Float:maxy, &Float:maxz">The "maximum" point of the model's bounding box</param>
  228. <returns>
  229. 0 if the model is invalid
  230. 1 otherwise
  231. </returns>
  232. \**--------------------------------------------------------------------------**/
  233. native CA_GetModelBoundingBox(modelid, &Float:minx, &Float:miny, &Float:minz, &Float:maxx, &Float:maxy, &Float:maxz);
  234. /**--------------------------------------------------------------------------**\
  235. <summary>
  236. CA_SetObjectExtraID
  237. </summary>
  238. <param name="index">The index of the ColAndreas object</param>
  239. <param name="type">The index of the extra ID to be set</param>
  240. <param name="data">The data stored in the extra ID</param>
  241. <returns>
  242. Always 1 (which needs to be changed to be like CA_GetObjectExtraID's returns...)
  243. </returns>
  244. \**--------------------------------------------------------------------------**/
  245. native CA_SetObjectExtraID(index, type, data);
  246. /**--------------------------------------------------------------------------**\
  247. <summary>
  248. CA_GetObjectExtraID
  249. </summary>
  250. <param name="index">The index of the ColAndreas object</param>
  251. <param name="type">The index of the extra ID to be set</param>
  252. <returns>
  253. -1 if the index or type is invalid
  254. The data stored in the extra ID
  255. </returns>
  256. \**--------------------------------------------------------------------------**/
  257. native CA_GetObjectExtraID(index, type);
  258. /**--------------------------------------------------------------------------**\
  259. <summary>
  260. CA_RayCastLineEx
  261. </summary>
  262. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  263. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  264. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  265. <param name="&Float:rx, &Float:ry, &Float:rz, &Float:rw">The quaternion rotation of the object that the ray collided</param>
  266. <param name="&Float:cx, &Float:cy, &Float:cz">The position of the object that the ray collided</param>
  267. <returns>
  268. 0 if the ray didn't collide with anything
  269. WATER_OBJECT if the ray collided with water
  270. The model of the object the ray collided
  271. </returns>
  272. \**--------------------------------------------------------------------------**/
  273. 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);
  274. /**--------------------------------------------------------------------------**\
  275. <summary>
  276. CA_RayCastLineAngleEx
  277. </summary>
  278. <param name="Float:StartX, Float:StartY, Float:StartZ">The beginning point of the ray</param>
  279. <param name="Float:EndX, Float:EndY, Float:EndZ">The ending point of the ray</param>
  280. <param name="&Float:x, &Float:y, &Float:z">The point that the ray collided</param>
  281. <param name="&Float:rx, &Float:ry, &Float:rz">The rotation of the face that the ray collided</param>
  282. <param name="&Float:ocx, &Float:ocy, &Float:ocz">The position of the object that the ray collided</param>
  283. <param name="&Float:orx, &Float:ory, &Float:orz">The rotation of the object that the ray collided</param>
  284. <returns>
  285. 0 if the ray didn't collide with anything
  286. WATER_OBJECT if the ray collided with water
  287. The model of the object the ray collided
  288. </returns>
  289. \**--------------------------------------------------------------------------**/
  290. 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);
  291. // Internal Functions:
  292. /**--------------------------------------------------------------------------**\
  293. <summary>
  294. CA_CreateObject
  295. </summary>
  296. <param name="modelid">The collision model to create</param>
  297. <param name="Float:x, Float:y, Float:z">The position in which to create the collision model</param>
  298. <param name="Float:rx, Float:ry, Float:rz">The rotation of the collision model</param>
  299. <param name="bool:add = false">Whether or not to store this objects index for manual management</param>
  300. <returns>
  301. -1 if the specified model has no collision (should be changed to -2, to avoid confusion with unmanaged objects)
  302. -1 if `add` is false
  303. The index of the created collision object
  304. </returns>
  305. <remarks>
  306. ONLY CREATES THE COLLISION, NOT THE IN-GAME OBJECT
  307. </remarks>
  308. \**--------------------------------------------------------------------------**/
  309. native CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, bool:add = false);
  310. /**--------------------------------------------------------------------------**\
  311. <summary>
  312. CA_DestroyObject
  313. </summary>
  314. <param name="index">The index of the object to be destroyed</param>
  315. <returns>
  316. -1 if the specified model has no collision (should be changed to -2, to avoid confusion with unmanaged objects)
  317. -1 if `add` is false
  318. The index of the created collision object
  319. </returns>
  320. \**--------------------------------------------------------------------------**/
  321. native CA_DestroyObject(index);
  322. /**--------------------------------------------------------------------------**\
  323. <summary>
  324. CA_SetObjectPos
  325. </summary>
  326. <param name="index">The index of the object to be moved</param>
  327. <param name="Float:x, Float:y, Float:z">The new position</param>
  328. <returns>
  329. 0 if the object doesn't exist
  330. 1 if the new position was set successfully
  331. </returns>
  332. \**--------------------------------------------------------------------------**/
  333. native CA_SetObjectPos(index, Float:x, Float:y, Float:z);
  334. /**--------------------------------------------------------------------------**\
  335. <summary>
  336. CA_SetObjectRot
  337. </summary>
  338. <param name="index">The index of the object to be moved</param>
  339. <param name="Float:rx, Float:ry, Float:rz">The new rotation</param>
  340. <returns>
  341. 0 if the object doesn't exist
  342. 1 if the new rotation was set successfully
  343. </returns>
  344. \**--------------------------------------------------------------------------**/
  345. native CA_SetObjectRot(index, Float:rx, Float:ry, Float:rz);
  346. #if defined _Y_ITERATE_LOCAL_VERSION
  347. static stock Iterator:CA_Objects<MAX_CA_OBJECTS>;
  348. #endif
  349. enum CAOBJECTINFO
  350. {
  351. ColdAndreadsID,
  352. ObjectID,
  353. ObjectType,
  354. #if !defined _Y_ITERATE_LOCAL_VERSION
  355. bool:ObjectUsed,
  356. #endif
  357. }
  358. static stock CA_ObjectList[MAX_CA_OBJECTS][CAOBJECTINFO];
  359. //Streamer
  360. #if defined STREAMER_TYPE_OBJECT
  361. // Static collision object functions (The index is not returned these can not be deleted!)
  362. 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)
  363. {
  364. new id = CreateDynamicObjectEx(modelid, x, y, z, rx, ry, rz, streamdistance, drawdistance, worlds, interiors, players, areas, maxworlds, maxinteriors, maxplayers, maxareas);
  365. CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  366. return id;
  367. }
  368. 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)
  369. {
  370. new id = CreateDynamicObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, vw, interior, playerid, streamdistance, drawdistance, areaid, priority);
  371. CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  372. return id;
  373. }
  374. stock CA_CreateObject_SC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:drawdistance = 300.0)
  375. {
  376. new id = CreateObject(modelid, x, y, z, rx, ry, rz, drawdistance);
  377. if(id != INVALID_OBJECT_ID) CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
  378. return id;
  379. }
  380. // Dynamic collision object functions (Removable)
  381. 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)
  382. {
  383. new index = -1;
  384. #if defined _Y_ITERATE_LOCAL_VERSION
  385. index = Iter_Free(CA_Objects);
  386. #else
  387. for(new i = 0; i < MAX_CA_OBJECTS; i++)
  388. {
  389. if(CA_ObjectList[i][ObjectUsed] == false)
  390. {
  391. index = i;
  392. break;
  393. }
  394. }
  395. #endif
  396. if(index > -1)
  397. {
  398. #if defined _Y_ITERATE_LOCAL_VERSION
  399. Iter_Add(CA_Objects, index);
  400. #else
  401. CA_ObjectList[index][ObjectUsed] = true;
  402. #endif
  403. CA_ObjectList[index][ObjectID] = CreateDynamicObjectEx(modelid, x, y, z, rx, ry, rz, drawdistance, streamdistance, worlds, interiors, players, areas, maxworlds, maxinteriors, maxplayers, maxareas);
  404. CA_ObjectList[index][ColdAndreadsID] = CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, true);
  405. CA_ObjectList[index][ObjectType] = OBJECT_TYPE_DYNAMIC;
  406. }
  407. return index;
  408. }
  409. 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)
  410. {
  411. new index = -1;
  412. #if defined _Y_ITERATE_LOCAL_VERSION
  413. index = Iter_Free(CA_Objects);
  414. #else
  415. for(new i = 0; i < MAX_CA_OBJECTS; i++)
  416. {
  417. if(CA_ObjectList[i][ObjectUsed] == false)
  418. {
  419. index = i;
  420. break;
  421. }
  422. }
  423. #endif
  424. if(index > -1)
  425. {
  426. #if defined _Y_ITERATE_LOCAL_VERSION
  427. Iter_Add(CA_Objects, index);
  428. #else
  429. CA_ObjectList[index][ObjectUsed] = true;
  430. #endif
  431. 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);
  432. CA_ObjectList[index][ColdAndreadsID] = CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, true);
  433. CA_ObjectList[index][ObjectType] = OBJECT_TYPE_DYNAMIC;
  434. }
  435. return index;
  436. }
  437. #endif
  438. /**--------------------------------------------------------------------------**\
  439. <summary>
  440. CA_CreateObject_DC
  441. </summary>
  442. <param name="modelid">The model to create</param>
  443. <param name="Float:x, Float:y, Float:z">The position in which to create the object</param>
  444. <param name="Float:rx, Float:ry, Float:rz">The rotation of the object</param>
  445. <param name="Float:drawdistance = 300.0">Whether or not to store this objects index for manual management</param>
  446. <returns>
  447. -1 if the object couldn't be created
  448. -1 if there are too many "DC" objects
  449. The "DC" index of the created object
  450. </returns>
  451. <remarks>
  452. The index returned by this function can only be used by "DC" functions
  453. </remarks>
  454. \**--------------------------------------------------------------------------**/
  455. stock CA_CreateObject_DC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:drawdistance = 300.0)
  456. {
  457. new index = -1;
  458. #if defined _Y_ITERATE_LOCAL_VERSION
  459. index = Iter_Free(CA_Objects);
  460. #else
  461. for(new i = 0; i < MAX_CA_OBJECTS; i++)
  462. {
  463. if(CA_ObjectList[i][ObjectUsed] == false)
  464. {
  465. index = i;
  466. break;
  467. }
  468. }
  469. #endif
  470. new id = CreateObject(modelid, x, y, z, rx, ry, rz, drawdistance);
  471. if(id == INVALID_OBJECT_ID) return -1;
  472. if(index > -1)
  473. {
  474. #if defined _Y_ITERATE_LOCAL_VERSION
  475. Iter_Add(CA_Objects, index);
  476. #else
  477. CA_ObjectList[index][ObjectUsed] = true;
  478. #endif
  479. CA_ObjectList[index][ObjectID] = id;
  480. CA_ObjectList[index][ColdAndreadsID] = CA_CreateObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, true);
  481. CA_ObjectList[index][ObjectType] = OBJECT_TYPE_OBJECT;
  482. }
  483. return index;
  484. }
  485. /**--------------------------------------------------------------------------**\
  486. <summary>
  487. CA_DestroyObject_DC
  488. </summary>
  489. <param name="index">The DC index of the object to destroy</param>
  490. <returns>
  491. -1 if the index is invalid
  492. -1 if the object doesn't exist
  493. 1 or next interator index if the object was destroyed
  494. </returns>
  495. \**--------------------------------------------------------------------------**/
  496. stock CA_DestroyObject_DC(index)
  497. {
  498. // Out of bounds
  499. if(index < 0 || index >= MAX_CA_OBJECTS) return -1;
  500. #if defined _Y_ITERATE_LOCAL_VERSION
  501. if(Iter_Contains(CA_Objects, index))
  502. {
  503. new next;
  504. Iter_SafeRemove(CA_Objects, index, next);
  505. if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) DestroyObject(CA_ObjectList[index][ObjectID]);
  506. #if defined STREAMER_TYPE_OBJECT
  507. else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) DestroyDynamicObject(CA_ObjectList[index][ObjectID]);
  508. #endif
  509. CA_DestroyObject(CA_ObjectList[index][ColdAndreadsID]);
  510. return next;
  511. }
  512. #else
  513. if(CA_ObjectList[index][ObjectUsed])
  514. {
  515. if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) DestroyObject(CA_ObjectList[index][ObjectID]);
  516. #if defined STREAMER_TYPE_OBJECT
  517. else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) DestroyDynamicObject(CA_ObjectList[index][ObjectID]);
  518. #endif
  519. CA_ObjectList[index][ObjectUsed] = false;
  520. CA_DestroyObject(CA_ObjectList[index][ColdAndreadsID]);
  521. return 1;
  522. }
  523. #endif
  524. return -1;
  525. }
  526. /**--------------------------------------------------------------------------**\
  527. <summary>
  528. CA_SetObjectPos_DC
  529. </summary>
  530. <param name="index">The DC index of the object to be moved</param>
  531. <param name="Float:x, Float:y, Float:z">The new position</param>
  532. <returns>
  533. -1 if the index is invalid
  534. -1 if the object doesn't exist
  535. 1 if the new position was set successfully
  536. </returns>
  537. \**--------------------------------------------------------------------------**/
  538. stock CA_SetObjectPos_DC(index, Float:x, Float:y, Float:z)
  539. {
  540. // Out of bounds
  541. if(index < 0 || index >= MAX_CA_OBJECTS) return -1;
  542. #if defined _Y_ITERATE_LOCAL_VERSION
  543. if(Iter_Contains(CA_Objects, index))
  544. {
  545. if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  546. #if defined STREAMER_TYPE_OBJECT
  547. else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  548. #endif
  549. CA_SetObjectPos(CA_ObjectList[index][ColdAndreadsID], x, y, z);
  550. }
  551. #else
  552. if(CA_ObjectList[index][ObjectUsed])
  553. {
  554. if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  555. #if defined STREAMER_TYPE_OBJECT
  556. else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  557. #endif
  558. SetObjectPos(CA_ObjectList[index][ObjectID], x, y, z);
  559. CA_SetObjectPos(CA_ObjectList[index][ColdAndreadsID], x, y, z);
  560. return 1;
  561. }
  562. #endif
  563. return -1;
  564. }
  565. /**--------------------------------------------------------------------------**\
  566. <summary>
  567. CA_SetObjectRot_DC
  568. </summary>
  569. <param name="index">The DC index of the object to be moved</param>
  570. <param name="Float:rx, Float:ry, Float:rz">The new rotation</param>
  571. <returns>
  572. -1 if the index is invalid
  573. -1 if the object doesn't exist
  574. 1 if the new rotation was set successfully
  575. </returns>
  576. \**--------------------------------------------------------------------------**/
  577. stock CA_SetObjectRot_DC(index, Float:rx, Float:ry, Float:rz)
  578. {
  579. // Out of bounds
  580. if(index < 0 || index >= MAX_CA_OBJECTS) return -1;
  581. #if defined _Y_ITERATE_LOCAL_VERSION
  582. if(Iter_Contains(CA_Objects, index))
  583. {
  584. if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  585. #if defined STREAMER_TYPE_OBJECT
  586. else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  587. #endif
  588. CA_SetObjectRot(CA_ObjectList[index][ColdAndreadsID], rx, ry, rz);
  589. }
  590. #else
  591. if(CA_ObjectList[index][ObjectUsed])
  592. {
  593. if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_OBJECT) SetObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  594. #if defined STREAMER_TYPE_OBJECT
  595. else if(CA_ObjectList[index][ObjectType] == OBJECT_TYPE_DYNAMIC) SetDynamicObjectRot(CA_ObjectList[index][ObjectID], rx, ry, rz);
  596. #endif
  597. CA_SetObjectRot(CA_ObjectList[index][ColdAndreadsID], rx, ry, rz);
  598. return 1;
  599. }
  600. #endif
  601. return -1;
  602. }
  603. /**--------------------------------------------------------------------------**\
  604. <summary>
  605. CA_DestroyAllObjects_DC
  606. </summary>
  607. <remarks>
  608. Destroys all DC objects
  609. </remarks>
  610. \**--------------------------------------------------------------------------**/
  611. stock CA_DestroyAllObjects_DC()
  612. {
  613. #if defined _Y_ITERATE_LOCAL_VERSION
  614. foreach(new i : CA_Objects)
  615. {
  616. if(CA_ObjectList[i][ObjectType] == OBJECT_TYPE_OBJECT) i = CA_DestroyObject_DC(i);
  617. }
  618. #else
  619. for(new i = 0; i < MAX_CA_OBJECTS; i++)
  620. {
  621. if(CA_ObjectList[i][ObjectUsed])
  622. {
  623. if(CA_ObjectList[i][ObjectType] == OBJECT_TYPE_OBJECT) CA_DestroyObject_DC(i);
  624. }
  625. }
  626. #endif
  627. }
  628. /**--------------------------------------------------------------------------**\
  629. <summary>
  630. CA_FindZ_For2DCoord
  631. </summary>
  632. <remarks>
  633. The ColAndreas alternative for MapAndreas's entire function
  634. This function does everything MapAndreas is capable of doing, and without the ground limit
  635. </remarks>
  636. \**--------------------------------------------------------------------------**/
  637. stock CA_FindZ_For2DCoord(Float:x, Float:y, &Float:z)
  638. {
  639. if(CA_RayCastLine(x, y, 700.0, x, y, -1000.0, x, y, z)) return 1;
  640. return 0;
  641. }
  642. // Explode ray casts in every direction
  643. stock CA_RayCastExplode(Float:cX, Float:cY, Float:cZ, Float:Radius, Float:intensity = 20.0, Float:collisions[][3])
  644. {
  645. if(intensity < 1.0 || intensity > 360.0 || (((360.0 / intensity) - floatround((360.0 / intensity), floatround_floor)) * intensity))
  646. return 0;
  647. new index;
  648. for(new Float:lat = -180.0; lat < 180.0; lat += (intensity * 0.75))
  649. for(new Float:lon = -90.0; lon < 90.0; lon += intensity)
  650. {
  651. new Float:LAT = lat * 3.141593 / 180.0,
  652. Float:LON = lon * 3.141593 / 180.0,
  653. Float:x = -Radius * floatcos(LAT) * floatcos(LON),
  654. Float:y = Radius * floatcos(LAT) * floatsin(LON),
  655. Float:z = Radius * floatsin(LAT);
  656. if(CA_RayCastLine(cX, cY, cZ, cX + x, cY + y, cZ + z, x, y, z))
  657. {
  658. collisions[index][0] = x;
  659. collisions[index][1] = y;
  660. collisions[index][2] = z;
  661. index++;
  662. }
  663. }
  664. return index;
  665. }
  666. /**--------------------------------------------------------------------------**\
  667. <summary>
  668. CA_IsPlayerOnSurface
  669. </summary>
  670. <param name="playerid">The playerid to check</param>
  671. <param name="Float:tolerance = 1.5">The distance to check for the ground</param>
  672. <returns>
  673. 0 if the player is not on the ground
  674. 1 if the player is on the ground
  675. </returns>
  676. \**--------------------------------------------------------------------------**/
  677. stock CA_IsPlayerOnSurface(playerid, Float:tolerance=1.5)
  678. {
  679. new Float:x, Float:y, Float:z;
  680. GetPlayerPos(playerid, x, y, z);
  681. // Check if player is actually on the ground
  682. if(!CA_RayCastLine(x, y, z, x, y, z-tolerance, x, y, z))
  683. return 0;
  684. return 1;
  685. }
  686. /**--------------------------------------------------------------------------**\
  687. <summary>
  688. CA_RemoveBarriers
  689. </summary>
  690. <returns>
  691. Always 1
  692. </returns>
  693. <remarks>
  694. Removes all of the barrier object collisions
  695. You must use this function before using `CA_Init`
  696. </remarks>
  697. \**--------------------------------------------------------------------------**/
  698. stock CA_RemoveBarriers()
  699. {
  700. static const BarrierIDS[] = {
  701. 16439, 16438, 16437, 16436, 4527, 4526, 4525, 4524,
  702. 4523, 4517, 4516, 4515, 4514, 4513, 4512, 4511, 4510,
  703. 4509, 4508, 4507, 4506, 4505, 4504, 1662
  704. };
  705. for(new i = 0; i < sizeof(BarrierIDS); i++)
  706. CA_RemoveBuilding(BarrierIDS[i], 0.0, 0.0, 0.0, 4242.6407);
  707. return 1;
  708. }
  709. /**--------------------------------------------------------------------------**\
  710. <summary>
  711. CA_RemoveBreakableBuildings
  712. </summary>
  713. <returns>
  714. Always 1
  715. </returns>
  716. <remarks>
  717. Removes all of the breakable object collisions
  718. You must use this function before using `CA_Init`
  719. </remarks>
  720. \**--------------------------------------------------------------------------**/
  721. stock CA_RemoveBreakableBuildings()
  722. {
  723. static const BreakableIDs[] = {
  724. 625, 626, 627, 628, 629, 630, 631, 632, 633, 642, 643, 644, 646, 650, 716, 717, 737, 738, 792, 858, 881, 882, 883,
  725. 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 904, 905, 941, 955, 956, 959, 961, 990, 993, 996, 1209,
  726. 1211, 1213, 1219, 1220, 1221, 1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1235, 1238, 1244, 1251,
  727. 1255, 1257, 1262, 1264, 1265, 1270, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1293,
  728. 1294, 1297, 1300, 1302, 1315, 1328, 1329, 1330, 1338, 1350, 1351, 1352, 1370, 1373, 1374, 1375, 1407, 1408, 1409,
  729. 1410, 1411, 1412, 1413, 1414, 1415, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 1428, 1429, 1431,
  730. 1432, 1433, 1436, 1437, 1438, 1440, 1441, 1443, 1444, 1445, 1446, 1447, 1448, 1449, 1450, 1451, 1452, 1456, 1457,
  731. 1458, 1459, 1460, 1461, 1462, 1463, 1464, 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476,
  732. 1477, 1478, 1479, 1480, 1481, 1482, 1483, 1514, 1517, 1520, 1534, 1543, 1544, 1545, 1551, 1553, 1554, 1558, 1564,
  733. 1568, 1582, 1583, 1584, 1588, 1589, 1590, 1591, 1592, 1645, 1646, 1647, 1654, 1664, 1666, 1667, 1668, 1669, 1670,
  734. 1672, 1676, 1684, 1686, 1775, 1776, 1949, 1950, 1951, 1960, 1961, 1962, 1975, 1976, 1977, 2647, 2663, 2682, 2683,
  735. 2885, 2886, 2887, 2900, 2918, 2920, 2925, 2932, 2933, 2942, 2943, 2945, 2947, 2958, 2959, 2966, 2968, 2971, 2977,
  736. 2987, 2988, 2989, 2991, 2994, 3006, 3018, 3019, 3020, 3021, 3022, 3023, 3024, 3029, 3032, 3036, 3058, 3059, 3067,
  737. 3083, 3091, 3221, 3260, 3261, 3262, 3263, 3264, 3265, 3267, 3275, 3276, 3278, 3280, 3281, 3282, 3302, 3374, 3409,
  738. 3460, 3516, 3794, 3795, 3797, 3853, 3855, 3864, 3884, 11103, 12840, 16627, 16628, 16629, 16630, 16631, 16632,
  739. 16633, 16634, 16635, 16636, 16732, 17968
  740. };
  741. for(new i = 0; i < sizeof(BreakableIDs); i++)
  742. CA_RemoveBuilding(BreakableIDs[i], 0.0, 0.0, 0.0, 4242.6407);
  743. return 1;
  744. }
  745. /**--------------------------------------------------------------------------**\
  746. <summary>
  747. CA_IsPlayerInWater
  748. </summary>
  749. <param name="playerid">The playerid to check</param>
  750. <param name="&Float:depth">The depth</param>
  751. <param name="&Float:playerdepth">The depth of the player</param>
  752. <returns>
  753. 0 if the player is not in water
  754. 1 if the player is in water
  755. </returns>
  756. \**--------------------------------------------------------------------------**/
  757. stock CA_IsPlayerInWater(playerid, &Float:depth, &Float:playerdepth)
  758. {
  759. new Float:x, Float:y, Float:z, Float:retx[10], Float:rety[10], Float:retz[10], Float: retdist[10], modelids[10];
  760. GetPlayerPos(playerid, x, y, z);
  761. new collisions = CA_RayCastMultiLine(x, y, z+1000.0, x, y, z-1000.0, retx, rety, retz, retdist, modelids, 10);
  762. if(collisions)
  763. {
  764. for(new i = 0; i < collisions; i++)
  765. {
  766. if(modelids[i] == WATER_OBJECT)
  767. {
  768. depth = INFINITY;
  769. for(new j = 0; j < collisions; j++)
  770. {
  771. if(retz[j] < depth)
  772. depth = retz[j];
  773. }
  774. depth = retz[i] - depth;
  775. if(depth < 0.001 && depth > -0.001)
  776. depth = 100.0;
  777. playerdepth = retz[i] - z;
  778. if(playerdepth < -2.0)
  779. return 0;
  780. return 1;
  781. }
  782. }
  783. }
  784. return 0;
  785. }
  786. /**--------------------------------------------------------------------------**\
  787. <summary>
  788. CA_IsPlayerNearWater
  789. </summary>
  790. <param name="playerid">The playerid to check</param>
  791. <param name="Float:dist = 3.0">The distance to check for water</param>
  792. <param name="Float:height = 3.0">The height the player can be from the water</param>
  793. <returns>
  794. 0 if the player is not in water
  795. 1 if the player is in water
  796. </returns>
  797. <remarks>
  798. Checks for water all around the player
  799. </remarks>
  800. \**--------------------------------------------------------------------------**/
  801. stock CA_IsPlayerNearWater(playerid, Float:dist=3.0, Float:height=3.0)
  802. {
  803. new Float:x, Float:y, Float:z, Float:tmp;
  804. GetPlayerPos(playerid, x, y, z);
  805. for(new i; i < 6; i++)
  806. 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)
  807. return 1;
  808. return 0;
  809. }
  810. /**--------------------------------------------------------------------------**\
  811. <summary>
  812. CA_IsPlayerFacingWater
  813. </summary>
  814. <param name="playerid">The playerid to check</param>
  815. <param name="Float:dist = 3.0">The distance to check for water</param>
  816. <param name="Float:height = 3.0">The height the player can be from the water</param>
  817. <returns>
  818. 0 if the player is not in water
  819. 1 if the player is in water
  820. </returns>
  821. <remarks>
  822. Checks for water only in front of the player
  823. </remarks>
  824. \**--------------------------------------------------------------------------**/
  825. stock CA_IsPlayerFacingWater(playerid, Float:dist=3.0, Float:height=3.0)
  826. {
  827. new Float:x, Float:y, Float:z, Float:r, Float:tmp;
  828. GetPlayerPos(playerid, x, y, z);
  829. GetPlayerFacingAngle(playerid, r);
  830. 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)
  831. return 1;
  832. return 0;
  833. }
  834. /**--------------------------------------------------------------------------**\
  835. <summary>
  836. CA_IsPlayerBlocked
  837. </summary>
  838. <param name="playerid">The playerid to check</param>
  839. <param name="Float:dist = 1.5">The distance to check for a wall</param>
  840. <param name="Float:height = 0.5">The height the wall can be from the ground</param>
  841. <returns>
  842. 0 if the player is not blocked
  843. 1 if the player is blocked
  844. </returns>
  845. \**--------------------------------------------------------------------------**/
  846. stock CA_IsPlayerBlocked(playerid, Float:dist=1.5, Float:height=0.5)
  847. {
  848. new Float:x, Float:y, Float:z, Float:endx, Float:endy, Float:fa;
  849. GetPlayerPos(playerid, x, y, z);
  850. z -= 1.0 + height;
  851. GetPlayerFacingAngle(playerid, fa);
  852. endx = (x + dist * floatsin(-fa,degrees));
  853. endy = (y + dist * floatcos(-fa,degrees));
  854. if(CA_RayCastLine(x, y, z, endx, endy, z, x, y, z))
  855. return 1;
  856. return 0;
  857. }
  858. /**--------------------------------------------------------------------------**\
  859. <summary>
  860. Float:CA_GetRoomHeight
  861. </summary>
  862. <param name="Float:x, Float:y, Float:z">A point in the area to be checked</param>
  863. <returns>
  864. 0.0 if there is either no floor or no ceiling
  865. The distance from the ceiling to the floor
  866. </returns>
  867. \**--------------------------------------------------------------------------**/
  868. stock Float:CA_GetRoomHeight(Float:x, Float:y, Float:z)
  869. {
  870. new Float:fx, Float:fy, Float:fz, Float:cx, Float:cy, Float:cz;
  871. if(CA_RayCastLine(x, y, z, x, y, z-1000.0, fx, fy, fz))
  872. {
  873. if(CA_RayCastLine(x, y, z, x, y, z+1000.0, cx, cy, cz))
  874. return floatsqroot(((fx-cx)*(fx-cx))+((fy-cy)*(fy-cy))+((fz-cz)*(fz-cz)));
  875. }
  876. return 0.0;
  877. }
  878. /**--------------------------------------------------------------------------**\
  879. <summary>
  880. Float:CA_GetRoomCenter
  881. </summary>
  882. <param name="Float:x, Float:y, Float:z">A point in the area to be checked</param>
  883. <param name="&Float:m_x, &Float:m_y">The center X and Y of the area</param>
  884. <returns>
  885. -1.0 if there isn't enough collisions to determine the center
  886. The radius of the circle formed by the test
  887. </returns>
  888. \**--------------------------------------------------------------------------**/
  889. stock Float:CA_GetRoomCenter(Float:x, Float:y, Float:z, &Float:m_x, &Float:m_y)
  890. {
  891. new Float:pt1x, Float:pt1y,
  892. Float:pt2x, Float:pt2y,
  893. Float:pt3x, Float:pt3y,
  894. Float:tmp;
  895. if(!CA_RayCastLine(x, y, z, x + 1000.0 * floatcos(0.0, degrees), y + 1000.0 * floatsin(0.0, degrees), z, pt1x, pt1y, tmp) ||
  896. !CA_RayCastLine(x, y, z, x + 1000.0 * floatcos(120.0, degrees), y + 1000.0 * floatsin(120.0, degrees), z, pt2x, pt2y, tmp) ||
  897. !CA_RayCastLine(x, y, z, x + 1000.0 * floatcos(-120.0, degrees), y + 1000.0 * floatsin(-120.0, degrees), z, pt3x, pt3y, tmp))
  898. return -1.0;
  899. new Float:yDelta_a = pt2y - pt1y,
  900. Float:xDelta_a = pt2x - pt1x,
  901. Float:yDelta_b = pt3y - pt2y,
  902. Float:xDelta_b = pt3x - pt2x;
  903. if (floatabs(xDelta_a) <= 0.000000001 && floatabs(yDelta_b) <= 0.000000001) {
  904. m_x = 0.5 * (pt2x + pt3x);
  905. m_y = 0.5 * (pt1y + pt2y);
  906. return VectorSize(m_x - pt1x, m_y - pt1y, 0.0);
  907. }
  908. new Float:aSlope = yDelta_a / xDelta_a,
  909. Float:bSlope = yDelta_b / xDelta_b;
  910. if (floatabs(aSlope-bSlope) <= 0.000000001)
  911. return -1.0;
  912. m_x = (aSlope * bSlope * (pt1y - pt3y) + bSlope * (pt1x + pt2x) - aSlope * (pt2x + pt3x)) / (2.0 * (bSlope - aSlope));
  913. m_y = -1.0 * (m_x - (pt1x + pt2x) / 2.0) / aSlope + (pt1y + pt2y) / 2.0;
  914. return VectorSize(m_x - pt1x, m_y - pt1y, 0.0);
  915. }
  916. // Hooked functions
  917. public OnFilterScriptExit()
  918. {
  919. CA_DestroyAllObjects_DC();
  920. if (funcidx("CA_OnFilterScriptExit") != -1)
  921. {
  922. return CallLocalFunction("CA_OnFilterScriptExit", "");
  923. }
  924. return 1;
  925. }
  926. #if defined _ALS_OnFilterScriptExit
  927. #undef OnFilterScriptExit
  928. #else
  929. #define _ALS_OnFilterScriptExit
  930. #endif
  931. #define OnFilterScriptExit CA_OnFilterScriptExit
  932. forward CA_OnFilterScriptExit();
  933. public OnGameModeExit()
  934. {
  935. CA_DestroyAllObjects_DC();
  936. if (funcidx("CA_OnGameModeExit") != -1)
  937. {
  938. return CallLocalFunction("CA_OnGameModeExit", "");
  939. }
  940. return 1;
  941. }
  942. #if defined _ALS_OnGameModeExit
  943. #undef OnGameModeExit
  944. #else
  945. #define _ALS_OnGameModeExit
  946. #endif
  947. #define OnGameModeExit CA_OnGameModeExit
  948. forward CA_OnGameModeExit();
  949. /*
  950. Create a object with collision in ColAndreas dynamic
  951. CA_CreateObject_DC(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:drawdistance = 300.0)
  952. Destroy a object with collision in ColAndreas
  953. CA_DestroyObject_DC(index)
  954. Destoys all objects streamer/regular
  955. CA_DestroyAllObjects_DC()
  956. MapAndreas replacement function
  957. CA_FindZ_For2DCoord(Float:x, Float:y, &Float:z)
  958. Explode ray casts in every direction
  959. CA_RayCastExplode(Float:cX, Float:cY, Float:cZ, Float:Radius, Float:intensity = 20.0, Float:collisions[][3])
  960. Checks if a player is standing on any surface (prevent animation exploit when falling)
  961. CA_IsOnSurface(playerid, Float:tolerance=1.5)
  962. Removes all barries this function only works BEFORE using CA_Init()
  963. CA_RemoveBarriers()
  964. Removes all dynamic breakable objects, also only works BEFORE using CA_Init()
  965. CA_RemoveBreakableBuildings()
  966. Checks if a player is in the water depth returns the lowest collision point found playerdepth returns
  967. how deep the player is below the surface
  968. CA_IsPlayerInWater(playerid, &Float:depth, &Float:playerdepth)
  969. Checks if a player is near water (returns 0 if they are actually in the water) distance is the radius to check
  970. Height is how high above the water to detect
  971. CA_IsNearWater(playerid, Float:dist=3.0, Float:height=3.0)
  972. // Check if a player is blocked by a wall
  973. CA_IsBlocked(playerid, Float:dist=1.5, Float:height=0.5)
  974. Notes:
  975. Recommended loading order
  976. - RemoveBuildings
  977. - Init static map
  978. - Add static objects
  979. There is currently no support for virtual worlds / interior or per player with streamer objects
  980. */