1
0

missilelaunchers.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*______________________________________________________________________________
  2. L-SAM "Lordz's Surface To Air Missiles" - v1.3
  3. Copyright(c) 2014 - L_SAM3.inc
  4. Author : Lordzâ„¢
  5. Editor - Desmond
  6. //Functions:
  7. 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, bool:followlimit=false);
  8. native IsSAMMissilesFollowing(samid);
  9. native DestroySAM(samid);
  10. native AvoidSAMAttacksOnPlayer(playerid, samid);
  11. native EnableSAMAttacksOnPlayer(playerid, samid);
  12. native ToggleNoSAMAttacksOnPlayer(playerid, samid, bool:noattack);
  13. native SetSAMMissileSpeed(samid, speed);
  14. native SetSAMMissilePower(samid, Power);
  15. native SetSAMMissileColor(samid, color);
  16. native GetSAMMissileSpeed(samid);
  17. native GetSAMMissilePower(samid);
  18. native GetSAMObjectID(samid);
  19. native GetSAMMissileColor(samid);
  20. native IsMissileFollowingLimited(samid);
  21. native DestroySAMMissile(playerid);
  22. native IsSAMMissileChasing(playerid);
  23. ~ Desmond's additions ~
  24. To determine whenever a launcher will shoot or not
  25. public MissileAuthorized(playerid)
  26. Command for SANG to authorize a specific vehicle ID
  27. CMD:authorizeaircraft(playerid, params[])
  28. Variable that checks whenever a vehicle ID is authorized
  29. vehMissileAuthorized[vehicleid]
  30. Additions were made to LordzSAMTimer, check it out if you wish
  31. Important note: the author of this include used indentation of 2 tabs, that's why
  32. it looks weird. It took me a lot of time to try and arrange it but the editor won't let me.
  33. For now I'm keeping it this way till I can arrange the whole include.
  34. _______________________________________________________________________________*/
  35. #define L_SAMUSE_SMOKES
  36. #if defined _included_l_sam
  37. #endinput
  38. #endif
  39. #define _included_l_sam
  40. #define MAX_LSAMS 100 //Change this value to create more SAM launchers.
  41. #define SAM_POWER_LOW 0
  42. #define SAM_POWER_NORMAL 1
  43. #define SAM_POWER_HIGH 2
  44. #define SAM_POWER_BEST 3
  45. #define MISSILE_RADAR_COLOR 0x660000FF
  46. enum L_saminfo
  47. {
  48. Float:L_SAMX,
  49. Float:L_SAMY,
  50. Float:L_SAMZ,
  51. Float:L_SAMrX,
  52. Float:L_SAMrY,
  53. Float:L_SAMrZ,
  54. Float:L_SAMDrawDistance,
  55. Float:L_SAMRange,
  56. L_SAMSpeed,
  57. L_SAMPower,
  58. bool:L_SAMFollow,
  59. bool:L_SAMFollowLimit,
  60. Float:L_SAMFollowLimitRange,
  61. bool:L_SAMCreated,
  62. L_SAMObjectID,
  63. L_SAMMissileColor,
  64. }
  65. new L_SAMData[MAX_LSAMS][L_saminfo],
  66. L_CountSAMS = 0,
  67. Float:L_SAMPlayerPos[MAX_PLAYERS][3],
  68. PlayerMissile[MAX_PLAYERS],
  69. #if defined L_SAMUSE_SMOKES
  70. PlayerMissileSmoke[MAX_PLAYERS],
  71. #endif
  72. bool:MissileInProgress[MAX_PLAYERS],
  73. L_SAMMissileObject[MAX_OBJECTS],
  74. #if defined L_SAMUSE_SMOKES
  75. L_SAMMissileSmoke[MAX_OBJECTS],
  76. #endif
  77. L_SAMMissilePower[MAX_OBJECTS],
  78. L_SAMMissileSAMID[MAX_OBJECTS],
  79. L_SAMMissileProgress[MAX_OBJECTS],
  80. bool:L_SAMFollowStopped[MAX_PLAYERS],
  81. bool:L_SAM_ExceptionalPlayer[MAX_PLAYERS][MAX_LSAMS],
  82. bool:L_SAMMissileStopped[MAX_OBJECTS],
  83. MissileWarning[MAX_PLAYERS],
  84. PlayerMissileWarningTimerID[MAX_PLAYERS],
  85. bool:vehMissileAuthorized[MAX_VEHICLES];
  86. 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, bool:followlimit=false)
  87. {
  88. if(L_CountSAMS > MAX_LSAMS) return printf("• <L_SAM> Error : Couldn't create SAM, maximum SAMS have already been done!"), 0;
  89. new samid = L_CountSAMS;
  90. L_SAMData[samid][L_SAMX] = X;
  91. L_SAMData[samid][L_SAMY] = Y;
  92. L_SAMData[samid][L_SAMZ] = Z;
  93. L_SAMData[samid][L_SAMrX] = rX;
  94. L_SAMData[samid][L_SAMrY] = rY;
  95. L_SAMData[samid][L_SAMrZ] = rZ;
  96. L_SAMData[samid][L_SAMDrawDistance] = DrawDistance;
  97. L_SAMData[samid][L_SAMRange] = Range;
  98. L_SAMData[samid][L_SAMSpeed] = Speed;
  99. if(Power >= SAM_POWER_BEST)
  100. L_SAMData[samid][L_SAMPower] = SAM_POWER_BEST;
  101. else if(Power <= SAM_POWER_LOW)
  102. L_SAMData[samid][L_SAMPower] = SAM_POWER_LOW;
  103. else L_SAMData[samid][L_SAMPower] = Power;
  104. L_SAMData[samid][L_SAMFollow] = follow;
  105. L_SAMData[samid][L_SAMFollowLimit] = followlimit;
  106. L_SAMData[samid][L_SAMFollowLimitRange] = Range;
  107. L_SAMData[samid][L_SAMObjectID] = CreateObject(18848, X, Y, Z, rX, rY, rZ, DrawDistance);
  108. L_SAMData[samid][L_SAMMissileColor] = MISSILE_RADAR_COLOR;
  109. L_SAMData[samid][L_SAMCreated] = true;
  110. L_CountSAMS++;
  111. return samid;
  112. }
  113. stock DestroySAM(samid)
  114. {
  115. if(L_SAMData[samid][L_SAMCreated] == false) return 0;
  116. L_SAMData[samid][L_SAMX] = 0.0;
  117. L_SAMData[samid][L_SAMY] = 0.0;
  118. L_SAMData[samid][L_SAMZ] = 0.0;
  119. L_SAMData[samid][L_SAMrX] = 0.0;
  120. L_SAMData[samid][L_SAMrY] = 0.0;
  121. L_SAMData[samid][L_SAMrZ] = 0.0;
  122. L_SAMData[samid][L_SAMDrawDistance] = 0.0;
  123. L_SAMData[samid][L_SAMRange] = 0.0;
  124. L_SAMData[samid][L_SAMSpeed] = 0;
  125. L_SAMData[samid][L_SAMPower] = 0;
  126. L_SAMData[samid][L_SAMFollow] = false;
  127. L_SAMData[samid][L_SAMCreated] = false;
  128. DestroyObject(L_SAMData[samid][L_SAMObjectID]);
  129. L_SAMData[samid][L_SAMObjectID] = -1;
  130. L_SAMData[samid][L_SAMMissileColor] = MISSILE_RADAR_COLOR;
  131. return 1;
  132. }
  133. stock IsMissileFollowingLimited(samid)
  134. {
  135. if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  136. if(L_SAMData[samid][L_SAMFollow] == false) return false;
  137. if(L_SAMData[samid][L_SAMFollowLimit] == false) return false;
  138. return true;
  139. }
  140. //Thanks to RyDeR` for this function!
  141. stock L_SetObjectFaceCoords3D(iObject, Float: fX, Float: fY, Float: fZ, Float: fRollOffset = 0.0, Float: fPitchOffset = 0.0, Float: fYawOffset = 0.0) {
  142. new
  143. Float: fOX,
  144. Float: fOY,
  145. Float: fOZ,
  146. Float: fPitch
  147. ;
  148. GetObjectPos(iObject, fOX, fOY, fOZ);
  149. fPitch = floatsqroot(floatpower(fX - fOX, 2.0) + floatpower(fY - fOY, 2.0));
  150. fPitch = floatabs(atan2(fPitch, fZ - fOZ));
  151. fZ = atan2(fY - fOY, fX - fOX) - 90.0; // Yaw
  152. SetObjectRot(iObject, fRollOffset, fPitch + fPitchOffset, fZ + fYawOffset);
  153. }
  154. #if defined FILTERSCRIPT
  155. public OnFilterScriptInit()
  156. {
  157. for(new samid; samid< MAX_LSAMS; samid++)
  158. {
  159. L_SAMData[samid][L_SAMX] = 0.0;
  160. L_SAMData[samid][L_SAMY] = 0.0;
  161. L_SAMData[samid][L_SAMZ] = 0.0;
  162. L_SAMData[samid][L_SAMrX] = 0.0;
  163. L_SAMData[samid][L_SAMrY] = 0.0;
  164. L_SAMData[samid][L_SAMrZ] = 0.0;
  165. L_SAMData[samid][L_SAMDrawDistance] = 0.0;
  166. L_SAMData[samid][L_SAMRange] = 0.0;
  167. L_SAMData[samid][L_SAMSpeed] = 0;
  168. L_SAMData[samid][L_SAMPower] = 0;
  169. L_SAMData[samid][L_SAMFollow] = false;
  170. L_SAMData[samid][L_SAMCreated] = false;
  171. L_SAMData[samid][L_SAMObjectID] = -1;
  172. L_SAMData[samid][L_SAMMissileColor] = MISSILE_RADAR_COLOR;
  173. for(new a; a< MAX_PLAYERS; a++) L_SAM_ExceptionalPlayer[a][samid] = false;
  174. }
  175. for(new i; i< MAX_OBJECTS; i++)
  176. {
  177. L_SAMMissileObject[i] = 0;
  178. L_SAMMissilePower[i] = 0;
  179. L_SAMMissileSAMID[i] = -1;
  180. L_SAMMissileProgress[i] = -1;
  181. }
  182. for(new i; i< MAX_PLAYERS; i++)
  183. {
  184. MissileInProgress[i] = false;
  185. L_SAMPlayerPos[i][0] = 0.0;
  186. L_SAMPlayerPos[i][1] = 0.0;
  187. L_SAMPlayerPos[i][2] = 0.0;
  188. PlayerMissile[i] = -1;
  189. L_SAMFollowStopped[i] = false;
  190. #if defined L_SAMUSE_SMOKES
  191. PlayerMissileSmoke[i] = -1;
  192. #endif
  193. }
  194. L_CountSAMS = 0;
  195. SetTimer("LordzSAMTimer", 2500, true);
  196. CallLocalFunction("L_SAM_OnFS", "");
  197. return 1;
  198. }
  199. #if defined _ALS_OnFilterScriptInit
  200. #undef OnFilterScriptInit
  201. #else
  202. #define _ALS_OnFilterScriptInit
  203. #endif
  204. public OnFilterScriptExit()
  205. {
  206. for(new i; i< MAX_LSAMS; i++)
  207. {
  208. if(L_SAMData[i][L_SAMCreated])
  209. {
  210. DestroyObject(L_SAMData[i][L_SAMObjectID]);
  211. }
  212. }
  213. for(new i; i< MAX_OBJECTS; i++)
  214. {
  215. if(L_SAMMissileProgress[i])
  216. {
  217. DestroyObject(i);
  218. #if defined L_SAMUSE_SMOKES
  219. DestroyObject(L_SAMMissileSmoke[i]);
  220. #endif
  221. }
  222. }
  223. CallLocalFunction("L_SAM_OnFSExit", "");
  224. return 1;
  225. }
  226. #if defined _ALS_OnFilterScriptExit
  227. #undef OnFilterScriptExit
  228. #else
  229. #define _ALS_OnFilterScriptExit
  230. #endif
  231. forward L_SAM_OnFS();
  232. forward L_SAM_OnFSExit();
  233. #else
  234. public OnGameModeInit()
  235. {
  236. for(new samid; samid< MAX_LSAMS; samid++)
  237. {
  238. L_SAMData[samid][L_SAMX] = 0.0;
  239. L_SAMData[samid][L_SAMY] = 0.0;
  240. L_SAMData[samid][L_SAMZ] = 0.0;
  241. L_SAMData[samid][L_SAMrX] = 0.0;
  242. L_SAMData[samid][L_SAMrY] = 0.0;
  243. L_SAMData[samid][L_SAMrZ] = 0.0;
  244. L_SAMData[samid][L_SAMDrawDistance] = 0.0;
  245. L_SAMData[samid][L_SAMRange] = 0.0;
  246. L_SAMData[samid][L_SAMSpeed] = 0;
  247. L_SAMData[samid][L_SAMPower] = 0;
  248. L_SAMData[samid][L_SAMFollow] = false;
  249. L_SAMData[samid][L_SAMCreated] = false;
  250. L_SAMData[samid][L_SAMObjectID] = -1;
  251. L_SAMData[samid][L_SAMMissileColor] = MISSILE_RADAR_COLOR;
  252. for(new a; a< MAX_PLAYERS; a++) L_SAM_ExceptionalPlayer[a][samid] = false;
  253. }
  254. for(new i; i< MAX_OBJECTS; i++)
  255. {
  256. L_SAMMissileObject[i] = 0;
  257. L_SAMMissilePower[i] = 0;
  258. L_SAMMissileSAMID[i] = -1;
  259. L_SAMMissileProgress[i] = -1;
  260. }
  261. for(new i; i< MAX_PLAYERS; i++)
  262. {
  263. MissileInProgress[i] = false;
  264. L_SAMPlayerPos[i][0] = 0.0;
  265. L_SAMPlayerPos[i][1] = 0.0;
  266. L_SAMPlayerPos[i][2] = 0.0;
  267. PlayerMissile[i] = -1;
  268. L_SAMFollowStopped[i] = false;
  269. #if defined L_SAMUSE_SMOKES
  270. PlayerMissileSmoke[i] = -1;
  271. #endif
  272. }
  273. L_CountSAMS = 0;
  274. SetTimer("LordzSAMTimer", 2500, true);
  275. CallLocalFunction("L_SAM_OnGM", "");
  276. return 1;
  277. }
  278. #if defined _ALS_OnGameModeInit
  279. #undef OnGameModeInit
  280. #else
  281. #define _ALS_OnGameModeInit
  282. #endif
  283. forward L_SAM_OnGM();
  284. public OnGameModeExit()
  285. {
  286. for(new i; i< MAX_LSAMS; i++)
  287. {
  288. if(L_SAMData[i][L_SAMCreated])
  289. {
  290. DestroyObject(L_SAMData[i][L_SAMObjectID]);
  291. }
  292. }
  293. for(new i; i< MAX_OBJECTS; i++)
  294. {
  295. if(L_SAMMissileProgress[i])
  296. {
  297. DestroyObject(i);
  298. #if defined L_SAMUSE_SMOKES
  299. DestroyObject(L_SAMMissileSmoke[i]);
  300. #endif
  301. }
  302. }
  303. CallLocalFunction("L_SAM_OnGMExit", "");
  304. return 1;
  305. }
  306. #if defined _ALS_OnGameModeExit
  307. #undef OnGameModeExit
  308. #else
  309. #define _ALS_OnGameModeExit
  310. #endif
  311. forward L_SAM_OnGMExit();
  312. #endif
  313. forward LordzSAMTimer();
  314. stock AvoidSAMAttacksOnPlayer(playerid, samid)
  315. {
  316. if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  317. L_SAM_ExceptionalPlayer[playerid][samid] = true;
  318. return 1;
  319. }
  320. stock EnableSAMAttacksOnPlayer(playerid, samid)
  321. {
  322. if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  323. L_SAM_ExceptionalPlayer[playerid][samid] = false;
  324. return 1;
  325. }
  326. stock ToggleNoSAMAttacksOnPlayer(playerid, samid, bool:noattack)
  327. {
  328. if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  329. L_SAM_ExceptionalPlayer[playerid][samid] = noattack;
  330. return 1;
  331. }
  332. stock SetSAMMissileSpeed(samid, speed)
  333. {
  334. if(L_SAMData[samid][L_SAMCreated] == false) return 0;
  335. L_SAMData[samid][L_SAMSpeed] = speed;
  336. return 1;
  337. }
  338. stock GetSAMMissileSpeed(samid)
  339. {
  340. if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  341. return L_SAMData[samid][L_SAMSpeed];
  342. }
  343. stock SetSAMMissilePower(samid, Power)
  344. {
  345. if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  346. if(Power >= SAM_POWER_BEST) L_SAMData[samid][L_SAMPower] = SAM_POWER_BEST;
  347. else if(Power <= SAM_POWER_LOW) L_SAMData[samid][L_SAMPower] = SAM_POWER_LOW;
  348. else L_SAMData[samid][L_SAMPower] = Power;
  349. return Power;
  350. }
  351. stock GetSAMMissilePower(samid)
  352. {
  353. if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  354. return L_SAMData[samid][L_SAMPower];
  355. }
  356. stock GetSAMObjectID(samid)
  357. {
  358. if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  359. return L_SAMData[samid][L_SAMObjectID];
  360. }
  361. stock IsSAMMissilesFollowing(samid)
  362. {
  363. if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  364. if(L_SAMData[samid][L_SAMFollow] == true) return true;
  365. else return false;
  366. }
  367. stock SetSAMMissileColor(samid, color)
  368. {
  369. if(L_SAMData[samid][L_SAMCreated] == false) return 0;
  370. L_SAMData[samid][L_SAMMissileColor] = color;
  371. return 1;
  372. }
  373. stock GetSAMMissileColor(samid)
  374. {
  375. return L_SAMData[samid][L_SAMMissileColor];
  376. }
  377. //Thanks to the person who created the function "randomEx"
  378. stock L_randomEx(minnum = cellmin, maxnum = cellmax) return random(maxnum - minnum + 1) + minnum;
  379. forward MissileAuthorized(playerid);
  380. public MissileAuthorized(playerid)
  381. {
  382. if(pDeathState[playerid] == PLAYER_STATE_REVIVE || pDeathState[playerid] == PLAYER_STATE_INHOSP) return 1; // prevent the launcher from constantly shooting at players that were just taken down
  383. if(!IsPlayerInAnyVehicle(playerid)) return 1;
  384. if(!IsAHelicopter(GetPlayerVehicleID(playerid)) && !IsAPlane(GetPlayerVehicleID(playerid))) return 1;
  385. new vehfaction = sVehicleInfo[GetDynamicVehicleID(GetPlayerVehicleID(playerid))][v_faction];
  386. if(vehfaction == FACTION_SAPD || vehfaction == FACTION_FBI || vehfaction == FACTION_FMD || vehfaction == 5 || vehfaction == FACTION_GOV || vehfaction == FACTION_SANG) return 1;
  387. if(vehMissileAuthorized[GetPlayerVehicleID(playerid)]) return 1;
  388. return 0;
  389. }
  390. forward GivePlayerMissileWarning(playerid);
  391. public GivePlayerMissileWarning(playerid)
  392. {
  393. MissileWarning[playerid] = 5;
  394. GameTextForPlayer(playerid, "~r~RESTRICTED ZONE~n~~r~LEAVE NOW ~w~(5 SECONDS LEFT)", 1000, 3);
  395. PlayerMissileWarningTimerID[playerid] = SetTimerEx("PlayerMissileWarning", 1000, true, "i", playerid);
  396. return 1;
  397. }
  398. forward PlayerMissileWarning(playerid);
  399. public PlayerMissileWarning(playerid)
  400. {
  401. new warningmsg[128];
  402. if(MissileWarning[playerid] > 0) MissileWarning[playerid]--;
  403. if(MissileWarning[playerid] == 0) KillTimer(PlayerMissileWarningTimerID[playerid]);
  404. format(warningmsg, sizeof(warningmsg), "~r~RESTRICTED ZONE~n~~r~LEAVE NOW ~w~(%d SECONDS LEFT)", MissileWarning[playerid]);
  405. GameTextForPlayer(playerid, warningmsg, 1000, 3);
  406. return 1;
  407. }
  408. public LordzSAMTimer()
  409. {
  410. for(new i; i< MAX_LSAMS; i++)
  411. {
  412. if(L_SAMData[i][L_SAMCreated])
  413. {
  414. for(new a, amax = GetMaxPlayers(); a< amax; a++)
  415. {
  416. if(!IsPlayerConnected(a)) continue;
  417. if(MissileAuthorized(a)) continue;
  418. if(!IsPlayerInRangeOfPoint(a, L_SAMData[i][L_SAMRange], L_SAMData[i][L_SAMX], L_SAMData[i][L_SAMY], L_SAMData[i][L_SAMZ])) continue;
  419. if(L_SAM_ExceptionalPlayer[a][i] == true) continue;
  420. if(MissileInProgress[a] == true) continue;
  421. if(MissileWarning[a] > 0) continue;
  422. if(MissileWarning[a] == -1) {
  423. new counter = 0, msg[128];
  424. foreach(new player: Player)
  425. {
  426. if(GetPlayerVehicleID(player) != GetPlayerVehicleID(a)) continue;
  427. GivePlayerMissileWarning(player);
  428. counter++;
  429. }
  430. format(msg, sizeof(msg), "Anti Aircraft (%d) has spotted a %s (%d occupied), taking it down in 5 seconds.", i, GetVehicleFriendlyName(GetPlayerVehicleID(a)), counter);
  431. SendRadioMessage(FACTION_SANG, COLOR_RED, msg);
  432. continue;
  433. }
  434. GetPlayerPos(a, L_SAMPlayerPos[a][0], L_SAMPlayerPos[a][1], L_SAMPlayerPos[a][2]);
  435. 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);
  436. #if defined L_SAMUSE_SMOKES
  437. new p_missilesmoke = CreateObject(18723, L_SAMData[i][L_SAMX], L_SAMData[i][L_SAMY], L_SAMData[i][L_SAMZ], 0.0, 0.0, 0.0, 300.0);
  438. AttachObjectToObject(p_missilesmoke, p_missileobj, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1);
  439. #endif
  440. PlayerMissile[a] = p_missileobj;
  441. #if defined L_SAMUSE_SMOKES
  442. PlayerMissileSmoke[a] = p_missilesmoke;
  443. #endif
  444. L_SAMMissileObject[p_missileobj] = 1;
  445. #if defined L_SAMUSE_SMOKES
  446. L_SAMMissileSmoke[p_missileobj] = p_missilesmoke;
  447. #endif
  448. L_SAMMissilePower[p_missileobj] = L_SAMData[i][L_SAMPower];
  449. L_SAMMissileSAMID[p_missileobj] = i;
  450. L_SAMMissileProgress[p_missileobj] = a;
  451. L_SetObjectFaceCoords3D(p_missileobj, L_SAMPlayerPos[a][0], L_SAMPlayerPos[a][1], L_SAMPlayerPos[a][2]);
  452. MoveObject(p_missileobj, L_SAMPlayerPos[a][0], L_SAMPlayerPos[a][1], L_SAMPlayerPos[a][2], L_SAMData[i][L_SAMSpeed]);
  453. MissileInProgress[a] = true;
  454. if(L_SAMData[i][L_SAMFollow] == true) L_SAMFollowStopped[a] = false;
  455. CallLocalFunction("OnSAMMissileLaunch", "ii", a, i);
  456. }
  457. }
  458. }
  459. return 1;
  460. }
  461. stock DestroySAMMissile(playerid)
  462. {
  463. if(!MissileInProgress[playerid]) return 0;
  464. L_SAMMissileStopped[PlayerMissile[playerid]] = false;
  465. L_SAMFollowStopped[playerid] = true;
  466. return CallLocalFunction("OnObjectMoved", "i", PlayerMissile[playerid]);
  467. }
  468. stock IsSAMMissileChasing(playerid)
  469. {
  470. if(MissileInProgress[playerid]) return true;
  471. else return false;
  472. }
  473. public OnObjectMoved(objectid)
  474. {
  475. if(L_SAMMissileObject[objectid] == 1)
  476. {
  477. if(L_SAMMissileStopped[objectid] == false)
  478. {
  479. new Float:X, Float:Y, Float:Z;
  480. GetObjectPos(objectid, X, Y, Z);
  481. switch(L_SAMMissilePower[objectid])
  482. {
  483. case SAM_POWER_LOW: CreateExplosion(X+4.0, Y+4.0, Z, 2, 12.0);
  484. case SAM_POWER_NORMAL: CreateExplosion(X+6.0, Y+6.0, Z, 6, 10.0);
  485. case SAM_POWER_HIGH:
  486. {
  487. CreateExplosion(X+8.0,Y, Z, 7, 10.0);
  488. CreateExplosion(X-8.0,Y, Z, 7, 10.0);
  489. CreateExplosion(X, Y+8.0,Z, 7, 10.0);
  490. CreateExplosion(X, Y-8.0,Z, 7, 10.0);
  491. }
  492. case SAM_POWER_BEST:
  493. {
  494. new Float:range = 8.0;
  495. CreateExplosion(X+range,Y, Z, 6, 10.0);
  496. CreateExplosion(X-range,Y, Z, 6, 10.0);
  497. CreateExplosion(X, Y+range,Z, 6, 10.0);
  498. CreateExplosion(X, Y-range,Z, 6, 10.0);
  499. CreateExplosion(X+range,Y+range,Z, 6, 10.0);
  500. CreateExplosion(X-range,Y+range,Z, 6, 10.0);
  501. CreateExplosion(X-range,Y-range,Z, 6, 10.0);
  502. }
  503. }
  504. if(IsPlayerConnected(L_SAMMissileProgress[objectid]) && L_SAMFollowStopped[L_SAMMissileProgress[objectid]] == false)
  505. CallLocalFunction("OnSAMMissileHitPlayer", "ii", L_SAMMissileProgress[objectid], L_SAMMissileSAMID[objectid]);
  506. DestroyObject(objectid);
  507. #if defined L_SAMUSE_SMOKES
  508. DestroyObject(L_SAMMissileSmoke[objectid]);
  509. #endif
  510. L_SAMMissileObject[objectid] = 0;
  511. L_SAMMissilePower[objectid] = 0;
  512. L_SAMMissileSAMID[objectid] = -1;
  513. MissileInProgress[L_SAMMissileProgress[objectid]] = false;
  514. L_SAMMissileProgress[objectid] = -1;
  515. }
  516. }
  517. CallLocalFunction("L_SAM_OnObjMoved", "i", objectid);
  518. return 1;
  519. }
  520. forward OnSAMMissileLaunch(playerid, samid);
  521. forward OnSAMMissileHitPlayer(playerid, samid);
  522. public OnSAMMissileHitPlayer(playerid, samid)
  523. {
  524. foreach(new i: Player)
  525. {
  526. if(GetPlayerVehicleID(i) != GetPlayerVehicleID(playerid)) continue;
  527. if(PlayerInfo[i][pAdmin] > 1) continue;
  528. SetPlayerHealth(i, 0); // make sure the players inside the vehicle are dead, since the explosion doesn't kill you since you're in a vehicle.
  529. MissileWarning[i] = -1;
  530. }
  531. return 1;
  532. }
  533. #if defined _ALS_OnObjectMoved
  534. #undef OnObjectMoved
  535. #else
  536. #define _ALS_OnObjectMoved
  537. #endif
  538. forward L_SAM_OnObjMoved(objectid);
  539. public OnPlayerConnect(playerid)
  540. {
  541. for(new i; i< MAX_LSAMS; i++) L_SAM_ExceptionalPlayer[playerid][i] = false;
  542. CallLocalFunction("L_SAM_OPC", "i", playerid);
  543. MissileWarning[playerid] = -1;
  544. return 1;
  545. }
  546. #if defined _ALS_OnPlayerConnect
  547. #undef OnPlayerConnect
  548. #else
  549. #define _ALS_OnPlayerConnect
  550. #endif
  551. forward L_SAM_OPC(playerid);
  552. public OnPlayerSpawn(playerid)
  553. {
  554. if(MissileInProgress[playerid] == true)
  555. {
  556. L_SAMMissileStopped[PlayerMissile[playerid]] = false;
  557. CallLocalFunction("OnObjectMoved", "i", PlayerMissile[playerid]);
  558. }
  559. CallLocalFunction("L_SAM_OPS", "i", playerid);
  560. return 1;
  561. }
  562. #if defined _ALS_OnPlayerSpawn
  563. #undef OnPlayerSpawn
  564. #else
  565. #define _ALS_OnPlayerSpawn
  566. #endif
  567. forward L_SAM_OPS(playerid);
  568. #define OnObjectMoved L_SAM_OnObjMoved
  569. #define OnGameModeInit L_SAM_OnGM
  570. #define OnGameModeExit L_SAM_OnGMExit
  571. #define OnPlayerConnect L_SAM_OPC
  572. #define OnPlayerSpawn L_SAM_OPS
  573. CMD:authorizeaircraft(playerid, params[])
  574. {
  575. if(PlayerInfo[playerid][pMember] != FACTION_SANG) return AdmErrorMsg;
  576. new vehid;
  577. if(sscanf(params, "d", vehid)) return SendClientMessage(playerid, -1, "{00BFFF}Usage:{FFFFFF} /authorizeaircraft [vehicleID]");
  578. if(vehid == INVALID_VEHICLE_ID) return SendClientMessage(playerid, COLOR_GREY, "Invalid vehicle ID.");
  579. if(!IsAHelicopter(vehid) && !IsAPlane(vehid)) return SendClientMessage(playerid, COLOR_GREY, "That vehicle is not an aircraft.");
  580. vehMissileAuthorized[vehid] = !vehMissileAuthorized[vehid];
  581. new msg[128];
  582. if(vehMissileAuthorized[vehid])
  583. {
  584. format(msg, sizeof(msg), "%s has authorized aircraft #%d (%s)", PlayerICName(playerid), vehid, GetVehicleFriendlyName(vehid));
  585. SendRadioMessage(FACTION_SANG, COLOR_SANG, msg);
  586. }
  587. else
  588. {
  589. format(msg, sizeof(msg), "%s has unauthorized aircraft #%d (%s)", PlayerICName(playerid), vehid, GetVehicleFriendlyName(vehid));
  590. SendRadioMessage(FACTION_SANG, COLOR_SANG, msg);
  591. }
  592. return 1;
  593. }