colandreas.inc 43 KB

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