-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathL_SAM.inc
467 lines (418 loc) · 12.5 KB
/
L_SAM.inc
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
/*______________________________________________________________________________
L-SAM "Lordz's Surface To Air Missiles" - v1.0
Copyright(c) 2014 - L_SAM.inc
Author : Lordzâ„¢
Thanks to Incognito for Streamer
&
All the players of YoUnG Generations for BETA Testing.
* Happy New Year!
//Functions:
native CreateSAM(Float:X, Float:Y, Float:Z, Float:rX=0.0, Float:rY=0.0, Float:rZ=0.0, Float:DrawDistance=200.0, Float:Range=300.0, Speed=80, Power=SAM_POWER_NORMAL, bool:follow=false)
native SetSAMToAttackVehicles(samid, bool:occupied = true);
native DestroySAM(samid);
native AvoidSAMAttacksOnPlayer(playerid, samid);
native EnableSAMAttacksOnPlayer(playerid, samid);
native ToggleNoSAMAttacksOnPlayer(playerid, samid, bool:noattack);
native SetSAMMissileSpeed(samid, speed);
native SetSAMMissilePower(samid, Power);
native GetSAMMissileSpeed(samid);
native GetSAMMissilePower(samid);
native GetSAMObjectID(samid);
_______________________________________________________________________________*/
#if defined _included_l_sam
#endinput
#endif
#define _included_l_sam
#include <a_samp>
//#define USE_STREAMER //Uncomment this line in case if you want to use streamer -
// SAM objects.
#if defined USE_STREAMER
#include <streamer>
#endif
#define MAX_LSAMS 100 //Change this value to create SAM launchers more than 100.
#define SAM_POWER_LOW 0
#define SAM_POWER_NORMAL 1
#define SAM_POWER_HIGH 2
#define SAM_POWER_BEST 3
enum L_saminfo
{
Float:L_SAMX,
Float:L_SAMY,
Float:L_SAMZ,
Float:L_SAMrX,
Float:L_SAMrY,
Float:L_SAMrZ,
Float:L_SAMDrawDistance,
Float:L_SAMRange,
L_SAMSpeed,
L_SAMPower,
bool:L_SAMFollow,
bool:L_SAMCreated,
L_SAMObjectID,
}
new L_SAMData[MAX_LSAMS][L_saminfo];
new L_CountSAMS = 0;
new Float:L_SAMPlayerPos[MAX_PLAYERS][3];
new PlayerMissile[MAX_PLAYERS];
new bool:MissileInProgress[MAX_PLAYERS];
new L_SAMMissileObject[MAX_OBJECTS];
new L_SAMMissilePower[MAX_OBJECTS];
new L_SAMMissileProgress[MAX_OBJECTS];
new L_SAMMissileMarker[MAX_PLAYERS];
new bool:L_SAM_ExceptionalPlayer[MAX_PLAYERS][MAX_LSAMS];
#if defined USE_STREAMER
stock CreateStreamedObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, vworld = -1, interiorid = -1, playerid = -1, Float:streamdistance = 300.0, Float:drawdistance = 300.0)
{
new Object_ID = CreateDynamicObject(modelid, X, Y, Z, rX, rY, rZ, vworld, interiorid, playerid, streamdistance);
Streamer_SetFloatData(STREAMER_TYPE_OBJECT, Object_ID, E_STREAMER_DRAW_DISTANCE, drawdistance);
return Object_ID;
}
#endif
stock CreateSAM(Float:X, Float:Y, Float:Z, Float:rX=0.0, Float:rY=0.0, Float:rZ=0.0, Float:DrawDistance=200.0, Float:Range=300.0, Speed=80, Power=SAM_POWER_NORMAL, bool:follow=false)
{
if(L_CountSAMS > MAX_LSAMS) return printf("• <L_SAM> Error : Couldn't create SAM, maximum SAMS have already been done!"), 0;
new samid = L_CountSAMS;
L_SAMData[samid][L_SAMX] = X;
L_SAMData[samid][L_SAMY] = Y;
L_SAMData[samid][L_SAMZ] = Z;
L_SAMData[samid][L_SAMrX] = rX;
L_SAMData[samid][L_SAMrY] = rY;
L_SAMData[samid][L_SAMrZ] = rZ;
L_SAMData[samid][L_SAMDrawDistance] = DrawDistance;
L_SAMData[samid][L_SAMRange] = Range;
L_SAMData[samid][L_SAMSpeed] = Speed;
if(Power >= SAM_POWER_BEST) L_SAMData[samid][L_SAMPower] = SAM_POWER_BEST;
else if(Power <= SAM_POWER_LOW) L_SAMData[samid][L_SAMPower] = SAM_POWER_LOW;
else L_SAMData[samid][L_SAMPower] = Power;
L_SAMData[samid][L_SAMFollow] = follow;
#if defined USE_STREAMER
L_SAMData[samid][L_SAMObjectID] = CreateStreamedObject(3267, X, Y, Z, rX, rY, rZ, -1, -1, -1, DrawDistance, DrawDistance);
#else
L_SAMData[samid][L_SAMObjectID] = CreateObject(3267, X, Y, Z, rX, rY, rZ, DrawDistance);
#endif
L_SAMData[samid][L_SAMCreated] = true;
L_CountSAMS++;
return samid;
}
stock DestroySAM(samid)
{
if(L_SAMData[samid][L_SAMCreated] == false) return 0;
L_SAMData[samid][L_SAMX] = 0.0;
L_SAMData[samid][L_SAMY] = 0.0;
L_SAMData[samid][L_SAMZ] = 0.0;
L_SAMData[samid][L_SAMrX] = 0.0;
L_SAMData[samid][L_SAMrY] = 0.0;
L_SAMData[samid][L_SAMrZ] = 0.0;
L_SAMData[samid][L_SAMDrawDistance] = 0.0;
L_SAMData[samid][L_SAMRange] = 0.0;
L_SAMData[samid][L_SAMSpeed] = 0;
L_SAMData[samid][L_SAMPower] = 0;
L_SAMData[samid][L_SAMFollow] = false;
L_SAMData[samid][L_SAMCreated] = false;
DestroyObject(L_SAMData[samid][L_SAMObjectID]);
L_SAMData[samid][L_SAMObjectID] = -1;
return 1;
}
#if defined FILTERSCRIPT
public OnFilterScriptInit()
{
for(new samid; samid< MAX_LSAMS; samid++)
{
L_SAMData[samid][L_SAMX] = 0.0;
L_SAMData[samid][L_SAMY] = 0.0;
L_SAMData[samid][L_SAMZ] = 0.0;
L_SAMData[samid][L_SAMrX] = 0.0;
L_SAMData[samid][L_SAMrY] = 0.0;
L_SAMData[samid][L_SAMrZ] = 0.0;
L_SAMData[samid][L_SAMDrawDistance] = 0.0;
L_SAMData[samid][L_SAMRange] = 0.0;
L_SAMData[samid][L_SAMSpeed] = 0;
L_SAMData[samid][L_SAMPower] = 0;
L_SAMData[samid][L_SAMFollow] = false;
L_SAMData[samid][L_SAMCreated] = false;
L_SAMData[samid][L_SAMObjectID] = -1;
for(new a; a< MAX_PLAYERS; a++) L_SAM_ExceptionalPlayer[a][samid] = false;
}
for(new i; i< MAX_OBJECTS; i++)
{
L_SAMMissileObject[i] = 0;
L_SAMMissilePower[i] = 0;
L_SAMMissileProgress[i] = -1;
}
for(new i; i< MAX_PLAYERS; i++)
{
MissileInProgress[i] = false;
L_SAMPlayerPos[i][0] = 0.0;
L_SAMPlayerPos[i][1] = 0.0;
L_SAMPlayerPos[i][2] = 0.0;
PlayerMissile[i] = -1;
}
L_CountSAMS = 0;
SetTimer("LordzSAMTimer", 2500, true);
CallLocalFunction("L_SAM_OnFS", "");
return 1;
}
#if defined _ALS_OnFilterScriptInit
#undef OnFilterScriptInit
#else
#define _ALS_OnFilterScriptInit
#endif
public OnFilterScriptExit()
{
#if !defined USE_STREAMER
for(new i; i< MAX_LSAMS; i++)
{
if(L_SAMData[i][L_SAMCreated])
{
DestroyObject(L_SAMData[i][L_SAMObjectID]);
}
}
#endif
for(new i; i< MAX_OBJECTS; i++)
{
if(L_SAMMissileProgress[i])
{
DestroyObject(i);
}
}
for(new i; i< MAX_PLAYERS; i++)
{
if(MissileInProgress[i]) RemovePlayerMapIcon(i, 99);
}
CallLocalFunction("L_SAM_OnFSExit", "");
return 1;
}
#if defined _ALS_OnFilterScriptExit
#undef OnFilterScriptExit
#else
#define _ALS_OnFilterScriptExit
#endif
forward L_SAM_OnFS();
forward L_SAM_OnFSExit();
#else
public OnGameModeInit()
{
for(new samid; samid< MAX_LSAMS; samid++)
{
L_SAMData[samid][L_SAMX] = 0.0;
L_SAMData[samid][L_SAMY] = 0.0;
L_SAMData[samid][L_SAMZ] = 0.0;
L_SAMData[samid][L_SAMrX] = 0.0;
L_SAMData[samid][L_SAMrY] = 0.0;
L_SAMData[samid][L_SAMrZ] = 0.0;
L_SAMData[samid][L_SAMDrawDistance] = 0.0;
L_SAMData[samid][L_SAMRange] = 0.0;
L_SAMData[samid][L_SAMSpeed] = 0;
L_SAMData[samid][L_SAMPower] = 0;
L_SAMData[samid][L_SAMFollow] = false;
L_SAMData[samid][L_SAMCreated] = false;
L_SAMData[samid][L_SAMObjectID] = -1;
for(new a; a< MAX_PLAYERS; a++) L_SAM_ExceptionalPlayer[a][samid] = false;
}
for(new i; i< MAX_OBJECTS; i++)
{
L_SAMMissileObject[i] = 0;
L_SAMMissilePower[i] = 0;
L_SAMMissileProgress[i] = -1;
}
for(new i; i< MAX_PLAYERS; i++)
{
MissileInProgress[i] = false;
L_SAMPlayerPos[i][0] = 0.0;
L_SAMPlayerPos[i][1] = 0.0;
L_SAMPlayerPos[i][2] = 0.0;
PlayerMissile[i] = -1;
}
L_CountSAMS = 0;
SetTimer("LordzSAMTimer", 2500, true);
CallLocalFunction("L_SAM_OnGM", "");
return 1;
}
#if defined _ALS_OnGameModeInit
#undef OnGameModeInit
#else
#define _ALS_OnGameModeInit
#endif
forward L_SAM_OnGM();
public OnGameModeExit()
{
#if !defined USE_STREAMER
for(new i; i< MAX_LSAMS; i++)
{
if(L_SAMData[i][L_SAMCreated])
{
DestroyObject(L_SAMData[i][L_SAMObjectID]);
}
}
#endif
for(new i; i< MAX_OBJECTS; i++)
{
if(L_SAMMissileProgress[i])
{
DestroyObject(i);
}
}
for(new i; i< MAX_PLAYERS; i++)
{
if(MissileInProgress[i]) RemovePlayerMapIcon(i, 99);
}
CallLocalFunction("L_SAM_OnGMExit", "");
return 1;
}
#if defined _ALS_OnGameModeExit
#undef OnGameModeExit
#else
#define _ALS_OnGameModeExit
#endif
forward L_SAM_OnGMExit();
#endif
forward LordzSAMTimer();
stock AvoidSAMAttacksOnPlayer(playerid, samid)
{
if(L_SAMData[samid][L_SAMCreated] == false) return -1;
L_SAM_ExceptionalPlayer[playerid][samid] = 1;
return 1;
}
stock EnableSAMAttacksOnPlayer(playerid, samid)
{
if(L_SAMData[samid][L_SAMCreated] == false) return -1;
L_SAM_ExceptionalPlayer[playerid][samid] = 0;
return 1;
}
stock ToggleNoSAMAttacksOnPlayer(playerid, samid, bool:noattack)
{
if(L_SAMData[samid][L_SAMCreated] == false) return -1;
L_SAM_ExceptionalPlayer[playerid][samid] = noattack;
return 1;
}
stock SetSAMMissileSpeed(samid, speed)
{
if(L_SAMData[samid][L_SAMCreated] == false) return 0;
L_SAMData[samid][L_SAMSpeed] = speed;
return 1;
}
stock GetSAMMissileSpeed(samid)
{
if(L_SAMData[samid][L_SAMCreated] == false) return -1;
return L_SAMData[samid][L_SAMSpeed];
}
stock SetSAMMissilePower(samid, Power)
{
if(L_SAMData[samid][L_SAMCreated] == false) return -1;
if(Power >= SAM_POWER_BEST) L_SAMData[samid][L_SAMPower] = SAM_POWER_BEST;
else if(Power <= SAM_POWER_LOW) L_SAMData[samid][L_SAMPower] = SAM_POWER_LOW;
else L_SAMData[samid][L_SAMPower] = Power;
return Power;
}
stock GetSAMMissilePower(samid)
{
if(L_SAMData[samid][L_SAMCreated] == false) return -1;
return L_SAMData[samid][L_SAMPower];
}
stock GetSAMObjectID(samid)
{
if(L_SAMData[samid][L_SAMCreated] == false) return -1;
return L_SAMData[samid][L_SAMObjectID];
}
public LordzSAMTimer()
{
for(new i; i< MAX_LSAMS; i++)
{
if(L_SAMData[i][L_SAMCreated])
{
for(new a; a< GetMaxPlayers(); a++)
{
if(!IsPlayerConnected(a)) continue;
if(!IsPlayerInRangeOfPoint(a, L_SAMData[i][L_SAMRange], L_SAMData[i][L_SAMX], L_SAMData[i][L_SAMY], L_SAMData[i][L_SAMZ])) continue;
if(L_SAM_ExceptionalPlayer[a][i] == true) continue;
if(MissileInProgress[a] == true) continue;
GetPlayerPos(a, L_SAMPlayerPos[a][0], L_SAMPlayerPos[a][1], L_SAMPlayerPos[a][2]);
new p_missileobj = CreateObject(345, L_SAMData[i][L_SAMX], L_SAMData[i][L_SAMY], L_SAMData[i][L_SAMZ], 0.0, 0.0, 0.0, 300.0);
PlayerMissile[a] = p_missileobj;
L_SAMMissileObject[p_missileobj] = 1;
L_SAMMissilePower[p_missileobj] = L_SAMData[i][L_SAMPower];
L_SAMMissileProgress[p_missileobj] = a;
MoveObject(p_missileobj, L_SAMPlayerPos[a][0], L_SAMPlayerPos[a][1], L_SAMPlayerPos[a][2], L_SAMData[i][L_SAMSpeed]);
MissileInProgress[a] = true;
SetPlayerMapIcon(a, 99, L_SAMData[i][L_SAMX], L_SAMData[i][L_SAMY], L_SAMData[i][L_SAMZ], 0, 0xFF0000FF);
L_SAMMissileMarker[a] = SetTimerEx("L_SAMUpdateMapIcon", 250, true, "i", a);
}
}
}
return 1;
}
forward L_SAMUpdateMapIcon(playerid);
public L_SAMUpdateMapIcon(playerid)
{
if(!MissileInProgress[playerid]) return KillTimer(L_SAMMissileMarker[playerid]);
new Float:X, Float:Y, Float:Z;
GetObjectPos(PlayerMissile[playerid], X, Y, Z);
SetPlayerMapIcon(playerid, 99, X, Y, Z, 0, 0xFF0000FF);
return 1;
}
public OnObjectMoved(objectid)
{
if(L_SAMMissileObject[objectid] == 1)
{
new Float:X, Float:Y, Float:Z;
GetObjectPos(objectid, X, Y, Z);
switch(L_SAMMissilePower[objectid])
{
case 0: CreateExplosion(X+4.0, Y+4.0, Z, 1, 10.0);
case 1: CreateExplosion(X+4.0, Y+4.0, Z, 7, 10.0);
case 2:
{
CreateExplosion(X+8.0,Y, Z, 7, 10.0);
CreateExplosion(X-8.0,Y, Z, 7, 10.0);
CreateExplosion(X, Y+8.0,Z, 7, 10.0);
CreateExplosion(X, Y-8.0,Z, 7, 10.0);
}
case 3:
{
new Float:range = 8.0;
CreateExplosion(X+range,Y, Z, 6, 10.0);
CreateExplosion(X-range,Y, Z, 6, 10.0);
CreateExplosion(X, Y+range,Z, 6, 10.0);
CreateExplosion(X, Y-range,Z, 6, 10.0);
CreateExplosion(X+range,Y+range,Z, 6, 10.0);
CreateExplosion(X-range,Y+range,Z, 6, 10.0);
CreateExplosion(X-range,Y-range,Z, 6, 10.0);
}
}
DestroyObject(objectid);
RemovePlayerMapIcon(L_SAMMissileProgress[objectid], 99);
L_SAMMissileObject[objectid] = 0;
L_SAMMissilePower[objectid] = 0;
MissileInProgress[L_SAMMissileProgress[objectid]] = false;
L_SAMMissileProgress[objectid] = -1;
}
CallLocalFunction("L_SAM_OnObjMoved", "i", objectid);
return 1;
}
#if defined _ALS_OnObjectMoved
#undef OnObjectMoved
#else
#define _ALS_OnObjectMoved
#endif
forward L_SAM_OnObjMoved(objectid);
public OnPlayerConnect(playerid)
{
for(new i; i< MAX_LSAMS; i++) L_SAM_ExceptionalPlayer[playerid][i] = false;
CallLocalFunction("L_SAM_OPC", "i", playerid);
return 1;
}
#if defined _ALS_OnPlayerConnect
#undef OnPlayerConnect
#else
#define _ALS_OnPlayerConnect
#endif
forward L_SAM_OPC(playerid);
#define OnObjectMoved L_SAM_OnObjMoved
#if defined FILTERSCRIPT
#define OnFilterScriptInit L_SAM_OnFS
#define OnFilterScriptExit L_SAM_OnFSExit
#else
#define OnGameModeInit L_SAM_OnGM
#define OnGameModeExit L_SAM_OnGMExit
#endif
#define OnPlayerConnect L_SAM_OPC