Guest User

Swat's cannon like rhino's

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