SAMsites0.4.1.inc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * SA:MP Surface To Air Missiles (SAMsites)
  3. * Version: 0.4.1
  4. * Patch: 0.1
  5. * (c) Copyright 2011 - 2012 by BockScar (pagie1111)
  6. * @date Jan 18 2010
  7. * @re-distributed May 31 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. The purpose of this include is to allow functionality of Surface
  16. To Air Missile launchers(SAMS) in San Andreas Multiplayer 0.3a.
  17. There is no saying that this current version(0.4.1) will work in
  18. future releases of San Andreas Multiplayer, however, future updates
  19. are a possibility. The current release of this system has an added
  20. attempt to kill the 'Dead Sam Bug'. Information about this bug can be
  21. found on the forum main post or at the bottom of this script.
  22. */
  23. /*Configuration*/
  24. #define MAX_SAMS 64
  25. #define INVALID_SAM_ID 255
  26. #define DEFAULT_MISSILE_SPEED 70.000
  27. #define DEFAULT_SAM_RANGE 300.000
  28. #define MISSILE_DRAG_TIME 25000 //milliseconds
  29. #define SAM_RADAR_LIMIT 15.000
  30. #define RESTART_TIME 1800000 // 30 minutes
  31. #define RELOAD_STRING "reloadfs SamSites041"
  32. new sOBJECT[MAX_SAMS];
  33. new resttime;
  34. new samset;
  35. enum SamS
  36. {
  37. samida,
  38. Float:SX,
  39. Float:SY,
  40. Float:SZ,
  41. Float:speed,
  42. Float:range,
  43. chaseid,
  44. Fired,
  45. };
  46. new Sam[MAX_SAMS][SamS];
  47. new Missile[MAX_SAMS];
  48. new FireMissileKill[MAX_SAMS];
  49. new FireMissileKill2[MAX_SAMS];
  50. new DragKill[MAX_SAMS];
  51. new Text3D:SamLabel[MAX_SAMS];
  52. forward OnSamSiteUpdate(samid, playerid);
  53. /* natives
  54. native AddStaticSAM(Float:X, Float:Y, Float:Z, Float:srange=DEFAULT_SAM_RANGE, Float:sspeed=DEFAULT_SAM_SPEED, CSO=false, Float:rX, Float:rY, Float:zZ);
  55. native CreateSamLabel(samid, label[], color, Float:DrawDistance, LOS);
  56. native SAM_start();
  57. */
  58. stock AddStaticSAM(Float:X, Float:Y, Float:Z, Float:srange=DEFAULT_SAM_RANGE, Float:sspeed=DEFAULT_MISSILE_SPEED, bool:CSO=false,Float:rX=0.0, Float:rY=0.0, Float:rZ=0.0)
  59. {
  60. new samid = samset;
  61. if(samset > MAX_SAMS-1)
  62. {
  63. print("[SAM] Error - Script exceeds max limit");
  64. samid = INVALID_SAM_ID;
  65. return samid;
  66. }
  67. samset++;
  68. Sam[samid][samida] = samid;
  69. Sam[samid][SX] = X;
  70. Sam[samid][SY] = Y;
  71. Sam[samid][SZ] = Z;
  72. Sam[samid][speed] = sspeed;
  73. Sam[samid][range] = srange;
  74. Sam[samid][chaseid] = -1;
  75. Sam[samid][Fired] = 0;
  76. if(bool:CSO == true)
  77. {
  78. sOBJECT[samid] = CreateObject(3884,X,Y,X,rX,rY,rZ);
  79. printf("[SAM] SAM %d Created - %f,%f,%f -",samid,X,Y,Z);
  80. }
  81. return samid;
  82. }
  83. stock SAM_start()
  84. {
  85. resttime = SetTimer("SamLive",500,true);
  86. SetTimer("Restart",RESTART_TIME,false);
  87. print("\n--------------------------------------");
  88. print(" Surface To Air Missiles System Loaded");
  89. print(" 0.4.1");
  90. print("--------------------------------------\n");
  91. return 1;
  92. }
  93. stock CreateSamLabel(samid, label[], color, Float:DrawDistance, LOS)
  94. {
  95. if(samid == INVALID_SAM_ID) return false;
  96. new string[128];
  97. format(string,sizeof(string),"%s(%d)",label,samid);
  98. SamLabel[samid] = Create3DTextLabel(string,color,Sam[samid][SX],Sam[samid][SY],Sam[samid][SZ] + 2.00,DrawDistance,0,LOS);
  99. return true;
  100. }
  101. stock GetMaxSams()
  102. {
  103. return samset;
  104. }
  105. forward SamLive();
  106. public SamLive()
  107. {
  108. for(new s = 0; s <GetMaxSams(); s++)
  109. {
  110. if(s != INVALID_SAM_ID)
  111. {
  112. SamConfig(s);
  113. }
  114. }
  115. }
  116. forward SamConfig(samid);
  117. public SamConfig(samid)
  118. {
  119. for(new i = 0; i <MAX_PLAYERS; i++)
  120. {
  121. if(IsPlayerConnected(i))
  122. {
  123. if(Sam[samid][Fired] == 0)
  124. {
  125. if(IsPlayerInAnyVehicle(i))
  126. {
  127. new veh = GetPlayerVehicleID(i);
  128. if(IsAirVehicle(veh))
  129. {
  130. if(IsVehicleInRangeOfPoint(veh,Sam[samid][range],Sam[samid][SX],Sam[samid][SY],Sam[samid][SZ]))
  131. {
  132. if(!OnSamSiteUpdate(samid, i)) { return 1; }
  133. else
  134. {
  135. Missile[samid] = CreateObject(354,Sam[samid][SX],Sam[samid][SY],Sam[samid][SZ],0,0,0);
  136. Sam[samid][Fired] = 1;
  137. Sam[samid][chaseid] = veh;
  138. FireSam(samid,i,veh);
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }
  146. return 1;
  147. }
  148. forward FireSam(samid, playerid, vehicleid);
  149. public FireSam(samid, playerid, vehicleid)
  150. {
  151. if(Sam[samid][chaseid] != vehicleid) return 1;
  152. FireMissileKill[samid] = SetTimerEx("Fire",500,true,"iii",playerid, samid, vehicleid);
  153. FireMissileKill2[samid] = SetTimerEx("Destroy",300,true,"iii",playerid,samid,vehicleid);
  154. DragKill[samid] = SetTimerEx("Drag",MISSILE_DRAG_TIME,false,"i",samid);
  155. return 1;
  156. }
  157. forward Fire(playerid, samid, vehicleid);
  158. public Fire(playerid, samid, vehicleid)
  159. {
  160. if(!IsPlayerConnected(playerid))
  161. {
  162. KillTimer(FireMissileKill[samid]);
  163. KillTimer(FireMissileKill2[samid]);
  164. KillTimer(DragKill[samid]);
  165. Drag(samid);
  166. return 1;
  167. }
  168. if(vehicleid == Sam[samid][chaseid])
  169. {
  170. new Float:X,
  171. Float:Y,
  172. Float:Z;
  173. GetVehiclePos(vehicleid,X,Y,Z);
  174. StopObject(Missile[samid]);
  175. MoveObject(Missile[samid],X,Y,Z,Sam[samid][speed]);
  176. }
  177. return 1;
  178. }
  179. forward Destroy(playerid, samid, vehicleid);
  180. public Destroy(playerid, samid, vehicleid)
  181. {
  182. new Float:OX,
  183. Float:OY,
  184. Float:OZ;
  185. GetObjectPos(Missile[samid],OX,OY,OZ);
  186. if(IsVehicleInRangeOfPoint(vehicleid,3,OX,OY,OZ))
  187. {
  188. CreateExplosion(OX,OY,OZ,2,10);
  189. KillTimer(FireMissileKill[samid]);
  190. KillTimer(FireMissileKill2[samid]);
  191. DecreaseVehicleHealth(vehicleid, 50.0);
  192. KillTimer(DragKill[samid]);
  193. SetTimerEx("FireSet",5000,false,"i",samid);
  194. DestroyObject(Missile[samid]);
  195. }
  196. return 1;
  197. }
  198. forward FireSet(samid);
  199. public FireSet(samid)
  200. {
  201. Sam[samid][Fired] = 0;
  202. }
  203. forward Drag(samid);
  204. public Drag(samid)
  205. {
  206. new Float:OX,
  207. Float:OY,
  208. Float:OZ;
  209. GetObjectPos(Missile[samid],OX,OY,OZ);
  210. CreateExplosion(OX,OY,OZ,2,2.00);
  211. CreateExplosion(OX,OY,OZ,2,2.00);
  212. CreateExplosion(OX,OY,OZ,2,2.00);
  213. Sam[samid][Fired] = 0;
  214. DestroyObject(Missile[samid]);
  215. }
  216. stock IsAirVehicle(carid)
  217. {
  218. new AirVeh[] = { 592, 577, 511, 512, 593, 520, 553, 476, 519, 460, 513, 548, 425, 417, 487, 488, 497, 563, 447, 469 };
  219. for(new i = 0; i < sizeof(AirVeh); i++)
  220. {
  221. if(GetVehicleModel(carid) == AirVeh[i]) return 1;
  222. }
  223. return 0;
  224. }
  225. stock DecreaseVehicleHealth(vehicleid, Float:decreaseby)
  226. {
  227. new Float:voldhp;
  228. GetVehicleHealth(vehicleid, voldhp);
  229. return SetVehicleHealth(vehicleid,voldhp - decreaseby);
  230. }
  231. IsVehicleInRangeOfPoint(vehicleid, Float:vrange, Float:x, Float:y, Float:z)
  232. {
  233. new Float:oldpos[3],
  234. Float:temppos[3];
  235. GetVehiclePos(vehicleid, oldpos[0], oldpos[1], oldpos[2]);
  236. temppos[0] = (oldpos[0] -x);
  237. temppos[1] = (oldpos[1] -y);
  238. temppos[2] = (oldpos[2] -z);
  239. if(((temppos[0] < vrange) && (temppos[0] > -vrange)) && ((temppos[1] < vrange) && (temppos[1] > -vrange)) && ((temppos[2] < vrange) && (temppos[2] > -vrange)))
  240. {
  241. return true;
  242. }
  243. return false;
  244. }
  245. forward Restart();
  246. public Restart()
  247. {
  248. KillTimer(resttime);
  249. print("SAM Sites System Reloading\n");
  250. SendRconCommand(RELOAD_STRING);
  251. return 1;
  252. }
  253. /*
  254. Dead SAM Bug
  255. This bug causes all Sam Sites to stop functionality after a duration of time. This is hopefully the last fix I need to do to this Script. */