Guest User

Untitled

a guest
Apr 6th, 2011
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.32 KB | None | 0 0
  1. /*
  2. * 30mm Autocannon for SA:MP air vehicles
  3. *
  4. *
  5. */
  6.  
  7. #include <a_samp>
  8. #include <mapandreas>
  9.  
  10. #define AC_PROJECTILE_DRAW_DISTANCE 150.0
  11.  
  12. #define AC_EXPLOSION_TYPE 2
  13. #define AC_EXPLOSION_RADIUS 10.0
  14.  
  15. #define AC_AIM_SWAY 0.02
  16.  
  17. #define AC_EXPLOSION_SWAY 1.0
  18.  
  19. #define AC_SPEED 100.0
  20.  
  21. #define AC_TIMER_INTERVAL 100
  22.  
  23. #define AC_PROJECTILES_PER_TICK 1
  24.  
  25. #define AC_PROJECTILE_OBJECT_ID 354
  26. #define AC_KEY_GUN KEY_FIRE
  27.  
  28. #define AC_SCALE 5.0
  29.  
  30. #define AC_MAX_PROJECTILES_PER_PLAYER 50
  31.  
  32. #define AC_MAX_STEPS 200 // max timer ticks projectile alive
  33.  
  34. #define AC_BURST_SIZE 10
  35.  
  36. #define AC_COOLDOWN 3000
  37.  
  38. #define FSTR(%0,%1) new %0[128]; \
  39. format(%0, 128, %1)
  40.  
  41. forward ACUpdate();
  42. forward ACBlow(playerid, projId, Float:PX, Float:PY, Float:PZ);
  43. forward Float:ac_floatrand(Float:max, Float:min = 0.0, dp = 4);
  44. stock Float:GetGroundZ(Float:x, Float:y);
  45.  
  46. enum AC_PROJECTILE
  47. {
  48. bool:enabled,
  49. Float:pos[3],
  50. Float:vector[3],
  51. objectId,
  52. steps,
  53. bool:explode
  54. }
  55.  
  56. new acProjectiles[MAX_PLAYERS][AC_MAX_PROJECTILES_PER_PLAYER][AC_PROJECTILE];
  57. new acProjectileCount[MAX_PLAYERS];
  58. new acIsFiring[MAX_PLAYERS];
  59. new acFiredLastTime[MAX_PLAYERS];
  60. new acFireCount[MAX_PLAYERS];
  61.  
  62. public OnFilterScriptInit()
  63. {
  64. print("\n--------------------------------------");
  65. print(" Autocannon script by Teprey");
  66. print("--------------------------------------\n");
  67. SetTimer("ACUpdate", AC_TIMER_INTERVAL, true);
  68. return 1;
  69. }
  70.  
  71. public ACBlow(playerid, projId, Float:PX, Float:PY, Float:PZ)
  72. {
  73. DestroyObject(acProjectiles[playerid][projId][objectId]);
  74. acProjectiles[playerid][projId][enabled] = false;
  75. CreateExplosion(ac_floatrand(PX + AC_EXPLOSION_SWAY, PX - AC_EXPLOSION_SWAY),
  76. ac_floatrand(PY + AC_EXPLOSION_SWAY, PY - AC_EXPLOSION_SWAY),
  77. ac_floatrand(PZ + AC_EXPLOSION_SWAY, PZ) + 1.0, AC_EXPLOSION_TYPE, AC_EXPLOSION_RADIUS);
  78. }
  79.  
  80. public ACUpdate()
  81. {
  82. for (new playerid = 0 ; playerid < MAX_PLAYERS ; playerid++)
  83. {
  84. if (acIsFiring[playerid] == 1)
  85. {
  86. if ((acFiredLastTime[playerid] - tickcount() + AC_COOLDOWN) < 0) {
  87. if (acFireCount[playerid] > AC_BURST_SIZE) { acFireCount[playerid] = 0; acFiredLastTime[playerid] = tickcount(); }
  88. if (IsPlayerInAnyVehicle(playerid))
  89. {
  90. new vehId = GetPlayerVehicleID(playerid);
  91. if (IsVehicleAirVehicle(GetVehicleModel(vehId)))
  92. {
  93. new
  94. Float:fPX, Float:fPY, Float:fPZ;
  95. //GetVehiclePos(vehId, fPX, fPY, fPZ);
  96. GetPlayerCameraPos(playerid, fPX, fPY, fPZ);
  97. for (new it = 0 ; it < AC_PROJECTILES_PER_TICK ; it++)
  98. {
  99. ac_Fire(playerid, fPX, fPY, fPZ);
  100. acFireCount[playerid]++;
  101. }
  102. }
  103. }
  104. }
  105. }
  106. for (new projId = 0 ; projId < AC_MAX_PROJECTILES_PER_PLAYER ; projId++)
  107. {
  108. if (acProjectiles[playerid][projId][enabled] == false) { continue; }
  109. if (acProjectiles[playerid][projId][explode]) continue;
  110. new
  111. Float:PX, Float:PY, Float:PZ,
  112. Float:fVX, Float:fVY, Float:fVZ,
  113. Float:object_x, Float:object_y, Float:object_z, bool:fire;
  114. fVX = acProjectiles[playerid][projId][vector][0];
  115. fVY = acProjectiles[playerid][projId][vector][1];
  116. fVZ = acProjectiles[playerid][projId][vector][2];
  117.  
  118. PX = acProjectiles[playerid][projId][pos][0];
  119. PY = acProjectiles[playerid][projId][pos][1];
  120. PZ = acProjectiles[playerid][projId][pos][2];
  121.  
  122. object_x = PX + floatmul(fVX, AC_SPEED);
  123. object_y = PY + floatmul(fVY, AC_SPEED);
  124. new Float:groundZ = GetGroundZ(object_x, object_y);
  125. object_z = PZ + floatmul(fVZ, AC_SPEED);
  126. if (groundZ > object_z)
  127. {
  128. fire = true;
  129. }
  130. acProjectiles[playerid][projId][pos][0] = object_x;
  131. acProjectiles[playerid][projId][pos][1] = object_y;
  132. acProjectiles[playerid][projId][pos][2] = object_z;
  133.  
  134. new time = MoveObject(acProjectiles[playerid][projId][objectId], object_x, object_y, object_z, AC_SPEED);
  135. if (fire == true) { SetTimerEx("ACBlow", time, false, "iifff", playerid, projId, object_x, object_y, groundZ); }
  136. acProjectiles[playerid][projId][steps]++;
  137. if (acProjectiles[playerid][projId][steps] > AC_MAX_STEPS) { DestroyObject(acProjectiles[playerid][projId][objectId]);
  138. acProjectiles[playerid][projId][steps] =0;
  139. acProjectiles[playerid][projId][enabled] = false;
  140. }
  141. }
  142. }
  143. }
  144.  
  145. public OnFilterScriptExit()
  146. {
  147. return 1;
  148. }
  149. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  150. {
  151. if ((newkeys & AC_KEY_GUN))
  152. {
  153. acIsFiring[playerid] = 1;
  154. }
  155. if (!(newkeys & AC_KEY_GUN) && (oldkeys & AC_KEY_GUN))
  156. {
  157. acIsFiring[playerid] = 0;
  158. }
  159. return 1;
  160. }
  161. stock ac_Fire(playerid, Float:posX, Float:posY, Float:posZ)
  162. {
  163.  
  164. new
  165. Float:fVX, Float:fVY, Float:fVZ,
  166. Float:object_x, Float:object_y, Float:object_z;
  167.  
  168. GetPlayerCameraFrontVector(playerid, fVX, fVY, fVZ);
  169.  
  170. fVX = floatadd(fVX, ac_floatrand(AC_AIM_SWAY, floatsub(0.0, AC_AIM_SWAY)));
  171. fVY = floatadd(fVY, ac_floatrand(AC_AIM_SWAY, floatsub(0.0, AC_AIM_SWAY)));
  172. fVZ = floatadd(fVZ, ac_floatrand(AC_AIM_SWAY, floatsub(0.0, AC_AIM_SWAY)));
  173.  
  174. object_x = posX + floatmul(fVX, AC_SCALE);
  175. object_y = posY + floatmul(fVY, AC_SCALE);
  176. object_z = posZ + floatmul(fVZ, AC_SCALE);
  177. new objId = CreateObject(AC_PROJECTILE_OBJECT_ID, object_x, object_y, object_z, 0, 0, 0, AC_PROJECTILE_DRAW_DISTANCE);
  178. acProjectiles[playerid][acProjectileCount[playerid]][pos][0] = object_x;
  179. acProjectiles[playerid][acProjectileCount[playerid]][pos][1] = object_y;
  180. acProjectiles[playerid][acProjectileCount[playerid]][pos][2] = object_z;
  181. acProjectiles[playerid][acProjectileCount[playerid]][vector][0] = fVX;
  182. acProjectiles[playerid][acProjectileCount[playerid]][vector][1] = fVY;
  183. acProjectiles[playerid][acProjectileCount[playerid]][vector][2] = fVZ;
  184. acProjectiles[playerid][acProjectileCount[playerid]][objectId] = objId;
  185. acProjectiles[playerid][acProjectileCount[playerid]][enabled] = true;
  186. acProjectiles[playerid][acProjectileCount[playerid]][explode] = false;
  187. acProjectileCount[playerid] = acProjectileCount[playerid] + 1;
  188. if (acProjectileCount[playerid] == AC_MAX_PROJECTILES_PER_PLAYER) { acProjectileCount[playerid] = 0; }
  189. }
  190. stock Float:GetGroundZ(Float:x, Float:y)
  191. {
  192. new Float:gz;
  193. new Float:highest = 0.0;
  194.  
  195. MapAndreas_FindZ_For2DCoord(x, y, gz); if (gz > highest) highest = gz;
  196. MapAndreas_FindZ_For2DCoord(x+1, y, gz); if (gz > highest) highest = gz;
  197. MapAndreas_FindZ_For2DCoord(x-1, y, gz); if (gz > highest) highest = gz;
  198. MapAndreas_FindZ_For2DCoord(x, y+1, gz); if (gz > highest) highest = gz;
  199. MapAndreas_FindZ_For2DCoord(x, y-1, gz); if (gz > highest) highest = gz;
  200. return highest;
  201. }
  202. stock Float:ac_floatrand(Float:max, Float:min = 0.0, dp = 4)
  203. {
  204. new
  205. // Get the multiplication for storing fractional parts.
  206. Float:mul = floatpower(10.0, dp),
  207. // Get the max and min as integers, with extra dp.
  208. imin = floatround(floatmul(min, mul)),
  209. imax = floatround(floatmul(max, mul));
  210. // Get a random int between two bounds and convert it to a float.
  211. return floatdiv(float(random(imax - imin) + imin), mul);
  212. }
  213. stock IsVehicleAirVehicle(vehid)
  214. {
  215. switch(vehid)
  216. {
  217. case 592, 577, 511, 512, 593, 520, 553, 476, 519, 460, 513, 548, 425, 417, 487, 488, 498, 563, 447, 469: return true;
  218. }
  219. return false;
  220. }
Advertisement
Add Comment
Please, Sign In to add comment