Advertisement
Guest User

Untitled

a guest
May 29th, 2011
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 9.80 KB | None | 0 0
  1. /*
  2. *       SA:MP Surface To Air Missiles (SAMsites)
  3. *       Version: 0.4
  4. *       (c) Copyright 2010 - 2011 by Awaran
  5. *       @date Jan 18 2010
  6. *       @re-distributed July 18 2010
  7. *       @pastebin entry May 30 2011
  8. *       @webaddress http://forum.sa-mp.com/showthread.php?t=115695
  9. *
  10. * Do not re-distribute. File is given 'AS IS' (no warranties)
  11. *
  12. * Always pay credits to authors
  13. *
  14. *
  15.  
  16.         The purpose of this include is to allow functionality of Surface
  17.         To Air Missile launchers(SAMS) in San Andreas Multiplayer 0.3a.
  18.         There is no saying that this current version(0.4) will work in
  19.         future releases of San Andreas Multiplayer, however, future updates
  20.         are a possibility. The said update '0.5 HARDCORE EDITION' has too
  21.         many bugs to even allow connectivity to any server, the resourses
  22.         the script needs is too great. There is no debug content in this
  23.         release, nor will I release any such script that does contain
  24.         any debug content.
  25. */
  26.  
  27. /*Configuration*/
  28. #define MAX_SAMS 64
  29. #define INVALID_SAM_ID 255
  30. #define DEFAULT_MISSILE_SPEED 70
  31. #define DEFAULT_SAM_RANGE 300
  32. #define MISSILE_DRAG_TIME 25000 //milliseconds
  33. #define SAM_RADAR_LIMIT 15.000
  34.  
  35. new sOBJECT[MAX_SAMS];
  36. new resttime;
  37. new samset;
  38.  
  39. enum SamS
  40. {
  41.     samida,
  42.     Float:SX,
  43.     Float:SY,
  44.     Float:SZ,
  45.     Float:speed,
  46.     Float:range,
  47.     chaseid,
  48.     Fired,
  49.     Ex,
  50.     cancel,                    
  51. };
  52.  
  53. new Sam[MAX_SAMS][SamS];
  54. new Missile[MAX_SAMS];
  55. new FireMissileKill[MAX_SAMS];
  56. new FireMissileKill2[MAX_SAMS];
  57. new DragKill[MAX_SAMS];
  58. new Text3D:SamLabel[MAX_SAMS];
  59. forward OnSamSiteUpdate(samid, playerid);
  60.  
  61. /* natives
  62. native AddStaticSAM(Float:X, Float:Y, Float:Z);
  63. native AddStaticSAMEx(Float:X, Float:Y, Float:Z, srange, sspeed);
  64. native CreateSAM(Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ);
  65. native CreateSAMEx(Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, srange, sspeed);
  66. native CreateSamLabel(samid, label[], color, Float:DrawDistance, LOS);
  67. native SAM_start();
  68. native SAM_cancel(samid);
  69. */
  70.  
  71. stock AddStaticSAM(Float:X, Float:Y, Float:Z)
  72. {
  73.     new samid = samset;
  74.     if(samset > MAX_SAMS-1)
  75.     {
  76.         print("[SAM] Error - Script exceeds max limit");
  77.         samid = INVALID_SAM_ID;
  78.         return samid;
  79.     }
  80.     samset++;
  81.     Sam[samid][samida] = samid;
  82.     Sam[samid][SX] = X;
  83.     Sam[samid][SY] = Y;
  84.     Sam[samid][SZ] = Z;
  85.     Sam[samid][speed] = DEFAULT_MISSILE_SPEED;
  86.     Sam[samid][range] = DEFAULT_SAM_RANGE;
  87.     Sam[samid][chaseid] = -1;
  88.     Sam[samid][Fired] = 0;
  89.     Sam[samid][Ex] = 0;
  90.     printf("[SAM] SAM %d Created - %f,%f,%f -",samid,X,Y,Z);
  91.     return samid;
  92. }
  93.  
  94. stock AddStaticSAMEx(Float:X, Float:Y, Float:Z, Float:srange, Float:sspeed)
  95. {
  96.     new samid = samset;
  97.     if(samset > MAX_SAMS-1)
  98.     {
  99.         print("[SAM] Error - Script exceeds max limit");
  100.         samid = INVALID_SAM_ID;
  101.         return samid;
  102.     }
  103.     samset++;
  104.     Sam[samid][samida] = samid;
  105.     Sam[samid][SX] = X;
  106.     Sam[samid][SY] = Y;
  107.     Sam[samid][SZ] = Z;
  108.     Sam[samid][speed] = sspeed;
  109.     Sam[samid][range] = srange;
  110.     Sam[samid][chaseid] = -1;
  111.     Sam[samid][Fired] = 0;
  112.     Sam[samid][Ex] = 1;
  113.     printf("[SAM] SAM %d Created - %f,%f,%f -",samid,X,Y,Z);
  114.     return samid;
  115. }
  116.  
  117. stock CreateSAM(Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ)
  118. {
  119.     new samid = samset;
  120.     if(samset > MAX_SAMS-1)
  121.     {
  122.         print("[SAM] Error - Script exceeds max limit");
  123.         samid = INVALID_SAM_ID;
  124.         return samid;
  125.     }
  126.     samset++;
  127.     Sam[samid][samida] = samid;
  128.     Sam[samid][SX] = X;
  129.     Sam[samid][SY] = Y;
  130.     Sam[samid][SZ] = Z;
  131.     Sam[samid][speed] = DEFAULT_MISSILE_SPEED;
  132.     Sam[samid][range] = DEFAULT_SAM_RANGE;
  133.     Sam[samid][chaseid] = -1;
  134.     Sam[samid][Fired] = 0;
  135.     sOBJECT[samid] = CreateObject(3884,X,Y,X,rX,rY,rZ);
  136.     Sam[samid][Ex] = 0;
  137.     printf("[SAM] SAM %d Created - %f,%f,%f -",samid,X,Y,Z);
  138.     return samid;
  139. }
  140.  
  141. stock CreateSAMEx(Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:srange, Float:sspeed)
  142. {
  143.     new samid = samset;
  144.     if(samset > MAX_SAMS-1)
  145.     {
  146.         print("[SAM] Error - Script exceeds max limit");
  147.         samid = INVALID_SAM_ID;
  148.         return samid;
  149.     }
  150.     samset++;
  151.     Sam[samid][samida] = samid;
  152.     Sam[samid][SX] = X;
  153.     Sam[samid][SY] = Y;
  154.     Sam[samid][SZ] = Z;
  155.     Sam[samid][speed] = sspeed;
  156.     Sam[samid][range] = srange;
  157.     Sam[samid][chaseid] = -1;
  158.     Sam[samid][Fired] = 0;
  159.     sOBJECT[samid] = CreateObject(3884,X,Y,X,rX,rY,rZ);
  160.     Sam[samid][Ex] = 1;
  161.     printf("[SAM] SAM %d Created - %f,%f,%f -",samid,X,Y,Z);
  162.     return samid;
  163. }
  164.  
  165. stock SAM_cancel(samid)
  166. {
  167.     Sam[samid][cancel] = 1;
  168. }
  169.  
  170. stock SAM_start()
  171. {
  172.     resttime = SetTimer("SamLive",500,true);
  173.     SetTimer("Restart",1800000,false);
  174.     print("\n--------------------------------------");
  175.     print(" Surface To Air Missiles System Loaded");
  176.     print("                 0.4");
  177.     print("--------------------------------------\n");
  178.     return 1;
  179. }
  180.  
  181. stock CreateSamLabel(samid, label[], color, Float:DrawDistance, LOS)
  182. {
  183.     if(samid == INVALID_SAM_ID) return false;
  184.     new string[128];
  185.     format(string,sizeof(string),"%s(%d)",label,samid);
  186.     SamLabel[samid] = Create3DTextLabel(string,color,Sam[samid][SX],Sam[samid][SY],Sam[samid][SZ] + 2.00,DrawDistance,0,LOS);
  187.     return true;
  188. }
  189.  
  190. stock GetMaxSams()
  191. {
  192.     return samset;
  193. }
  194.  
  195. forward SamLive();
  196. public SamLive()
  197. {
  198.     for(new s = 0; s <GetMaxSams(); s++)
  199.     {
  200.         if(s != INVALID_SAM_ID)
  201.         {
  202.             SamConfig(s);
  203.         }
  204.     }
  205. }
  206.  
  207. forward SamConfig(samid);
  208. public SamConfig(samid)
  209. {
  210.     for(new i = 0; i <MAX_PLAYERS; i++)
  211.     {
  212.         if(IsPlayerConnected(i))
  213.         {
  214.             if(Sam[samid][Fired] == 0)
  215.             {
  216.                 if(IsPlayerInAnyVehicle(i))
  217.                 {
  218.                     new veh = GetPlayerVehicleID(i);
  219.                     if(IsAirVehicle(veh))
  220.                     {
  221.                         if(Sam[samid][Ex] == 1)
  222.                         {
  223.                             if(IsVehicleInRangeOfPoint(veh,Sam[samid][range],Sam[samid][SX],Sam[samid][SY],Sam[samid][SZ]))
  224.                             {
  225.                                 OnSamSiteUpdate(samid, i);
  226.                                 if(Sam[samid][cancel] == 1)
  227.                                 {
  228.                                     Sam[samid][cancel] = 0;
  229.                                     return 1;
  230.                                 }
  231.                                 Missile[samid] = CreateObject(354,Sam[samid][SX],Sam[samid][SY],Sam[samid][SZ],0,0,0);
  232.                                 Sam[samid][Fired] = 1;
  233.                                 Sam[samid][chaseid] = veh;
  234.                                 FireSam(samid,i,veh);
  235.                             }
  236.                         }
  237.                         else
  238.                         {
  239.                             if(IsVehicleInRangeOfPoint(veh,DEFAULT_SAM_RANGE,Sam[samid][SX],Sam[samid][SY],Sam[samid][SZ]))
  240.                             {
  241.                                 OnSamSiteUpdate(samid, i);
  242.                                 if(Sam[samid][cancel] == 1)
  243.                                 {
  244.                                     Sam[samid][cancel] = 0;
  245.                                     return 1;
  246.                                 }
  247.                                 Missile[samid] = CreateObject(354,Sam[samid][SX],Sam[samid][SY],Sam[samid][SZ],0,0,0);
  248.                                 Sam[samid][Fired] = 1;
  249.                                 Sam[samid][chaseid] = veh;
  250.                                 FireSam(samid,i,veh);
  251.                             }
  252.                         }
  253.                     }
  254.                 }
  255.             }
  256.         }
  257.     }
  258.     return 1;
  259. }
  260.  
  261. forward FireSam(samid, playerid, vehicleid);
  262. public FireSam(samid, playerid, vehicleid)
  263. {
  264.     if(Sam[samid][chaseid] != vehicleid) return 1;
  265.     FireMissileKill[samid] = SetTimerEx("Fire",500,true,"iii",playerid, samid, vehicleid);
  266.     FireMissileKill2[samid] = SetTimerEx("Destroy",300,true,"iii",playerid,samid,vehicleid);
  267.     DragKill[samid] = SetTimerEx("Drag",MISSILE_DRAG_TIME,false,"i",samid);
  268.     return 1;
  269. }
  270.  
  271. forward Fire(playerid, samid, vehicleid);
  272. public Fire(playerid, samid, vehicleid)
  273. {
  274.     if(!IsPlayerConnected(playerid))
  275.     {
  276.         KillTimer(FireMissileKill[samid]);
  277.         KillTimer(FireMissileKill2[samid]);
  278.         KillTimer(DragKill[samid]);
  279.         Drag(samid);
  280.         return 1;
  281.     }
  282.     if(vehicleid == Sam[samid][chaseid])
  283.     {
  284.         new Float:X,
  285.             Float:Y,
  286.             Float:Z;
  287.         GetVehiclePos(vehicleid,X,Y,Z);
  288.         if(Sam[samid][Ex] == 1)
  289.         {
  290.             StopObject(Missile[samid]);
  291.             MoveObject(Missile[samid],X,Y,Z,Sam[samid][speed]);
  292.         }
  293.         else
  294.         {
  295.             StopObject(Missile[samid]);
  296.             MoveObject(Missile[samid],X,Y,Z,DEFAULT_MISSILE_SPEED);
  297.         }
  298.     }
  299.     return 1;
  300. }
  301.  
  302. forward Destroy(playerid, samid, vehicleid);
  303. public Destroy(playerid, samid, vehicleid)
  304. {
  305.     new Float:OX,
  306.         Float:OY,
  307.         Float:OZ;
  308.     GetObjectPos(Missile[samid],OX,OY,OZ);
  309.     if(IsVehicleInRangeOfPoint(vehicleid,3,OX,OY,OZ))
  310.     {
  311.         CreateExplosion(OX,OY,OZ,2,10);
  312.         CreateExplosion(OX,OY,OZ,2,10);
  313.         CreateExplosion(OX,OY,OZ,2,10);
  314.         KillTimer(FireMissileKill[samid]);
  315.         KillTimer(FireMissileKill2[samid]);
  316.         DecreaseVehicleHealth(vehicleid, 50.0);
  317.         KillTimer(DragKill[samid]);
  318.         SetTimerEx("FireSet",5000,false,"i",samid);
  319.         DestroyObject(Missile[samid]);
  320.     }
  321.     return 1;
  322. }
  323.  
  324. forward FireSet(samid);
  325. public FireSet(samid)
  326. {
  327.     Sam[samid][Fired] = 0;
  328. }
  329.  
  330. forward Drag(samid);
  331. public Drag(samid)
  332. {
  333.     new Float:OX,
  334.         Float:OY,
  335.         Float:OZ;
  336.     GetObjectPos(Missile[samid],OX,OY,OZ);
  337.     CreateExplosion(OX,OY,OZ,2,2.00);
  338.     CreateExplosion(OX,OY,OZ,2,2.00);
  339.     CreateExplosion(OX,OY,OZ,2,2.00);
  340.     Sam[samid][Fired] = 0;
  341.     DestroyObject(Missile[samid]);
  342. }
  343.  
  344. forward Restart();
  345. public Restart()
  346. {
  347.     KillTimer(resttime);
  348.     SAM_start();
  349. }
  350.  
  351. stock IsAirVehicle(carid)
  352. {
  353.     new AirVeh[] = { 592, 577, 511, 512, 593, 520, 553, 476, 519, 460, 513, 548, 425, 417, 487, 488, 497, 563, 447, 469 };
  354.     for(new i = 0; i < sizeof(AirVeh); i++)
  355.     {
  356.         if(GetVehicleModel(carid) == AirVeh[i]) return 1;
  357.     }
  358.     return 0;
  359. }
  360.  
  361. stock DecreaseVehicleHealth(vehicleid, Float:decreaseby)
  362. {
  363.     new Float:voldhp;
  364.     GetVehicleHealth(vehicleid, voldhp);
  365.     return SetVehicleHealth(vehicleid,voldhp - decreaseby);
  366. }
  367.  
  368. IsVehicleInRangeOfPoint(vehicleid, Float:vrange, Float:x, Float:y, Float:z)
  369. {
  370.     new Float:oldpos[3],
  371.         Float:temppos[3];
  372.     GetVehiclePos(vehicleid, oldpos[0], oldpos[1], oldpos[2]);
  373.     temppos[0] = (oldpos[0] -x);
  374.     temppos[1] = (oldpos[1] -y);
  375.     temppos[2] = (oldpos[2] -z);
  376.     if(((temppos[0] < vrange) && (temppos[0] > -vrange)) && ((temppos[1] < vrange) && (temppos[1] > -vrange)) && ((temppos[2] < vrange) && (temppos[2] > -vrange)))
  377.     {
  378.         return true;
  379.     }
  380.     return false;
  381. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement