Advertisement
Guest User

Hotrod Minigun by Smileys

a guest
Feb 23rd, 2015
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.80 KB | None | 0 0
  1. #include < a_samp >
  2. #include <foreach>
  3. #include <streamer>
  4. #include <zcmd>
  5.  
  6. #define function%0(%1) \
  7. forward%0(%1); public%0(%1) // Thanks Ryder`
  8.  
  9. // Change these if you wish to change the accuracy, be careful with it tho
  10. /* DEFAULT VALUES:
  11. * MAX_VEHICLE_SHOOT_DISTANCE 5.0
  12. * MAX_PLAYER_SHOOT_DISTANCE 5.0
  13. * DISTANCE_FROM_VEHICLE 10.0
  14. */
  15. #define MAX_VEHICLE_SHOOT_DISTANCE 5.0 // maximum distance a hotrod can shoot another vehicle
  16. #define MAX_PLAYER_SHOOT_DISTANCE 5.0 // maximum distance a hotrod can shoot a player
  17. #define DISTANCE_FROM_VEHICLE 10.0 // distance away from the car infront of the car
  18.  
  19. // Change these to your whatever you feel is right
  20. /* DEFAULT VALUES:
  21. * PLAYER_HEALTH_LOSS 5.0
  22. * OCCUPIED_VEHICLE_HEALTH_LOSS 75.0
  23. * UNOCCUPIED_VEHICLE_HEALTH_LOSS 125.0
  24. */
  25. #define PLAYER_HEALTH_LOSS 5.0 // amount of health a player loses when someone shoots him with a hotrod
  26. #define OCCUPIED_VEHICLE_HEALTH_LOSS 75.0 // amount of health an occupied vehicle loses when someone shoots it with a hotrod
  27. #define UNOCCUPIED_VEHICLE_HEALTH_LOSS 125.0 // amount of health an unoccupied vehicle loses when someone shoots it with a hotrod
  28.  
  29. // change these to yours
  30. #undef MAX_VEHICLES
  31. #define MAX_VEHICLES 2000 // change this to your max vehicles.
  32.  
  33. #undef MAX_PLAYERS
  34. #define MAX_PLAYERS 100 // change this to your max players.
  35.  
  36. //native IsValidVehicle(vehicleid); // uncomment this if you don't have this native defined in your a_samp.inc
  37.  
  38. enum E_MINIGUN_DATA
  39. {
  40. E_MINIGUN_OBJECT[ 2 ],
  41. E_MINIGUN_FLASH[ 2 ]
  42. };
  43.  
  44. new updateTimer;
  45.  
  46. new gMiniguns[ MAX_VEHICLES ][ E_MINIGUN_DATA ];
  47.  
  48. new gHasMiniguns[ MAX_VEHICLES ] = { false, false, false };
  49.  
  50. public OnFilterScriptInit( )
  51. {
  52. updateTimer = SetTimer( "update", 200, 1 );
  53. return 1;
  54. }
  55.  
  56. public OnFilterScriptExit( )
  57. {
  58. KillTimer( updateTimer );
  59. for( new i = 0; i < MAX_VEHICLES; i++ )
  60. {
  61. if( GetVehicleModel( i ) == 434 && gHasMiniguns[ i ] )
  62. {
  63. DestroyMiniguns( i );
  64. DestroyMinigunFlashes( i );
  65.  
  66. DestroyVehicle( i );
  67. }
  68. }
  69. return 1;
  70. }
  71.  
  72. CMD:hotrod( playerid, params[ ] )
  73. {
  74. new Float:x, Float:y, Float:z, Float:angle;
  75. GetPlayerPos( playerid, x, y, z );
  76. GetPlayerFacingAngle( playerid, angle );
  77. new vehicle = CreateHotrod( playerid, x, y, z, angle );
  78. PutPlayerInVehicle( playerid, vehicle, 0 );
  79. return 1;
  80. }
  81.  
  82. public OnVehicleDeath( vehicleid, killerid )
  83. {
  84. if( GetVehicleModel( vehicleid ) == 434 && gHasMiniguns[ vehicleid ] )
  85. {
  86. DestroyMiniguns( vehicleid );
  87. DestroyMinigunFlashes( vehicleid );
  88. DestroyVehicle( vehicleid );
  89. }
  90. return 1;
  91. }
  92.  
  93. public OnVehicleSpawn( vehicleid )
  94. {
  95. if( GetVehicleModel( vehicleid ) == 434 && gHasMiniguns[ vehicleid ] )
  96. {
  97. DestroyMiniguns( vehicleid );
  98. DestroyMinigunFlashes( vehicleid );
  99.  
  100. AttachMinigunsToHotrod( vehicleid );
  101. }
  102. return 1;
  103. }
  104.  
  105. public OnPlayerDeath( playerid, killerid, reason )
  106. {
  107. //CallRemoteFunction( "OnPlayerDeath", "iii", playerid, killerid, reason );
  108. return 1;
  109. }
  110.  
  111. function CreateHotrod( playerid, Float:x, Float:y, Float:z, Float:rot )
  112. {
  113. new Hotrod = CreateVehicle( 434, x, y, z, rot, -1, -1, -1 ); // Hotrod vehicle
  114. SetVehicleVirtualWorld( Hotrod, GetPlayerVirtualWorld( playerid ) );
  115. AttachMinigunsToHotrod( Hotrod );
  116. return Hotrod; // returns the vehicleid of the hotrod
  117. }
  118.  
  119. function update( )
  120. {
  121. new
  122. keys,
  123. ud,
  124. lr,
  125. vehicleid,
  126. Float:x,
  127. Float:y,
  128. Float:z,
  129. Float:health
  130. ;
  131.  
  132. foreach( new i : Player)
  133. {
  134. if( !IsPlayerInAnyVehicle( i ) ) continue;
  135.  
  136. vehicleid = GetPlayerVehicleID( i );
  137.  
  138. if( GetVehicleModel( vehicleid ) == 434 && gHasMiniguns[ vehicleid ] ) // hotknife
  139. {
  140. GetPlayerKeys( i, keys, ud, lr );
  141.  
  142. if( ( ( keys & ( KEY_FIRE ) )== ( KEY_FIRE ) ) )
  143. {
  144. DestroyMinigunFlashes( vehicleid );
  145.  
  146. gMiniguns[ vehicleid ][ E_MINIGUN_FLASH ][ 0 ] = CreateDynamicObject( 18695, 0, 0, 0, 0, 0, 0, GetVehicleVirtualWorld( vehicleid ), -1, -1, 200.0, 200.0 );
  147. AttachDynamicObjectToVehicle( gMiniguns[ vehicleid ][ E_MINIGUN_FLASH ][ 0 ], vehicleid, 0.299999,2.035000,-1.485000,0.000000,0.000000,0.000000 );
  148.  
  149. gMiniguns[ vehicleid ][ E_MINIGUN_FLASH ][ 1 ] = CreateDynamicObject( 18695, 0, 0, 0, 0, 0, 0, GetVehicleVirtualWorld( vehicleid ), -1, -1, 200.0, 200.0 );
  150. AttachDynamicObjectToVehicle( gMiniguns[ vehicleid ][ E_MINIGUN_FLASH ][ 1 ], vehicleid, -0.310000,2.035000,-1.485000,0.000000,0.000000,0.000000 );
  151.  
  152. PlaySoundForPlayer( i, 1135 ); // gunsound
  153.  
  154. GetPlayerPos( i, x, y, z );
  155. GetXYInFrontOfPlayer( i, x, y, DISTANCE_FROM_VEHICLE );
  156.  
  157. for( new u = 0; u < MAX_VEHICLES; u++ )
  158. {
  159. if( !IsValidVehicle( u ) ) continue;
  160.  
  161. if( GetVehicleDistanceFromPoint( u, x, y, z ) < MAX_VEHICLE_SHOOT_DISTANCE && u != vehicleid )
  162. {
  163. GetVehicleHealth( u, health );
  164.  
  165. if( health > 240 )
  166. SetVehicleHealth( u, health - UNOCCUPIED_VEHICLE_HEALTH_LOSS );
  167. }
  168. }
  169.  
  170. foreach( new u : Player)
  171. {
  172. if( IsPlayerInRangeOfPoint( u, MAX_PLAYER_SHOOT_DISTANCE, x, y, z ) && u != i )
  173. {
  174. if( IsPlayerInAnyVehicle( u ) )
  175. {
  176. GetVehicleHealth( GetPlayerVehicleID( u ), health );
  177. SetVehicleHealth( GetPlayerVehicleID( u ), health - OCCUPIED_VEHICLE_HEALTH_LOSS );
  178. }
  179. else
  180. {
  181. GetPlayerHealth( u, health );
  182. SetPlayerHealth( u, health - PLAYER_HEALTH_LOSS );
  183. }
  184. PlayerPlaySound( u, 1135, 0.0, 0.0, 0.0 ); // gunsound
  185. }
  186. }
  187. }
  188. }
  189. }
  190. return 1;
  191. }
  192.  
  193. stock AttachMinigunsToHotrod( vehicleid )
  194. {
  195. gMiniguns[ vehicleid ][ E_MINIGUN_OBJECT ][ 0 ] = CreateDynamicObject( 362, 0, 0, 0, 0, 0, 0, GetVehicleVirtualWorld( vehicleid ), -1, -1, 200.0, 200.0 ); // minigun object
  196. AttachDynamicObjectToVehicle( gMiniguns[ vehicleid ][ E_MINIGUN_OBJECT ][ 0 ], vehicleid, 0.450000,0.824999,0.290000,27.000003,27.000001,94.499977 );
  197.  
  198. gMiniguns[ vehicleid ][ E_MINIGUN_OBJECT ][ 1 ] = CreateDynamicObject( 362, 0, 0, 0, 0, 0, 0, GetVehicleVirtualWorld( vehicleid ), -1, -1, 200.0, 200.0 ); // minigun object
  199. AttachDynamicObjectToVehicle( gMiniguns[ vehicleid ][ E_MINIGUN_OBJECT ][ 1 ], vehicleid, -0.449999,0.824999,0.260000,-54.000007,32.400001,94.499977 );
  200.  
  201. gHasMiniguns[ vehicleid ] = true;
  202. return 1;
  203. }
  204.  
  205. stock PlaySoundForPlayer( playerid, soundid )
  206. {
  207. new Float:x, Float:y, Float:z;
  208. GetPlayerPos( playerid, x, y, z );
  209. PlayerPlaySound( playerid, soundid, x, y, z );
  210. return 1;
  211. }
  212.  
  213. stock DestroyMiniguns( vehicleid )
  214. {
  215. if( IsValidDynamicObject( gMiniguns[ vehicleid ][ E_MINIGUN_OBJECT ][ 0 ] ) )
  216. DestroyDynamicObject( gMiniguns[ vehicleid ][ E_MINIGUN_OBJECT ][ 0 ] );
  217.  
  218. if( IsValidDynamicObject( gMiniguns[ vehicleid ][ E_MINIGUN_OBJECT ][ 1 ] ) )
  219. DestroyDynamicObject( gMiniguns[ vehicleid ][ E_MINIGUN_OBJECT ][ 1 ] );
  220.  
  221. gHasMiniguns[ vehicleid ] = false;
  222. return 1;
  223. }
  224.  
  225. stock DestroyMinigunFlashes( vehicleid )
  226. {
  227. if( IsValidDynamicObject( gMiniguns[ vehicleid ][ E_MINIGUN_FLASH ][ 0 ] ) )
  228. DestroyDynamicObject( gMiniguns[ vehicleid ][ E_MINIGUN_FLASH ][ 0 ] );
  229.  
  230. if( IsValidDynamicObject( gMiniguns[ vehicleid ][ E_MINIGUN_FLASH ][ 1 ] ) )
  231. DestroyDynamicObject( gMiniguns[ vehicleid ][ E_MINIGUN_FLASH ][ 1 ] );
  232. return 1;
  233. }
  234.  
  235. GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance) // Thanks whoever made this
  236. {
  237. new Float:a;
  238. GetPlayerPos(playerid, x, y, a);
  239. GetPlayerFacingAngle(playerid, a);
  240. if (GetPlayerVehicleID(playerid))
  241. {
  242. GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
  243. }
  244. x += (distance * floatsin(-a, degrees));
  245. y += (distance * floatcos(-a, degrees));
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement