colandreas.inc 23 KB

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