Advertisement
Lordz

L_SAM3.inc

Jan 8th, 2014
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 21.27 KB | None | 0 0
  1. #if defined FOR_FUCK_SAKE_L_SAM
  2. PLEASE DEFINE FILTERSCRIPT IF YOU ARE USING IT AS A FILTERSCRIPT
  3. I've spent too much time for forgetting that define, I thought my include was
  4. fucked up. But nope, you must define it to use it as a filterscript!
  5. #endif
  6.  
  7. /*______________________________________________________________________________
  8.  
  9.                     L-SAM "Lordz's Surface To Air Missiles" - v1.3
  10.                     Copyright(c) 2014 - L_SAM3.inc
  11.                     Author : Lordzโ„ข
  12.                     Version : 1.3
  13.                     Initial v1 Released Date : 04-01-2014
  14.                     Thread : http://forum.sa-mp.com/showthread.php?t=484765
  15.                     Thanks to the person who created randomEx,
  16.                     Thanks to RyDeR` for SetObjectFaceCoords3D function,
  17.                                         &
  18.                     All the players of YoUnG Generations for Testing this!
  19.  
  20. * Happy New Year!
  21.  
  22. //Functions:
  23.  
  24. 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);
  25. native IsSAMMissilesFollowing(samid);
  26. native DestroySAM(samid);
  27. native AvoidSAMAttacksOnPlayer(playerid, samid);
  28. native EnableSAMAttacksOnPlayer(playerid, samid);
  29. native ToggleNoSAMAttacksOnPlayer(playerid, samid, bool:noattack);
  30. native SetSAMMissileSpeed(samid, speed);
  31. native SetSAMMissilePower(samid, Power);
  32. native SetSAMMissileColor(samid, color);
  33. native GetSAMMissileSpeed(samid);
  34. native GetSAMMissilePower(samid);
  35. native GetSAMObjectID(samid);
  36. native GetSAMMissileColor(samid);
  37. native IsMissileFollowingLimited(samid);
  38. native DestroySAMMissile(playerid);
  39. native IsSAMMissileChasing(playerid);
  40.  
  41. //Callbacks:
  42. OnSAMMissileHitPlayer(playerid, samid, power);
  43.  
  44. ChangeLogs:
  45. v1.0 (01/01/2014)
  46. Initial release.
  47.  
  48. v1.2 (02/01/2014)
  49. + The following missile system has been done! Parameter is at the end of CreateSAM.
  50.  Set it to true to allow the SAM to target lock players.
  51. + Added a function called IsSAMMissilesFollowing which returns true in case if SAM
  52.  got following missiles, false if not.
  53. + Missiles can now have colors specified on radar. It's per-sam colors.
  54. + Added two functions called GetSAMMissileColor and SetSAMMissileColor.
  55.  
  56. v2 <B>
  57.  
  58. + Fixed the tag mismatch problems in AvoidSAMAttacksOnPlayer and on
  59.  EnableSAMAttacksOnPlayer.
  60.  
  61. v1.3
  62. + This include no longer uses Streamer as it's use is very less for further
  63.  things coming. So, it doesn't use Streamer function anymore.
  64. + The missiles now set it's facing position according to the player's position.
  65. + Added smoke effects on missiles. You can disable it by removing :
  66.  #define L_SAMUSE_SMOKES from the include.
  67. + Added callback called "OnSAMMissileLaunch" which is called when a SAM
  68.  launches a missile on player.
  69. + Added callback called "OnSAMMissileHitPlayer" which is called when a SAM
  70.  missile hits the player. (Player must be connected)
  71. + Added a new parameter called "bool:followlimit" on CreateSAM. It creates
  72.  limitations for the following range according to the area range specified.
  73.  It's set to false as default so it follows the player everywhere until it
  74.  hits the player, if not set to true.
  75. + Added function called "IsMissileFollowingLimited" which returns true in case
  76.  if the following missiles got range limit, else false.
  77. + Added function called "DestroySAMMissile" which destroys the missile if player
  78.  is being chased by any missiles.
  79. + Added function called "IsSAMMissileChasing" which return true in case if the
  80.  player is being chased by a missile. False if not.
  81. _______________________________________________________________________________*/
  82.  
  83. //#define FILTERSCRIPT
  84.  
  85. #define L_SAMUSE_SMOKES
  86.  
  87. #if defined _included_l_sam
  88. #endinput
  89. #endif
  90.  
  91. #define _included_l_sam
  92.  
  93. #include <a_samp>
  94.  
  95.  
  96.  
  97. #define MAX_LSAMS 100
  98.  
  99. #define SAM_POWER_LOW    0
  100. #define SAM_POWER_NORMAL 1
  101. #define SAM_POWER_HIGH   2
  102. #define SAM_POWER_BEST 3
  103.  
  104. #define MISSILE_RADAR_COLOR 0x660000FF
  105.  
  106.  
  107.  
  108. enum L_saminfo
  109. {
  110.     Float:L_SAMX,
  111.     Float:L_SAMY,
  112.     Float:L_SAMZ,
  113.     Float:L_SAMrX,
  114.     Float:L_SAMrY,
  115.     Float:L_SAMrZ,
  116.     Float:L_SAMDrawDistance,
  117.     Float:L_SAMRange,
  118.     L_SAMSpeed,
  119.     L_SAMPower,
  120.     bool:L_SAMFollow,
  121.     bool:L_SAMFollowLimit,
  122.     Float:L_SAMFollowLimitRange,
  123.     bool:L_SAMCreated,
  124.     L_SAMObjectID,
  125.     L_SAMMissileColor,
  126. }
  127.  
  128. new L_SAMData[MAX_LSAMS][L_saminfo],
  129.     L_CountSAMS = 0,
  130.     Float:L_SAMPlayerPos[MAX_PLAYERS][3],
  131.     PlayerMissile[MAX_PLAYERS],
  132. #if defined L_SAMUSE_SMOKES
  133.     PlayerMissileSmoke[MAX_PLAYERS],
  134. #endif
  135.     bool:MissileInProgress[MAX_PLAYERS],
  136.     L_SAMMissileObject[MAX_OBJECTS],
  137. #if defined L_SAMUSE_SMOKES
  138.     L_SAMMissileSmoke[MAX_OBJECTS],
  139. #endif
  140.     L_SAMMissilePower[MAX_OBJECTS],
  141.     L_SAMMissileSAMID[MAX_OBJECTS],
  142.     L_SAMMissileProgress[MAX_OBJECTS],
  143.     L_SAMMissileMarker[MAX_PLAYERS],
  144.     bool:L_SAMFollowStopped[MAX_PLAYERS],
  145.     bool:L_SAM_ExceptionalPlayer[MAX_PLAYERS][MAX_LSAMS],
  146.     L_SAMAssignedSpeed[MAX_OBJECTS],
  147.     bool:L_SAMMissileStopped[MAX_OBJECTS];
  148.  
  149. 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)
  150. {
  151.     if(L_CountSAMS > MAX_LSAMS) return printf("โ€ข <L_SAM> Error : Couldn't create SAM, maximum SAMS have already been done!"), 0;
  152.     new samid = L_CountSAMS;
  153.     L_SAMData[samid][L_SAMX] = X;
  154.     L_SAMData[samid][L_SAMY] = Y;
  155.     L_SAMData[samid][L_SAMZ] = Z;
  156.     L_SAMData[samid][L_SAMrX] = rX;
  157.     L_SAMData[samid][L_SAMrY] = rY;
  158.     L_SAMData[samid][L_SAMrZ] = rZ;
  159.     L_SAMData[samid][L_SAMDrawDistance] = DrawDistance;
  160.     L_SAMData[samid][L_SAMRange] = Range;
  161.     L_SAMData[samid][L_SAMSpeed] = Speed;
  162.     if(Power >= SAM_POWER_BEST)
  163.      L_SAMData[samid][L_SAMPower] = SAM_POWER_BEST;
  164.     else if(Power <= SAM_POWER_LOW)
  165.      L_SAMData[samid][L_SAMPower] = SAM_POWER_LOW;
  166.     else L_SAMData[samid][L_SAMPower] = Power;
  167.     L_SAMData[samid][L_SAMFollow] = follow;
  168.     L_SAMData[samid][L_SAMFollowLimit] = followlimit;
  169.     L_SAMData[samid][L_SAMFollowLimitRange] = Range;
  170.     L_SAMData[samid][L_SAMObjectID] = CreateObject(18848, X, Y, Z, rX, rY, rZ, DrawDistance);
  171.     L_SAMData[samid][L_SAMMissileColor] = MISSILE_RADAR_COLOR;
  172.     L_SAMData[samid][L_SAMCreated] = true;
  173.     L_CountSAMS++;
  174.     return samid;
  175. }
  176.  
  177. stock DestroySAM(samid)
  178. {
  179.     if(L_SAMData[samid][L_SAMCreated] == false) return 0;
  180.     L_SAMData[samid][L_SAMX] = 0.0;
  181.     L_SAMData[samid][L_SAMY] = 0.0;
  182.     L_SAMData[samid][L_SAMZ] = 0.0;
  183.     L_SAMData[samid][L_SAMrX] = 0.0;
  184.     L_SAMData[samid][L_SAMrY] = 0.0;
  185.     L_SAMData[samid][L_SAMrZ] = 0.0;
  186.     L_SAMData[samid][L_SAMDrawDistance] = 0.0;
  187.     L_SAMData[samid][L_SAMRange] = 0.0;
  188.     L_SAMData[samid][L_SAMSpeed] = 0;
  189.     L_SAMData[samid][L_SAMPower] = 0;
  190.     L_SAMData[samid][L_SAMFollow] = false;
  191.     L_SAMData[samid][L_SAMCreated] = false;
  192.     DestroyObject(L_SAMData[samid][L_SAMObjectID]);
  193.     L_SAMData[samid][L_SAMObjectID] = -1;
  194.     L_SAMData[samid][L_SAMMissileColor] = MISSILE_RADAR_COLOR;
  195.     return 1;
  196. }
  197.  
  198. stock IsMissileFollowingLimited(samid)
  199. {
  200.     if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  201.     if(L_SAMData[samid][L_SAMFollow] == false) return false;
  202.     if(L_SAMData[samid][L_SAMFollowLimit] == false) return false;
  203.     return true;
  204. }
  205.  
  206. //Thanks to RyDeR` for this function!
  207. stock L_SetObjectFaceCoords3D(iObject, Float: fX, Float: fY, Float: fZ, Float: fRollOffset = 0.0, Float: fPitchOffset = 0.0, Float: fYawOffset = 0.0) {
  208.    new
  209.        Float: fOX,
  210.        Float: fOY,
  211.        Float: fOZ,
  212.        Float: fPitch
  213.    ;
  214.    GetObjectPos(iObject, fOX, fOY, fOZ);
  215.  
  216.    fPitch = floatsqroot(floatpower(fX - fOX, 2.0) + floatpower(fY - fOY, 2.0));
  217.    fPitch = floatabs(atan2(fPitch, fZ - fOZ));
  218.  
  219.    fZ = atan2(fY - fOY, fX - fOX) - 90.0; // Yaw
  220.  
  221.    SetObjectRot(iObject, fRollOffset, fPitch + fPitchOffset, fZ + fYawOffset);
  222. }
  223.  
  224.  
  225. #if defined FILTERSCRIPT
  226.  
  227. public OnFilterScriptInit()
  228. {
  229.     for(new samid; samid< MAX_LSAMS; samid++)
  230.     {
  231.         L_SAMData[samid][L_SAMX] = 0.0;
  232.         L_SAMData[samid][L_SAMY] = 0.0;
  233.         L_SAMData[samid][L_SAMZ] = 0.0;
  234.         L_SAMData[samid][L_SAMrX] = 0.0;
  235.         L_SAMData[samid][L_SAMrY] = 0.0;
  236.         L_SAMData[samid][L_SAMrZ] = 0.0;
  237.         L_SAMData[samid][L_SAMDrawDistance] = 0.0;
  238.         L_SAMData[samid][L_SAMRange] = 0.0;
  239.         L_SAMData[samid][L_SAMSpeed] = 0;
  240.         L_SAMData[samid][L_SAMPower] = 0;
  241.         L_SAMData[samid][L_SAMFollow] = false;
  242.         L_SAMData[samid][L_SAMCreated] = false;
  243.         L_SAMData[samid][L_SAMObjectID] = -1;
  244.         L_SAMData[samid][L_SAMMissileColor] = MISSILE_RADAR_COLOR;
  245.         for(new a; a< MAX_PLAYERS; a++) L_SAM_ExceptionalPlayer[a][samid] = false;
  246.     }
  247.     for(new i; i< MAX_OBJECTS; i++)
  248.     {
  249.         L_SAMMissileObject[i] = 0;
  250.         L_SAMMissilePower[i] = 0;
  251.         L_SAMMissileSAMID[i] = -1;
  252.         L_SAMMissileProgress[i] = -1;
  253.     }
  254.     for(new i; i< MAX_PLAYERS; i++)
  255.     {
  256.         MissileInProgress[i] = false;
  257.         L_SAMPlayerPos[i][0] = 0.0;
  258.         L_SAMPlayerPos[i][1] = 0.0;
  259.         L_SAMPlayerPos[i][2] = 0.0;
  260.         PlayerMissile[i] = -1;
  261.         L_SAMFollowStopped[i] = false;
  262.  #if defined L_SAMUSE_SMOKES
  263.         PlayerMissileSmoke[i] = -1;
  264.  #endif
  265.     }
  266.     L_CountSAMS = 0;
  267.     SetTimer("LordzSAMTimer", 2500, true);
  268.     CallLocalFunction("L_SAM_OnFS", "");
  269.     return 1;
  270. }
  271.  
  272. #if defined _ALS_OnFilterScriptInit
  273. #undef OnFilterScriptInit
  274. #else
  275. #define _ALS_OnFilterScriptInit
  276. #endif
  277.  
  278. public OnFilterScriptExit()
  279. {
  280.     for(new i; i< MAX_LSAMS; i++)
  281.     {
  282.         if(L_SAMData[i][L_SAMCreated])
  283.         {
  284.             DestroyObject(L_SAMData[i][L_SAMObjectID]);
  285.         }
  286.     }
  287.     for(new i; i< MAX_OBJECTS; i++)
  288.     {
  289.         if(L_SAMMissileProgress[i])
  290.         {
  291.             DestroyObject(i);
  292.   #if defined L_SAMUSE_SMOKES
  293.             DestroyObject(L_SAMMissileSmoke[i]);
  294.   #endif
  295.         }
  296.     }
  297.     for(new i; i< MAX_PLAYERS; i++)
  298.     {
  299.         if(MissileInProgress[i]) RemovePlayerMapIcon(i, 99);
  300.     }
  301.     CallLocalFunction("L_SAM_OnFSExit", "");
  302.     return 1;
  303. }
  304.  
  305. #if defined _ALS_OnFilterScriptExit
  306.     #undef OnFilterScriptExit
  307. #else
  308.     #define _ALS_OnFilterScriptExit
  309. #endif
  310.  
  311. forward L_SAM_OnFS();
  312. forward L_SAM_OnFSExit();
  313.  
  314. #else
  315.  
  316. public OnGameModeInit()
  317. {
  318.     for(new samid; samid< MAX_LSAMS; samid++)
  319.     {
  320.         L_SAMData[samid][L_SAMX] = 0.0;
  321.         L_SAMData[samid][L_SAMY] = 0.0;
  322.         L_SAMData[samid][L_SAMZ] = 0.0;
  323.         L_SAMData[samid][L_SAMrX] = 0.0;
  324.         L_SAMData[samid][L_SAMrY] = 0.0;
  325.         L_SAMData[samid][L_SAMrZ] = 0.0;
  326.         L_SAMData[samid][L_SAMDrawDistance] = 0.0;
  327.         L_SAMData[samid][L_SAMRange] = 0.0;
  328.         L_SAMData[samid][L_SAMSpeed] = 0;
  329.         L_SAMData[samid][L_SAMPower] = 0;
  330.         L_SAMData[samid][L_SAMFollow] = false;
  331.         L_SAMData[samid][L_SAMCreated] = false;
  332.         L_SAMData[samid][L_SAMObjectID] = -1;
  333.         L_SAMData[samid][L_SAMMissileColor] = MISSILE_RADAR_COLOR;
  334.         for(new a; a< MAX_PLAYERS; a++) L_SAM_ExceptionalPlayer[a][samid] = false;
  335.     }
  336.     for(new i; i< MAX_OBJECTS; i++)
  337.     {
  338.         L_SAMMissileObject[i] = 0;
  339.         L_SAMMissilePower[i] = 0;
  340.         L_SAMMissileSAMID[i] = -1;
  341.         L_SAMMissileProgress[i] = -1;
  342.     }
  343.     for(new i; i< MAX_PLAYERS; i++)
  344.     {
  345.         MissileInProgress[i] = false;
  346.         L_SAMPlayerPos[i][0] = 0.0;
  347.         L_SAMPlayerPos[i][1] = 0.0;
  348.         L_SAMPlayerPos[i][2] = 0.0;
  349.         PlayerMissile[i] = -1;
  350.         L_SAMFollowStopped[i] = false;
  351.  #if defined L_SAMUSE_SMOKES
  352.         PlayerMissileSmoke[i] = -1;
  353.  #endif
  354.     }
  355.     L_CountSAMS = 0;
  356.     SetTimer("LordzSAMTimer", 2500, true);
  357.     CallLocalFunction("L_SAM_OnGM", "");
  358.     return 1;
  359. }
  360.  
  361. #if defined _ALS_OnGameModeInit
  362.     #undef OnGameModeInit
  363. #else
  364.     #define _ALS_OnGameModeInit
  365. #endif
  366.  
  367. forward L_SAM_OnGM();
  368. public OnGameModeExit()
  369. {
  370.     for(new i; i< MAX_LSAMS; i++)
  371.     {
  372.         if(L_SAMData[i][L_SAMCreated])
  373.         {
  374.             DestroyObject(L_SAMData[i][L_SAMObjectID]);
  375.         }
  376.     }
  377.     for(new i; i< MAX_OBJECTS; i++)
  378.     {
  379.         if(L_SAMMissileProgress[i])
  380.         {
  381.             DestroyObject(i);
  382.   #if defined L_SAMUSE_SMOKES
  383.             DestroyObject(L_SAMMissileSmoke[i]);
  384.   #endif
  385.         }
  386.     }
  387.     for(new i; i< MAX_PLAYERS; i++)
  388.     {
  389.         if(MissileInProgress[i]) RemovePlayerMapIcon(i, 99);
  390.     }
  391.     CallLocalFunction("L_SAM_OnGMExit", "");
  392.     return 1;
  393. }
  394.  
  395. #if defined _ALS_OnGameModeExit
  396.     #undef OnGameModeExit
  397. #else
  398.     #define _ALS_OnGameModeExit
  399. #endif
  400. forward L_SAM_OnGMExit();
  401. #endif
  402.  
  403. forward LordzSAMTimer();
  404.  
  405. stock AvoidSAMAttacksOnPlayer(playerid, samid)
  406. {
  407.     if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  408.     L_SAM_ExceptionalPlayer[playerid][samid] = true;
  409. return 1;
  410. }
  411.  
  412. stock EnableSAMAttacksOnPlayer(playerid, samid)
  413. {
  414.     if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  415.     L_SAM_ExceptionalPlayer[playerid][samid] = false;
  416. return 1;
  417. }
  418.  
  419. stock ToggleNoSAMAttacksOnPlayer(playerid, samid, bool:noattack)
  420. {
  421.     if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  422.     L_SAM_ExceptionalPlayer[playerid][samid] = noattack;
  423. return 1;
  424. }
  425.  
  426. stock SetSAMMissileSpeed(samid, speed)
  427. {
  428.     if(L_SAMData[samid][L_SAMCreated] == false) return 0;
  429.     L_SAMData[samid][L_SAMSpeed] = speed;
  430. return 1;
  431. }
  432.  
  433. stock GetSAMMissileSpeed(samid)
  434. {
  435.     if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  436.     return L_SAMData[samid][L_SAMSpeed];
  437. }
  438.  
  439. stock SetSAMMissilePower(samid, Power)
  440. {
  441.     if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  442.     if(Power >= SAM_POWER_BEST) L_SAMData[samid][L_SAMPower] = SAM_POWER_BEST;
  443.     else if(Power <= SAM_POWER_LOW) L_SAMData[samid][L_SAMPower] = SAM_POWER_LOW;
  444.     else L_SAMData[samid][L_SAMPower] = Power;
  445.     return Power;
  446. }
  447.  
  448. stock GetSAMMissilePower(samid)
  449. {
  450.     if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  451.     return L_SAMData[samid][L_SAMPower];
  452. }
  453.  
  454. stock GetSAMObjectID(samid)
  455. {
  456.     if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  457.     return L_SAMData[samid][L_SAMObjectID];
  458. }
  459.  
  460. stock IsSAMMissilesFollowing(samid)
  461. {
  462.     if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  463.     if(L_SAMData[samid][L_SAMFollow] == true) return true;
  464.     else return false;
  465. }
  466.  
  467. stock SetSAMMissileColor(samid, color)
  468. {
  469.     if(L_SAMData[samid][L_SAMCreated] == false) return 0;
  470.     L_SAMData[samid][L_SAMMissileColor] = color;
  471.     return 1;
  472. }
  473.  
  474. stock GetSAMMissileColor(samid)
  475. {
  476.     return L_SAMData[samid][L_SAMMissileColor];
  477. }
  478.  
  479. //Thanks to the person who created the function "randomEx"
  480. stock L_randomEx(minnum = cellmin, maxnum = cellmax) return random(maxnum - minnum + 1) + minnum;
  481.  
  482.  
  483. public LordzSAMTimer()
  484. {
  485.     for(new i; i< MAX_LSAMS; i++)
  486.     {
  487.         if(L_SAMData[i][L_SAMCreated])
  488.         {
  489.             for(new a; a< GetMaxPlayers(); a++)
  490.             {
  491.                 if(!IsPlayerConnected(a)) continue;
  492.                 if(!IsPlayerInRangeOfPoint(a, L_SAMData[i][L_SAMRange], L_SAMData[i][L_SAMX], L_SAMData[i][L_SAMY], L_SAMData[i][L_SAMZ])) continue;
  493.                 if(L_SAM_ExceptionalPlayer[a][i] == true) continue;
  494.                 if(MissileInProgress[a] == true) continue;
  495.                 GetPlayerPos(a, L_SAMPlayerPos[a][0], L_SAMPlayerPos[a][1], L_SAMPlayerPos[a][2]);
  496.                 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);
  497.         #if defined L_SAMUSE_SMOKES
  498.                 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);
  499.                 AttachObjectToObject(p_missilesmoke, p_missileobj, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1);
  500.         #endif
  501.                 PlayerMissile[a] = p_missileobj;
  502.         #if defined L_SAMUSE_SMOKES
  503.                 PlayerMissileSmoke[a] = p_missilesmoke;
  504.         #endif
  505.                 L_SAMMissileObject[p_missileobj] = 1;
  506.         #if defined L_SAMUSE_SMOKES
  507.                 L_SAMMissileSmoke[p_missileobj] = p_missilesmoke;
  508.         #endif
  509.                 L_SAMMissilePower[p_missileobj] = L_SAMData[i][L_SAMPower];
  510.                 L_SAMMissileSAMID[p_missileobj] = i;
  511.                 L_SAMMissileProgress[p_missileobj] = a;
  512.                 L_SetObjectFaceCoords3D(p_missileobj, L_SAMPlayerPos[a][0], L_SAMPlayerPos[a][1], L_SAMPlayerPos[a][2]);
  513.                 MoveObject(p_missileobj, L_SAMPlayerPos[a][0], L_SAMPlayerPos[a][1], L_SAMPlayerPos[a][2], L_SAMData[i][L_SAMSpeed]);
  514.                 MissileInProgress[a] = true;
  515.                 SetPlayerMapIcon(a, 99, L_SAMData[i][L_SAMX], L_SAMData[i][L_SAMY], L_SAMData[i][L_SAMZ], 0, L_SAMData[i][L_SAMMissileColor]);
  516.                 L_SAMMissileMarker[a] = SetTimerEx("L_SAMUpdateMapIcon", 250, true, "ii", a, i);
  517.                 if(L_SAMData[i][L_SAMFollow] == true) L_SAMFollowStopped[a] = false;
  518.                 CallLocalFunction("OnSAMMissileLaunch", "ii", a, i);
  519.             }
  520.         }
  521.     }
  522.     return 1;
  523. }
  524.  
  525. stock DestroySAMMissile(playerid)
  526. {
  527.     if(!MissileInProgress[playerid]) return 0;
  528.     L_SAMMissileStopped[PlayerMissile[playerid]] = false;
  529.     L_SAMFollowStopped[playerid] = true;
  530.     return CallLocalFunction("OnObjectMoved", "i", PlayerMissile[playerid]);
  531. }
  532.  
  533. stock IsSAMMissileChasing(playerid)
  534. {
  535.     if(MissileInProgress[playerid]) return true;
  536.     else return false;
  537. }
  538.  
  539. forward L_SAMUpdateMapIcon(playerid, samid);
  540. public L_SAMUpdateMapIcon(playerid, samid)
  541. {
  542.     if(!MissileInProgress[playerid]) return KillTimer(L_SAMMissileMarker[playerid]);
  543.     new Float:X, Float:Y, Float:Z, Float:oX, Float:oY, Float:oZ;
  544.     if(L_SAMData[samid][L_SAMFollow] == true)
  545.     {
  546.         L_SAMFollowStopped[playerid] = false;
  547.         GetPlayerPos(playerid, X, Y, Z);
  548.         GetObjectPos(PlayerMissile[playerid], oX, oY, oZ);
  549.         if(L_SAMData[samid][L_SAMFollowLimit] == true)
  550.         {
  551.             if(IsPlayerConnected(playerid))
  552.             {
  553.                 if(!(oX >= L_SAMData[samid][L_SAMX]-L_SAMData[samid][L_SAMFollowLimitRange] &&
  554.                 oX <= L_SAMData[samid][L_SAMX]+L_SAMData[samid][L_SAMFollowLimitRange] &&
  555.                 oY >= L_SAMData[samid][L_SAMY]-L_SAMData[samid][L_SAMFollowLimitRange] &&
  556.                 oY <= L_SAMData[samid][L_SAMY]+L_SAMData[samid][L_SAMFollowLimitRange]))
  557.                 {
  558.                     L_SAMMissileStopped[PlayerMissile[playerid]] = false;
  559.                     L_SAMFollowStopped[playerid] = true;
  560.                     return CallLocalFunction("OnObjectMoved", "i", PlayerMissile[playerid]);
  561.                 }
  562.             }
  563.         }
  564.         if(!IsPlayerConnected(playerid) || IsPlayerInRangeOfPoint(playerid, 10.0, oX, oY, oZ) || L_SAM_ExceptionalPlayer[playerid][samid] == true)
  565.         {
  566.             L_SAMMissileStopped[PlayerMissile[playerid]] = false;
  567.             return CallLocalFunction("OnObjectMoved", "i", PlayerMissile[playerid]);
  568.         }
  569.         else
  570.         {
  571.             L_SAMMissileStopped[PlayerMissile[playerid]] = true;
  572.             L_SAMAssignedSpeed[PlayerMissile[playerid]] = L_SAMData[samid][L_SAMSpeed]+L_randomEx(2,20); //Increasing the speed!
  573.             StopObject(PlayerMissile[playerid]);
  574.             L_SetObjectFaceCoords3D(PlayerMissile[playerid], X, Y, Z);
  575.             MoveObject(PlayerMissile[playerid], X, Y, Z, L_SAMAssignedSpeed[PlayerMissile[playerid]]);
  576.         }
  577.     }
  578.     GetObjectPos(PlayerMissile[playerid], X, Y, Z);
  579.     SetPlayerMapIcon(playerid, 99, X, Y, Z, 0, L_SAMData[samid][L_SAMMissileColor]);
  580.     return 1;
  581. }
  582.  
  583. public OnObjectMoved(objectid)
  584. {
  585.     if(L_SAMMissileObject[objectid] == 1)
  586.     {
  587.         if(L_SAMMissileStopped[objectid] == false)
  588.         {
  589.             new Float:X, Float:Y, Float:Z;
  590.             GetObjectPos(objectid, X, Y, Z);
  591.             switch(L_SAMMissilePower[objectid])
  592.             {
  593.                 case SAM_POWER_LOW: CreateExplosion(X+4.0, Y+4.0, Z, 2, 12.0);
  594.                 case SAM_POWER_NORMAL: CreateExplosion(X+6.0, Y+6.0, Z, 6, 10.0);
  595.                 case SAM_POWER_HIGH:
  596.                 {
  597.                     CreateExplosion(X+8.0,Y, Z, 7, 10.0);
  598.                     CreateExplosion(X-8.0,Y, Z, 7, 10.0);
  599.                     CreateExplosion(X, Y+8.0,Z, 7, 10.0);
  600.                     CreateExplosion(X, Y-8.0,Z, 7, 10.0);
  601.                 }
  602.                 case SAM_POWER_BEST:
  603.                 {
  604.                     new Float:range = 8.0;
  605.                     CreateExplosion(X+range,Y, Z, 6, 10.0);
  606.                     CreateExplosion(X-range,Y, Z, 6, 10.0);
  607.                     CreateExplosion(X, Y+range,Z, 6, 10.0);
  608.                     CreateExplosion(X, Y-range,Z, 6, 10.0);
  609.                     CreateExplosion(X+range,Y+range,Z, 6, 10.0);
  610.                     CreateExplosion(X-range,Y+range,Z, 6, 10.0);
  611.                     CreateExplosion(X-range,Y-range,Z, 6, 10.0);
  612.                 }
  613.             }
  614.             if(IsPlayerConnected(L_SAMMissileProgress[objectid]) && L_SAMFollowStopped[L_SAMMissileProgress[objectid]] == false)
  615.             CallLocalFunction("OnSAMMissileHitPlayer", "ii", L_SAMMissileProgress[objectid], L_SAMMissileSAMID[objectid]);
  616.             DestroyObject(objectid);
  617.         #if defined L_SAMUSE_SMOKES
  618.             DestroyObject(L_SAMMissileSmoke[objectid]);
  619.         #endif
  620.             RemovePlayerMapIcon(L_SAMMissileProgress[objectid], 99);
  621.             L_SAMMissileObject[objectid] = 0;
  622.             L_SAMMissilePower[objectid] = 0;
  623.             L_SAMMissileSAMID[objectid] = -1;
  624.             MissileInProgress[L_SAMMissileProgress[objectid]] = false;
  625.             L_SAMMissileProgress[objectid] = -1;
  626.         }
  627.     }
  628.     CallLocalFunction("L_SAM_OnObjMoved", "i", objectid);
  629.     return 1;
  630. }
  631.  
  632. forward OnSAMMissileLaunch(playerid, samid);
  633. forward OnSAMMissileHitPlayer(playerid, samid);
  634.  
  635.  
  636. #if defined _ALS_OnObjectMoved
  637.     #undef OnObjectMoved
  638. #else
  639.     #define _ALS_OnObjectMoved
  640. #endif
  641.  
  642. forward L_SAM_OnObjMoved(objectid);
  643.  
  644. public OnPlayerConnect(playerid)
  645. {
  646.     for(new i; i< MAX_LSAMS; i++) L_SAM_ExceptionalPlayer[playerid][i] = false;
  647.     CallLocalFunction("L_SAM_OPC", "i", playerid);
  648.     return 1;
  649. }
  650.  
  651. #if defined _ALS_OnPlayerConnect
  652.     #undef OnPlayerConnect
  653. #else
  654.     #define _ALS_OnPlayerConnect
  655. #endif
  656.  
  657. forward L_SAM_OPC(playerid);
  658.  
  659. public OnPlayerSpawn(playerid)
  660. {
  661.     if(MissileInProgress[playerid] == true)
  662.     {
  663.         L_SAMMissileStopped[PlayerMissile[playerid]] = false;
  664.         CallLocalFunction("OnObjectMoved", "i", PlayerMissile[playerid]);
  665.     }
  666.     CallLocalFunction("L_SAM_OPS", "i", playerid);
  667.     return 1;
  668. }
  669.  
  670. #if defined _ALS_OnPlayerSpawn
  671.     #undef OnPlayerSpawn
  672. #else
  673.     #define _ALS_OnPlayerSpawn
  674. #endif
  675.  
  676. forward L_SAM_OPS(playerid);
  677.  
  678. #define OnObjectMoved L_SAM_OnObjMoved
  679. #if defined FILTERSCRIPT
  680.     #define OnFilterScriptInit L_SAM_OnFS
  681.     #define OnFilterScriptExit L_SAM_OnFSExit
  682. #else
  683.     #define OnGameModeInit L_SAM_OnGM
  684.     #define OnGameModeExit L_SAM_OnGMExit
  685. #endif
  686. #define OnPlayerConnect L_SAM_OPC
  687. #define OnPlayerSpawn L_SAM_OPS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement