Advertisement
Lordz

L_SAM.inc

Jan 1st, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.84 KB | None | 0 0
  1. /*______________________________________________________________________________
  2.  
  3.                     L-SAM "Lordz's Surface To Air Missiles" - v1.0
  4.                     Copyright(c) 2014 - L_SAM.inc
  5.                     Author : Lordz™
  6.                     Thanks to Incognito for Streamer
  7.                         &
  8.            All the players of YoUnG Generations for BETA Testing.
  9.  
  10. * Happy New Year!
  11.  
  12. //Functions:
  13.  
  14. 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)
  15. native SetSAMToAttackVehicles(samid, bool:occupied = true);
  16. native DestroySAM(samid);
  17. native AvoidSAMAttacksOnPlayer(playerid, samid);
  18. native EnableSAMAttacksOnPlayer(playerid, samid);
  19. native ToggleNoSAMAttacksOnPlayer(playerid, samid, bool:noattack);
  20. native SetSAMMissileSpeed(samid, speed);
  21. native SetSAMMissilePower(samid, Power);
  22. native GetSAMMissileSpeed(samid);
  23. native GetSAMMissilePower(samid);
  24. native GetSAMObjectID(samid);
  25.  
  26. _______________________________________________________________________________*/
  27.  
  28. #if defined _included_l_sam
  29.  #endinput
  30. #endif
  31.  
  32. #define _included_l_sam
  33.  
  34. #include <a_samp>
  35.  
  36. //#define USE_STREAMER //Uncomment this line in case if you want to use streamer -
  37.                     // SAM objects.
  38.  
  39. #if defined USE_STREAMER
  40.  #include <streamer>
  41. #endif
  42.  
  43. #define MAX_LSAMS 100
  44.  
  45. #define SAM_POWER_LOW    0
  46. #define SAM_POWER_NORMAL 1
  47. #define SAM_POWER_HIGH   2
  48. #define SAM_POWER_BEST   3
  49.  
  50.  
  51.  
  52. enum L_saminfo
  53. {
  54.  Float:L_SAMX,
  55.  Float:L_SAMY,
  56.  Float:L_SAMZ,
  57.  Float:L_SAMrX,
  58.  Float:L_SAMrY,
  59.  Float:L_SAMrZ,
  60.  Float:L_SAMDrawDistance,
  61.  Float:L_SAMRange,
  62.  L_SAMSpeed,
  63.  L_SAMPower,
  64.  bool:L_SAMFollow,
  65.  bool:L_SAMCreated,
  66.  L_SAMObjectID,
  67. }
  68.  
  69. new L_SAMData[MAX_LSAMS][L_saminfo];
  70. new L_CountSAMS = 0;
  71. new Float:L_SAMPlayerPos[MAX_PLAYERS][3];
  72. new PlayerMissile[MAX_PLAYERS];
  73. new bool:MissileInProgress[MAX_PLAYERS];
  74. new L_SAMMissileObject[MAX_OBJECTS];
  75. new L_SAMMissilePower[MAX_OBJECTS];
  76. new L_SAMMissileProgress[MAX_OBJECTS];
  77. new L_SAMMissileMarker[MAX_PLAYERS];
  78. new bool:L_SAM_ExceptionalPlayer[MAX_PLAYERS][MAX_LSAMS];
  79. #if defined USE_STREAMER
  80. 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)
  81. {
  82.  new Object_ID = CreateDynamicObject(modelid, X, Y, Z, rX, rY, rZ, vworld, interiorid, playerid, streamdistance);
  83.  Streamer_SetFloatData(STREAMER_TYPE_OBJECT, Object_ID, E_STREAMER_DRAW_DISTANCE, drawdistance);
  84.  return Object_ID;
  85. }
  86. #endif
  87.  
  88. 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)
  89. {
  90.  if(L_CountSAMS > MAX_LSAMS) return printf("• <L_SAM> Error : Couldn't create SAM, maximum SAMS have already been done!"), 0;
  91.  new samid = L_CountSAMS;
  92.  L_SAMData[samid][L_SAMX] = X;
  93.  L_SAMData[samid][L_SAMY] = Y;
  94.  L_SAMData[samid][L_SAMZ] = Z;
  95.  L_SAMData[samid][L_SAMrX] = rX;
  96.  L_SAMData[samid][L_SAMrY] = rY;
  97.  L_SAMData[samid][L_SAMrZ] = rZ;
  98.  L_SAMData[samid][L_SAMDrawDistance] = DrawDistance;
  99.  L_SAMData[samid][L_SAMRange] = Range;
  100.  L_SAMData[samid][L_SAMSpeed] = Speed;
  101.  if(Power >= SAM_POWER_BEST) L_SAMData[samid][L_SAMPower] = SAM_POWER_BEST;
  102.  else if(Power <= SAM_POWER_LOW) L_SAMData[samid][L_SAMPower] = SAM_POWER_LOW;
  103.  else L_SAMData[samid][L_SAMPower] = Power;
  104.  L_SAMData[samid][L_SAMFollow] = follow;
  105.  #if defined USE_STREAMER
  106.  L_SAMData[samid][L_SAMObjectID] = CreateStreamedObject(3267, X, Y, Z, rX, rY, rZ, -1, -1, -1, DrawDistance, DrawDistance);
  107.  #else
  108.  L_SAMData[samid][L_SAMObjectID] = CreateObject(3267, X, Y, Z, rX, rY, rZ, DrawDistance);
  109.  #endif
  110.  L_SAMData[samid][L_SAMCreated] = true;
  111.  L_CountSAMS++;
  112.  return samid;
  113. }
  114.  
  115. stock DestroySAM(samid)
  116. {
  117.   if(L_SAMData[samid][L_SAMCreated] == false) return 0;
  118.   L_SAMData[samid][L_SAMX] = 0.0;
  119.   L_SAMData[samid][L_SAMY] = 0.0;
  120.   L_SAMData[samid][L_SAMZ] = 0.0;
  121.   L_SAMData[samid][L_SAMrX] = 0.0;
  122.   L_SAMData[samid][L_SAMrY] = 0.0;
  123.   L_SAMData[samid][L_SAMrZ] = 0.0;
  124.   L_SAMData[samid][L_SAMDrawDistance] = 0.0;
  125.   L_SAMData[samid][L_SAMRange] = 0.0;
  126.   L_SAMData[samid][L_SAMSpeed] = 0;
  127.   L_SAMData[samid][L_SAMPower] = 0;
  128.   L_SAMData[samid][L_SAMFollow] = false;
  129.   L_SAMData[samid][L_SAMCreated] = false;
  130.   DestroyObject(L_SAMData[samid][L_SAMObjectID]);
  131.   L_SAMData[samid][L_SAMObjectID] = -1;
  132.   return 1;
  133. }
  134.  
  135. #if defined FILTERSCRIPT
  136.  
  137. public OnFilterScriptInit()
  138. {
  139.  for(new samid; samid< MAX_LSAMS; samid++)
  140.  {
  141.   L_SAMData[samid][L_SAMX] = 0.0;
  142.   L_SAMData[samid][L_SAMY] = 0.0;
  143.   L_SAMData[samid][L_SAMZ] = 0.0;
  144.   L_SAMData[samid][L_SAMrX] = 0.0;
  145.   L_SAMData[samid][L_SAMrY] = 0.0;
  146.   L_SAMData[samid][L_SAMrZ] = 0.0;
  147.   L_SAMData[samid][L_SAMDrawDistance] = 0.0;
  148.   L_SAMData[samid][L_SAMRange] = 0.0;
  149.   L_SAMData[samid][L_SAMSpeed] = 0;
  150.   L_SAMData[samid][L_SAMPower] = 0;
  151.   L_SAMData[samid][L_SAMFollow] = false;
  152.   L_SAMData[samid][L_SAMCreated] = false;
  153.   L_SAMData[samid][L_SAMObjectID] = -1;
  154.   for(new a; a< MAX_PLAYERS; a++) L_SAM_ExceptionalPlayer[a][samid] = false;
  155.  }
  156.  for(new i; i< MAX_OBJECTS; i++)
  157.  {
  158.   L_SAMMissileObject[i] = 0;
  159.   L_SAMMissilePower[i] = 0;
  160.   L_SAMMissileProgress[i] = -1;
  161.  }
  162.  for(new i; i< MAX_PLAYERS; i++)
  163.  {
  164.   MissileInProgress[i] = false;
  165.   L_SAMPlayerPos[i][0] = 0.0;
  166.   L_SAMPlayerPos[i][1] = 0.0;
  167.   L_SAMPlayerPos[i][2] = 0.0;
  168.   PlayerMissile[i] = -1;
  169.  }
  170.  L_CountSAMS = 0;
  171.  SetTimer("LordzSAMTimer", 2500, true);
  172.  CallLocalFunction("L_SAM_OnFS", "");
  173.  return 1;
  174. }
  175.  
  176. #if defined _ALS_OnFilterScriptInit
  177.  #undef OnFilterScriptInit
  178. #else
  179.  #define _ALS_OnFilterScriptInit
  180. #endif
  181.  
  182. public OnFilterScriptExit()
  183. {
  184.  #if !defined USE_STREAMER
  185.  for(new i; i< MAX_LSAMS; i++)
  186.  {
  187.   if(L_SAMData[i][L_SAMCreated])
  188.   {
  189.    DestroyObject(L_SAMData[i][L_SAMObjectID]);
  190.   }
  191.  }
  192.  #endif
  193.  for(new i; i< MAX_OBJECTS; i++)
  194.  {
  195.   if(L_SAMMissileProgress[i])
  196.   {
  197.    DestroyObject(i);
  198.   }
  199.  }
  200.  for(new i; i< MAX_PLAYERS; i++)
  201.  {
  202.   if(MissileInProgress[i]) RemovePlayerMapIcon(i, 99);
  203.  }
  204.  CallLocalFunction("L_SAM_OnFSExit", "");
  205.  return 1;
  206. }
  207.  
  208. #if defined _ALS_OnFilterScriptExit
  209.  #undef OnFilterScriptExit
  210. #else
  211.  #define _ALS_OnFilterScriptExit
  212. #endif
  213.  
  214. forward L_SAM_OnFS();
  215. forward L_SAM_OnFSExit();
  216.  
  217. #else
  218.  
  219. public OnGameModeInit()
  220. {
  221.  for(new samid; samid< MAX_LSAMS; samid++)
  222.  {
  223.   L_SAMData[samid][L_SAMX] = 0.0;
  224.   L_SAMData[samid][L_SAMY] = 0.0;
  225.   L_SAMData[samid][L_SAMZ] = 0.0;
  226.   L_SAMData[samid][L_SAMrX] = 0.0;
  227.   L_SAMData[samid][L_SAMrY] = 0.0;
  228.   L_SAMData[samid][L_SAMrZ] = 0.0;
  229.   L_SAMData[samid][L_SAMDrawDistance] = 0.0;
  230.   L_SAMData[samid][L_SAMRange] = 0.0;
  231.   L_SAMData[samid][L_SAMSpeed] = 0;
  232.   L_SAMData[samid][L_SAMPower] = 0;
  233.   L_SAMData[samid][L_SAMFollow] = false;
  234.   L_SAMData[samid][L_SAMCreated] = false;
  235.   L_SAMData[samid][L_SAMObjectID] = -1;
  236.   for(new a; a< MAX_PLAYERS; a++) L_SAM_ExceptionalPlayer[a][samid] = false;
  237.  }
  238.  for(new i; i< MAX_OBJECTS; i++)
  239.  {
  240.   L_SAMMissileObject[i] = 0;
  241.   L_SAMMissilePower[i] = 0;
  242.   L_SAMMissileProgress[i] = -1;
  243.  }
  244.  for(new i; i< MAX_PLAYERS; i++)
  245.  {
  246.   MissileInProgress[i] = false;
  247.   L_SAMPlayerPos[i][0] = 0.0;
  248.   L_SAMPlayerPos[i][1] = 0.0;
  249.   L_SAMPlayerPos[i][2] = 0.0;
  250.   PlayerMissile[i] = -1;
  251.  }
  252.  L_CountSAMS = 0;
  253.  SetTimer("LordzSAMTimer", 2500, true);
  254.  CallLocalFunction("L_SAM_OnGM", "");
  255.  return 1;
  256. }
  257.  
  258. #if defined _ALS_OnGameModeInit
  259.  #undef OnGameModeInit
  260. #else
  261.  #define _ALS_OnGameModeInit
  262. #endif
  263.  
  264. forward L_SAM_OnGM();
  265. public OnGameModeExit()
  266. {
  267.  #if !defined USE_STREAMER
  268.  for(new i; i< MAX_LSAMS; i++)
  269.  {
  270.   if(L_SAMData[i][L_SAMCreated])
  271.   {
  272.    DestroyObject(L_SAMData[i][L_SAMObjectID]);
  273.   }
  274.  }
  275.  #endif
  276.  for(new i; i< MAX_OBJECTS; i++)
  277.  {
  278.   if(L_SAMMissileProgress[i])
  279.   {
  280.    DestroyObject(i);
  281.   }
  282.  }
  283.  for(new i; i< MAX_PLAYERS; i++)
  284.  {
  285.   if(MissileInProgress[i]) RemovePlayerMapIcon(i, 99);
  286.  }
  287.  CallLocalFunction("L_SAM_OnGMExit", "");
  288.  return 1;
  289. }
  290.  
  291. #if defined _ALS_OnGameModeExit
  292.  #undef OnGameModeExit
  293. #else
  294.  #define _ALS_OnGameModeExit
  295. #endif
  296. forward L_SAM_OnGMExit();
  297. #endif
  298.  
  299. forward LordzSAMTimer();
  300.  
  301. stock AvoidSAMAttacksOnPlayer(playerid, samid)
  302. {
  303.  if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  304.  L_SAM_ExceptionalPlayer[playerid][samid] = 1;
  305.  return 1;
  306. }
  307.  
  308. stock EnableSAMAttacksOnPlayer(playerid, samid)
  309. {
  310.  if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  311.  L_SAM_ExceptionalPlayer[playerid][samid] = 0;
  312.  return 1;
  313. }
  314.  
  315. stock ToggleNoSAMAttacksOnPlayer(playerid, samid, bool:noattack)
  316. {
  317.  if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  318.  L_SAM_ExceptionalPlayer[playerid][samid] = noattack;
  319.  return 1;
  320. }
  321.  
  322. stock SetSAMMissileSpeed(samid, speed)
  323. {
  324.  if(L_SAMData[samid][L_SAMCreated] == false) return 0;
  325.  L_SAMData[samid][L_SAMSpeed] = speed;
  326.  return 1;
  327. }
  328.  
  329. stock GetSAMMissileSpeed(samid)
  330. {
  331.   if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  332.   return L_SAMData[samid][L_SAMSpeed];
  333. }
  334.  
  335. stock SetSAMMissilePower(samid, Power)
  336. {
  337.  if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  338.  if(Power >= SAM_POWER_BEST) L_SAMData[samid][L_SAMPower] = SAM_POWER_BEST;
  339.  else if(Power <= SAM_POWER_LOW) L_SAMData[samid][L_SAMPower] = SAM_POWER_LOW;
  340.  else L_SAMData[samid][L_SAMPower] = Power;
  341.  return Power;
  342. }
  343.  
  344. stock GetSAMMissilePower(samid)
  345. {
  346.  if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  347.  return L_SAMData[samid][L_SAMPower];
  348. }
  349.  
  350. stock GetSAMObjectID(samid)
  351. {
  352.  if(L_SAMData[samid][L_SAMCreated] == false) return -1;
  353.  return L_SAMData[samid][L_SAMObjectID];
  354. }
  355.  
  356.  
  357. public LordzSAMTimer()
  358. {
  359.  for(new i; i< MAX_LSAMS; i++)
  360.  {
  361.   if(L_SAMData[i][L_SAMCreated])
  362.   {
  363.    for(new a; a< GetMaxPlayers(); a++)
  364.    {
  365.     if(!IsPlayerConnected(a)) continue;
  366.     if(!IsPlayerInRangeOfPoint(a, L_SAMData[i][L_SAMRange], L_SAMData[i][L_SAMX], L_SAMData[i][L_SAMY], L_SAMData[i][L_SAMZ])) continue;
  367.     if(L_SAM_ExceptionalPlayer[a][i] == true) continue;
  368.     if(MissileInProgress[a] == true) continue;
  369.     GetPlayerPos(a, L_SAMPlayerPos[a][0], L_SAMPlayerPos[a][1], L_SAMPlayerPos[a][2]);
  370.     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);
  371.     PlayerMissile[a] = p_missileobj;
  372.     L_SAMMissileObject[p_missileobj] = 1;
  373.     L_SAMMissilePower[p_missileobj] = L_SAMData[i][L_SAMPower];
  374.     L_SAMMissileProgress[p_missileobj] = a;
  375.     MoveObject(p_missileobj, L_SAMPlayerPos[a][0], L_SAMPlayerPos[a][1], L_SAMPlayerPos[a][2], L_SAMData[i][L_SAMSpeed]);
  376.     MissileInProgress[a] = true;
  377.     SetPlayerMapIcon(a, 99, L_SAMData[i][L_SAMX], L_SAMData[i][L_SAMY], L_SAMData[i][L_SAMZ], 0, 0xFF0000FF);
  378.     L_SAMMissileMarker[a] = SetTimerEx("L_SAMUpdateMapIcon", 250, true, "i", a);
  379.    }
  380.   }
  381.  }
  382.  return 1;
  383. }
  384.  
  385.  
  386. forward L_SAMUpdateMapIcon(playerid);
  387. public L_SAMUpdateMapIcon(playerid)
  388. {
  389.  if(!MissileInProgress[playerid]) return KillTimer(L_SAMMissileMarker[playerid]);
  390.  new Float:X, Float:Y, Float:Z;
  391.  GetObjectPos(PlayerMissile[playerid], X, Y, Z);
  392.  SetPlayerMapIcon(playerid, 99, X, Y, Z, 0, 0xFF0000FF);
  393.  return 1;
  394. }
  395.  
  396. public OnObjectMoved(objectid)
  397. {
  398.  if(L_SAMMissileObject[objectid] == 1)
  399.  {
  400.   new Float:X, Float:Y, Float:Z;
  401.   GetObjectPos(objectid, X, Y, Z);
  402.   switch(L_SAMMissilePower[objectid])
  403.   {
  404.    case 0: CreateExplosion(X+4.0, Y+4.0, Z, 1, 10.0);
  405.    case 1: CreateExplosion(X+4.0, Y+4.0, Z, 7, 10.0);
  406.    case 2:
  407.    {
  408.       CreateExplosion(X+8.0,Y, Z, 7, 10.0);
  409.       CreateExplosion(X-8.0,Y, Z, 7, 10.0);
  410.       CreateExplosion(X, Y+8.0,Z, 7, 10.0);
  411.       CreateExplosion(X, Y-8.0,Z, 7, 10.0);
  412.    }
  413.    case 3:
  414.    {
  415.       new Float:range = 8.0;
  416.       CreateExplosion(X+range,Y, Z, 6, 10.0);
  417.       CreateExplosion(X-range,Y, Z, 6, 10.0);
  418.       CreateExplosion(X, Y+range,Z, 6, 10.0);
  419.       CreateExplosion(X, Y-range,Z, 6, 10.0);
  420.       CreateExplosion(X+range,Y+range,Z, 6, 10.0);
  421.       CreateExplosion(X-range,Y+range,Z, 6, 10.0);
  422.       CreateExplosion(X-range,Y-range,Z, 6, 10.0);
  423.    }
  424.   }
  425.   DestroyObject(objectid);
  426.   RemovePlayerMapIcon(L_SAMMissileProgress[objectid], 99);
  427.   L_SAMMissileObject[objectid] = 0;
  428.   L_SAMMissilePower[objectid] = 0;
  429.   MissileInProgress[L_SAMMissileProgress[objectid]] = false;
  430.   L_SAMMissileProgress[objectid] = -1;
  431.  }
  432.  CallLocalFunction("L_SAM_OnObjMoved", "i", objectid);
  433.  return 1;
  434. }
  435.  
  436. #if defined _ALS_OnObjectMoved
  437.  #undef OnObjectMoved
  438. #else
  439.  #define _ALS_OnObjectMoved
  440. #endif
  441.  
  442. forward L_SAM_OnObjMoved(objectid);
  443.  
  444. public OnPlayerConnect(playerid)
  445. {
  446.  for(new i; i< MAX_LSAMS; i++) L_SAM_ExceptionalPlayer[playerid][i] = false;
  447.  CallLocalFunction("L_SAM_OPC", "i", playerid);
  448.  return 1;
  449. }
  450.  
  451. #if defined _ALS_OnPlayerConnect
  452.  #undef OnPlayerConnect
  453. #else
  454.  #define _ALS_OnPlayerConnect
  455. #endif
  456.  
  457. forward L_SAM_OPC(playerid);
  458.  
  459. #define OnObjectMoved L_SAM_OnObjMoved
  460. #if defined FILTERSCRIPT
  461. #define OnFilterScriptInit L_SAM_OnFS
  462. #define OnFilterScriptExit L_SAM_OnFSExit
  463. #else
  464. #define OnGameModeInit L_SAM_OnGM
  465. #define OnGameModeExit L_SAM_OnGMExit
  466. #endif
  467. #define OnPlayerConnect L_SAM_OPC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement