Guest User

SWAT Cannon V2.3 (colandreas)

a guest
Aug 16th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. #include <streamer>
  2. #include <colandreas>
  3.  
  4. #define MAX_CANNON_RANGE 200
  5. #define MIN_CANNON_RANGE 15
  6.  
  7. new firedcannon[MAX_PLAYERS];
  8. new CannonRange[MAX_PLAYERS] = 200;
  9. new HPDeathCallTimer[MAX_PLAYERS];
  10.  
  11. stock randomEx(min, max)
  12. {
  13. new rand9 = random(max-min)+min;
  14. return rand9;
  15. }//credits to yless
  16.  
  17. stock GetPlayerVSpeed(playerid)
  18. {
  19. new Float:x,Float:y,Float:z,Float:speed,final_speed;
  20. GetVehicleVelocity(GetPlayerVehicleID(playerid),x,y,z);
  21. speed = floatsqroot(((x*x)+(y*y))+(z*z))*100;
  22. final_speed = floatround(speed,floatround_round);
  23. return final_speed;
  24. }
  25.  
  26. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  27. {
  28. if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 601)
  29. {
  30. new string[128];
  31. if(HOLDING(65536))//yes
  32. {
  33. if(CannonRange[playerid] < MAX_CANNON_RANGE)
  34. {
  35. CannonRange[playerid] = CannonRange[playerid]+1;
  36. format(string, sizeof(string), "~g~Cannon's Range Increased To %i",CannonRange[playerid]);
  37. GameTextForPlayer(playerid,string,5000,4);
  38. }
  39. else
  40. {
  41. GameTextForPlayer(playerid,"~r~Cannon is at the maximum range of 200 meters",5000,4);
  42. }
  43. }
  44. else if(HOLDING(131072))//no
  45. {
  46. if(CannonRange[playerid] > MIN_CANNON_RANGE)
  47. {
  48. CannonRange[playerid] = CannonRange[playerid]-1;
  49. format(string, sizeof(string), "~r~Cannon's Range Decreased To %i",CannonRange[playerid]);
  50. GameTextForPlayer(playerid,string,5000,4);
  51. }
  52. else
  53. {
  54. GameTextForPlayer(playerid,"~r~Cannon is at the minimum range of 15 meters",5000,4);
  55. }
  56. }
  57. }
  58.  
  59. if(newkeys & KEY_FIRE)
  60. {
  61. if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 601)
  62. {
  63. if(firedcannon[playerid] == 0)
  64. {
  65. firedcannon[playerid] = 1;
  66. SetTimerEx("cannonfired", 2500, false,"i",playerid);
  67. new
  68. Float:x8, Float:y8, Float:z8,
  69. Float:x2, Float:y2, Float:z2,
  70. Float:x7, Float:y7, Float:z7,
  71. Float:object_x1, Float:object_y1, Float:object_z1,
  72. Float:xf,Float:yf,Float:zf;
  73. GetPlayerPos(playerid,x7,y7,z7);
  74. GetPlayerCameraPos(playerid, x8,y8,z8);
  75. GetPlayerCameraFrontVector(playerid, x2,y2,z2);
  76.  
  77.  
  78. new sa2 = randomEx(-1, 1)*((CannonRange[playerid]-5)/10);
  79. new sa3 = randomEx(-1, 1)*((CannonRange[playerid]-5)/10);
  80. new Float:speedt2 = GetPlayerVSpeed(playerid);
  81. new speedt;
  82. if(speedt2 == 0.0)
  83. {
  84. speedt = 0;
  85. }
  86. else if(speedt2 <= 5.0)
  87. {
  88. speedt = 1;
  89. }
  90. else if(speedt2 > 5.0 && speedt2 <= 40.0)
  91. {
  92. speedt = 2;
  93. }
  94. else if(speedt2 > 40.0)
  95. {
  96. speedt = 3;
  97. }
  98.  
  99. object_x1 = floatadd(x8, floatmul(x2, CannonRange[playerid]));
  100. object_y1 = floatadd(y8, floatmul(y2, CannonRange[playerid]));
  101. object_z1 = floatadd(z8, floatmul(z2, CannonRange[playerid]));
  102.  
  103. xf = floatadd(x8, floatmul(x2, CannonRange[playerid]));
  104. yf = floatadd(y8, floatmul(y2, CannonRange[playerid]));
  105. zf = floatadd(z8, floatmul(z2, CannonRange[playerid]));
  106.  
  107. CA_RayCastLine(x8,y8,z8,object_x1,object_y1,object_z1,xf,yf,zf);
  108.  
  109. CreateExplosion(xf+sa2*speedt, yf+sa3*speedt, zf, 12, 3.5);
  110. foreach(new i : Player)
  111. {
  112. if(GetPlayerTeam(i) != GetPlayerTeam(playerid))
  113. {
  114. if(i != playerid)
  115. {
  116. if(IsPlayerInRangeOfPoint(i,3.5,xf+sa2*speedt, yf+sa3*speedt, zf))
  117. {
  118. HPDeathCallTimer[i] = defer PlayerHPDeathCall(i, playerid, 5.0, 51);
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }
  125. }
  126. return 1;
  127. }
  128.  
  129. forward DeathCall(playerid,killerid,Float:HP,reason);
  130. public DeathCall(playerid,killerid,Float:HP,reason)
  131. {
  132. new Float:hitp;
  133. GetPlayerHealth(playerid, hitp);
  134. if((hitp - HP) <= 0.0)
  135. {
  136. return CallLocalFunction("OnPlayerDeath", "iii", playerid, killerid, reason);
  137. }
  138. return 1;
  139. }
  140.  
  141. forward cannonfired(playerid);
  142. public cannonfired(playerid)
  143. {
  144. firedcannon[playerid] = 0;
  145. return 1;
  146. }
Add Comment
Please, Sign In to add comment