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