Advertisement
Guest User

Untitled

a guest
Mar 19th, 2012
568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.71 KB | None | 0 0
  1. /*
  2.  
  3.     TJs Anti Air Filterscript
  4.     Author: TJ (TTJJ SA:MP forums)
  5.     Credits: TJ, LucifeR (SetObjectToFaceCords functionality)
  6.  
  7. */
  8. #include <a_samp>
  9.  
  10. #define MAX_MISSLES 400//The maximum number of missles that can be created at any one time
  11. #define MISSLE_INTERVAL 200//The timers interval, increasing this will reduce the number of missles fired
  12. #define MISSLE_SPEED 215.0//The speed of the missles, increase this to make the missles go faster and the avoidance of them harder
  13. #define BLAST_RADIUS 30.0//The blast radius for the explosion caused by the missles
  14.  
  15. forward antiair();
  16.  
  17. new anti_air_timer;
  18. new missles[MAX_MISSLES];
  19.  
  20. new Float:anti_air_origins[4][4] = {//The anti-air positions. More can be defined by adding coords to this list, Syntax: X, Y, Z, Range
  21.  
  22.     {15.6185,1721.6699,23.8750,450.0},
  23.     {237.4360,1698.6774,23.8673,450.0},
  24.     {353.6885,2031.6732,22.6406,450.0},
  25.     {187.3830,2084.9536,22.6468,450.0}
  26.  
  27. };
  28.  
  29. public OnFilterScriptInit()
  30. {
  31.     print("\n--------------------------------------");
  32.     print(" TJs Anti-Air Filterscript v1.0");
  33.     print("--------------------------------------\n");
  34.     anti_air_timer = SetTimer("antiair",MISSLE_INTERVAL,1);
  35.     ResetMissles();
  36.     return 1;
  37. }
  38.  
  39. public OnFilterScriptExit()
  40. {
  41.     KillTimer(anti_air_timer);
  42.     return 1;
  43. }
  44.  
  45. public antiair()
  46. {
  47.  
  48.     for(new i = 0; i < MAX_PLAYERS; i ++)
  49.     {
  50.    
  51.         if(IsPlayerConnected(i))
  52.         {
  53.        
  54.             for(new a = 0; a < sizeof(anti_air_origins); a ++)
  55.             {
  56.            
  57.                 if(IsPlayerInRangeOfPoint(i,anti_air_origins[a][3],anti_air_origins[a][0],anti_air_origins[a][1],anti_air_origins[a][2]))
  58.                 {
  59.                
  60.                     if(IsInAircraft(i))
  61.                     {
  62.                    
  63.                         new slot = FetchNextMissleSlot();
  64.                         if(slot > -1)
  65.                         {
  66.                        
  67.                             new Float:X, Float:Y, Float:Z;
  68.                             GetPlayerPos(i,X,Y,Z);
  69.                             missles[slot] = CreateObject(345,anti_air_origins[a][0],anti_air_origins[a][1],anti_air_origins[a][2],0.0,0.0,0.0);
  70.                             SetObjectToFaceCords(missles[slot], X, Y, Z);
  71.                             MoveObject(missles[slot],X,Y,Z,MISSLE_SPEED);
  72.                        
  73.                         }
  74.                    
  75.                     }
  76.                
  77.                 }
  78.            
  79.             }
  80.        
  81.         }
  82.    
  83.     }
  84.  
  85. }
  86.  
  87. public OnObjectMoved(objectid)
  88. {
  89.  
  90.     new slot = FetchMissleSlot(objectid);
  91.     if(slot > -1)
  92.     {
  93.    
  94.         new Float:X, Float:Y, Float:Z;
  95.         GetObjectPos(objectid,X,Y,Z);
  96.         CreateExplosion(X,Y,Z,2,BLAST_RADIUS);
  97.         DestroyObject(objectid);
  98.         missles[slot] = -1;
  99.    
  100.     }
  101.  
  102. }
  103.  
  104. stock FetchMissleSlot(objectid)
  105. {
  106.  
  107.     for(new i = 0; i < MAX_MISSLES; i ++)
  108.     {
  109.    
  110.         if(missles[i] == objectid) return i;
  111.    
  112.     }
  113.     return -1;
  114.  
  115. }
  116.  
  117. stock IsInAircraft(playerid)
  118. {
  119.  
  120.     if(!IsPlayerInAnyVehicle(playerid)) return false;
  121.     new vehicleid = GetPlayerVehicleID(playerid);
  122.     switch(GetVehicleModel(vehicleid))
  123.     {
  124.    
  125.         case
  126.             460,464,476,511,512,513,519,520,553,577,592,593,
  127.             417,425,447,465,469,487,488,497,501,548,563:
  128.         return true;
  129.        
  130.     }
  131.     return false;
  132. }
  133.  
  134. stock ResetMissles()
  135. {
  136.  
  137.     for(new i = 0; i < MAX_MISSLES; i ++) missles[i] = -1;
  138.  
  139. }
  140.  
  141. stock FetchNextMissleSlot()
  142. {
  143.  
  144.     for(new i = 0; i < MAX_MISSLES; i ++)
  145.     {
  146.    
  147.         if(missles[i] == -1) return i;
  148.    
  149.     }
  150.     return -1;
  151.  
  152. }
  153.  
  154. stock SetObjectToFaceCords(objectid, Float:x1, Float:y1, Float:z1)
  155. {
  156.  
  157.     //   SetObjectToFaceCords() By LucifeR   //
  158.  
  159.     new Float:x2,Float:y2,Float:z2;
  160.     GetObjectPos(objectid, x2,y2,z2);
  161.  
  162.     new Float:DX = floatabs(x2-x1);
  163.     new Float:DY = floatabs(y2-y1);
  164.     new Float:DZ = floatabs(z2-z1);
  165.  
  166.     new Float:yaw = 0;
  167.     new Float:pitch = 0;
  168.  
  169.     if(DY == 0 || DX == 0)
  170.     {
  171.    
  172.         if(DY == 0 && DX > 0)
  173.         {
  174.             yaw = 00;
  175.             pitch = 0;
  176.         }
  177.         else if(DY == 0 && DX < 0)
  178.         {
  179.  
  180.             yaw = 180;
  181.             pitch = 180;
  182.  
  183.         }
  184.         else if(DY > 0 && DX == 0)
  185.         {
  186.  
  187.             yaw = 90;
  188.             pitch = 90;
  189.  
  190.         }
  191.         else if(DY < 0 && DX == 0)
  192.         {
  193.             yaw = 270;
  194.             pitch = 270;
  195.  
  196.         }
  197.         else if(DY == 0 && DX == 0)
  198.         {
  199.             yaw = 0;
  200.             pitch = 0;
  201.         }
  202.        
  203.     }
  204.     else
  205.     {
  206.         yaw = atan(DX/DY);
  207.         pitch = atan(floatsqroot(DX*DX + DZ*DZ) / DY);
  208.         if(x1 > x2 && y1 <= y2)
  209.         {
  210.        
  211.             yaw = yaw + 90;
  212.             pitch = pitch - 45;
  213.            
  214.         }
  215.         else if(x1 <= x2 && y1 < y2)
  216.         {
  217.        
  218.             yaw = 90 - yaw;
  219.             pitch = pitch - 45;
  220.  
  221.         }
  222.         else if(x1 < x2 && y1 >= y2)
  223.         {
  224.        
  225.             yaw = yaw - 90;
  226.             pitch = pitch - 45;
  227.            
  228.         }
  229.         else if(x1 >= x2 && y1 > y2)
  230.         {
  231.        
  232.             yaw = 270 - yaw;
  233.             pitch = pitch + 315;
  234.            
  235.         }
  236.         if(z1 < z2)
  237.         {
  238.        
  239.             pitch = 360-pitch;
  240.            
  241.         }
  242.         SetObjectRot(objectid, 0, 0, yaw);
  243.         SetObjectRot(objectid, 0, pitch, yaw+90);
  244.  
  245.     }
  246.        
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement