Advertisement
Guest User

Untitled

a guest
May 5th, 2012
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.12 KB | None | 0 0
  1. /* FS:Bazooka made by Marricio/Mecaurio for SA-MP forums
  2. I keep the credits as creator of this filterscript.
  3. Check line 242*/
  4.  
  5. #include a_samp
  6. #include zcmd
  7. #include MapAndreas
  8.  
  9. #define SCRIPT_VERSION "v1.1"
  10. #define MISSIL_RANGE 55.0
  11. #define MAX_BAZOOKAS 200
  12. #define FIRE_SPEED 40
  13.  
  14. forward FixAnimation( playerid );
  15.  
  16. enum fs_bInfo
  17. {
  18. bCreated,
  19. Float:bx,
  20. Float:by,
  21. Float:bz,
  22. Float:ba,
  23. Float:bmx,
  24. Float:bmy,
  25. Float:bmz,
  26. bObject,
  27. bMissil,
  28. bBeingUsed,
  29. bPlacedBy[24],
  30. bDate[64]
  31. }
  32. new BazInfo[MAX_BAZOOKAS][fs_bInfo];
  33.  
  34. new PlacingBazooka[MAX_PLAYERS];
  35. new AimingBazooka[MAX_PLAYERS] = -1;
  36.  
  37. public OnFilterScriptInit( )
  38. {
  39. printf(" FS:Bazooka %s by Marricio is loaded.", SCRIPT_VERSION );
  40. }
  41.  
  42. public OnPlayerDisconnect( playerid )
  43. {
  44. PlacingBazooka[playerid] = 0;
  45. AimingBazooka[playerid] = -1;
  46. if( IsPlayerAttachedObjectSlotUsed( playerid, 0 ) )
  47. RemovePlayerAttachedObject( playerid, 0 );
  48.  
  49. for( new i = 0; i != MAX_BAZOOKAS; i++ )
  50. {
  51. if( BazInfo[i][bBeingUsed] == playerid )
  52. {
  53. BazInfo[i][bBeingUsed] = -1;
  54. break;
  55. }
  56. }
  57.  
  58. return 1;
  59. }
  60.  
  61. public OnFilterScriptExit( )
  62. {
  63. for( new i = 0; i != MAX_BAZOOKAS; i++ )
  64. {
  65. if( BazInfo[i][bCreated] == 1 )
  66. {
  67. BazInfo[i][bCreated] = 0;
  68. BazInfo[i][bx] = 0;
  69. BazInfo[i][by] = 0;
  70. BazInfo[i][bz] = 0;
  71. BazInfo[i][bmx] = 0;
  72. BazInfo[i][bmy] = 0;
  73. BazInfo[i][bmz] = 0;
  74. BazInfo[i][ba] = 0;
  75. BazInfo[i][bBeingUsed] = -1;
  76.  
  77. if( IsValidObject( BazInfo[i][bMissil] ) )
  78. DestroyObject( BazInfo[i][bMissil] );
  79.  
  80. if( IsValidObject( BazInfo[i][bObject] ) )
  81. DestroyObject( BazInfo[i][bObject] );
  82.  
  83. format( BazInfo[i][bPlacedBy], 32, "None" );
  84. format( BazInfo[i][bDate], 64, "-" );
  85. for( new pi = 0; pi != MAX_PLAYERS; pi++ )
  86. {
  87. if( AimingBazooka[pi] == i )
  88. {
  89. SetCameraBehindPlayer( pi );
  90. ClearAnimations( pi );
  91. TogglePlayerControllable( pi, 1 );
  92. AimingBazooka[pi] = -1;
  93. if( IsPlayerAttachedObjectSlotUsed( pi, 0 ) )
  94. RemovePlayerAttachedObject( pi, 0 );
  95. }
  96. }
  97. }
  98. }
  99.  
  100. return 1;
  101. }
  102.  
  103. public OnPlayerUpdate( playerid )
  104. {
  105. new Keys,ud,lr;
  106. GetPlayerKeys(playerid,Keys,ud,lr);
  107.  
  108. if( AimingBazooka[playerid] != -1 )
  109. {
  110. if( lr > 0 )
  111. {
  112. new Float:fA, Float:lookPos[3];
  113. GetPlayerPos( playerid, lookPos[0], lookPos[1], lookPos[2] );
  114. GetPlayerFacingAngle( playerid, fA );
  115. SetPlayerFacingAngle( playerid, fA-0.6 );
  116. BazInfo[AimingBazooka[playerid]][ba]-=0.6;
  117.  
  118. GetXYInFrontOfPoint( lookPos[0], lookPos[1], fA, MISSIL_RANGE );
  119. SetPlayerCameraLookAt( playerid, lookPos[0], lookPos[1], lookPos[2] );
  120. }
  121.  
  122. else if( lr < 0 )
  123. {
  124. new Float:fA, Float:lookPos[3];
  125. GetPlayerPos( playerid, lookPos[0], lookPos[1], lookPos[2] );
  126. GetPlayerFacingAngle( playerid, fA );
  127. SetPlayerFacingAngle( playerid, fA+0.6 );
  128. BazInfo[AimingBazooka[playerid]][ba]+=0.8;
  129.  
  130. GetXYInFrontOfPoint( lookPos[0], lookPos[1], fA, MISSIL_RANGE );
  131. SetPlayerCameraPos( playerid, BazInfo[AimingBazooka[playerid]][bx], BazInfo[AimingBazooka[playerid]][by], BazInfo[AimingBazooka[playerid]][bz]+0.8 );
  132. SetPlayerCameraLookAt( playerid, lookPos[0], lookPos[1], lookPos[2] );
  133. }
  134. }
  135.  
  136. return 1;
  137. }
  138.  
  139. public OnPlayerKeyStateChange( playerid, newkeys, oldkeys )
  140. {
  141. if( newkeys & KEY_SECONDARY_ATTACK )
  142. {
  143. if( PlacingBazooka[playerid] == 1 )
  144. {
  145. new Float:pPos[4];
  146. GetPlayerPos( playerid, pPos[0], pPos[1], pPos[2] );
  147. GetPlayerFacingAngle( playerid, pPos[3] );
  148. CreateBazooka( playerid, pPos[0], pPos[1], pPos[2], pPos[3] );
  149.  
  150. SendClientMessage( playerid, -1, "You placed a bazooka. | Press your ENTER key to enable shooting | FIRE key to shoot the bazooka |." );
  151. RemovePlayerAttachedObject( playerid, 0 );
  152. PlacingBazooka[playerid] = 0;
  153.  
  154. return 1;
  155. }
  156.  
  157. for( new i = 0; i != MAX_BAZOOKAS; i++ )
  158. {
  159. if( BazInfo[i][bCreated] == 1 )
  160. {
  161. if( IsPlayerInRangeOfPoint( playerid, 1.0, BazInfo[i][bx], BazInfo[i][by], BazInfo[i][bz] ) )
  162. {
  163. if( AimingBazooka[playerid] != -1 )
  164. {
  165. new Float:pPos[4];
  166. GetPlayerPos( playerid, pPos[0], pPos[1], pPos[2] );
  167. GetPlayerFacingAngle( playerid, pPos[3] );
  168. SetPlayerPos( playerid, pPos[0]-0.5, pPos[1]-0.5, pPos[2] );
  169.  
  170. AimingBazooka[playerid] = -1;
  171. SetCameraBehindPlayer( playerid );
  172. TogglePlayerControllable( playerid, 1 );
  173. ClearAnimations( playerid );
  174.  
  175. if( IsPlayerAttachedObjectSlotUsed( playerid, 0 ) )
  176. RemovePlayerAttachedObject( playerid, 0 );
  177.  
  178. for( new b = 0; b != MAX_BAZOOKAS; i++ )
  179. {
  180. if( BazInfo[b][bBeingUsed] == playerid )
  181. {
  182. BazInfo[b][bObject] = CreateObject( 2600, pPos[0], pPos[1], pPos[2]-0.17, 0, 0, pPos[3] );
  183. break;
  184. }
  185. }
  186.  
  187. BazInfo[i][bBeingUsed] = -1;
  188.  
  189. return 1;
  190. }
  191.  
  192. else
  193. {
  194. if( BazInfo[i][bBeingUsed] == -1 )
  195. {
  196. new Float:lookPos[4];
  197. lookPos[0] = BazInfo[i][bx]; lookPos[1] = BazInfo[i][by]; lookPos[2] = BazInfo[i][bz]; lookPos[3] = BazInfo[i][ba];
  198. DestroyObject( BazInfo[i][bObject] );
  199. AimingBazooka[playerid] = i;
  200. BazInfo[i][bBeingUsed] = playerid;
  201.  
  202. SetPlayerPos( playerid, BazInfo[i][bx], BazInfo[i][by], BazInfo[i][bz] );
  203. SetPlayerFacingAngle( playerid, BazInfo[i][ba] );
  204. TogglePlayerControllable( playerid, 0 );
  205.  
  206. GetXYInFrontOfPoint( lookPos[0], lookPos[1], BazInfo[i][ba], MISSIL_RANGE );
  207. SetPlayerCameraPos( playerid, BazInfo[i][bx], BazInfo[i][by], BazInfo[i][bz]+0.8 );
  208. SetPlayerCameraLookAt( playerid, lookPos[0], lookPos[1], lookPos[2] );
  209.  
  210. SetTimerEx( "FixAnimation", 200, false, "i", playerid );
  211. SendClientMessage( playerid, -1, "Use your left and right key to move your angle." );
  212.  
  213. if( IsPlayerAttachedObjectSlotUsed( playerid, 0 ) )
  214. RemovePlayerAttachedObject( playerid, 0 );
  215. SetPlayerAttachedObject( playerid,0,2600,6,0.227999,0.071999,-0.580999,-173.000030,-172.099990,81.000000,1.000000,1.000000,1.000000 );
  216. }
  217.  
  218. else
  219. return SendClientMessage( playerid, -1, "Somebody is already using this bazooka." );
  220. }
  221. }
  222. }
  223. }
  224. }
  225.  
  226. if( newkeys & KEY_FIRE )
  227. {
  228. for( new i = 0; i != MAX_BAZOOKAS; i++ )
  229. {
  230. if( BazInfo[i][bCreated] == 1 )
  231. {
  232. if( !IsValidObject( BazInfo[i][bMissil] ) )
  233. {
  234. if( AimingBazooka[playerid] == i )
  235. {
  236. new Float:fA;
  237. GetPlayerFacingAngle( playerid, fA );
  238.  
  239. BazInfo[i][bMissil] = CreateObject( 1636, BazInfo[i][bmx], BazInfo[i][bmy], BazInfo[i][bmz]+0.5, 0, 0, fA );
  240.  
  241. GetXYInFrontOfPoint( BazInfo[i][bmx], BazInfo[i][bmy], fA, MISSIL_RANGE );
  242.  
  243. BazInfo[i][bmz] = 0.0;
  244. GetPointZPos( BazInfo[i][bmx], BazInfo[i][bmy], BazInfo[i][bmz] ); // You can edit this line if you're not using MapAndreas RydeR's edit.
  245.  
  246. MoveObject( BazInfo[i][bMissil], BazInfo[i][bmx], BazInfo[i][bmy], BazInfo[i][bmz], FIRE_SPEED );
  247.  
  248. break;
  249. }
  250. }
  251.  
  252. else
  253. return SendClientMessage( playerid, -1, "The bazooka is reloading.." );
  254. }
  255. }
  256. }
  257.  
  258. return 1;
  259. }
  260.  
  261. public FixAnimation( playerid )
  262. {
  263. if( AimingBazooka[playerid] != -1 )
  264. {
  265. ClearAnimations( playerid );
  266. ApplyAnimation(playerid, "SHOP", "SHP_Gun_Aim", 4.0, 0, 1, 0, 1, -1);
  267. ApplyAnimation(playerid, "SHOP", "SHP_Gun_Aim", 4.0, 0, 1, 0, 1, -1);
  268. }
  269.  
  270. return 1;
  271. }
  272.  
  273. public OnObjectMoved(objectid)
  274. {
  275. for( new i = 0; i != MAX_BAZOOKAS; i++ )
  276. {
  277. if( objectid == BazInfo[i][bMissil] )
  278. {
  279. new Float:oPos[3];
  280. GetObjectPos( objectid, oPos[0], oPos[1], oPos[2] );
  281. CreateExplosion( oPos[0], oPos[1], oPos[2], 0, 10.0 );
  282. DestroyObject( objectid );
  283. BazInfo[i][bMissil] = -1;
  284.  
  285. BazInfo[i][bmx] = BazInfo[i][bx];
  286. BazInfo[i][bmy] = BazInfo[i][by];
  287. BazInfo[i][bmz] = BazInfo[i][bz];
  288.  
  289.  
  290. GetXYInFrontOfPoint( BazInfo[i][bmx], BazInfo[i][bmy], BazInfo[i][ba], 3 );
  291. break;
  292. }
  293. }
  294.  
  295. return 1;
  296. }
  297.  
  298. CMD:bazookainfo( playerid, params[] )
  299. {
  300. if( IsPlayerAdmin( playerid ) )
  301. {
  302. for( new i = 0; i != MAX_BAZOOKAS; i++ )
  303. {
  304. if( IsPlayerInRangeOfPoint( playerid, 2.0, BazInfo[i][bx], BazInfo[i][by], BazInfo[i][bz] ) )
  305. {
  306. new szString[128];
  307. format( szString, 128, "| Bazooka ID: %d | Placed By: %s |", i, BazInfo[i][bPlacedBy] );
  308. SendClientMessage( playerid, -1, szString );
  309. format( szString, 128, "| Placed in Time: %s |", BazInfo[i][bDate] );
  310. SendClientMessage( playerid, -1, szString );
  311. }
  312. }
  313. }
  314.  
  315. else
  316. return SendClientMessage( playerid, -1, "You must be logged in as RCON." );
  317.  
  318. return 1;
  319. }
  320.  
  321. CMD:placebazooka( playerid, params[] )
  322. {
  323. if( IsPlayerAttachedObjectSlotUsed( playerid, 0 ) )
  324. RemovePlayerAttachedObject( playerid, 0 );
  325.  
  326. new szName[24];
  327. GetPlayerName( playerid, szName, 24 );
  328. PlacingBazooka[playerid] = 1;
  329. SendClientMessage( playerid, -1, "Find a place you want the bazooka to be and click your ENTER key." );
  330. SetPlayerAttachedObject( playerid,0,2600,6,0.227999,0.071999,-0.580999,-173.000030,-172.099990,81.000000,1.000000,1.000000,1.000000 );
  331. SetPlayerArmedWeapon( playerid, 0 );
  332.  
  333. for( new i = 0; i != MAX_BAZOOKAS; i++ )
  334. {
  335. if( BazInfo[i][bCreated] == 1 )
  336. {
  337. if( !strcmp( BazInfo[i][bPlacedBy], szName, true ) )
  338. {
  339. BazInfo[i][bCreated] = 0;
  340. BazInfo[i][bx] = 0;
  341. BazInfo[i][by] = 0;
  342. BazInfo[i][bz] = 0;
  343. BazInfo[i][bmx] = 0;
  344. BazInfo[i][bmy] = 0;
  345. BazInfo[i][bmz] = 0;
  346. BazInfo[i][ba] = 0;
  347. BazInfo[i][bBeingUsed] = -1;
  348.  
  349. if( IsValidObject( BazInfo[i][bMissil] ) )
  350. DestroyObject( BazInfo[i][bMissil] );
  351.  
  352. if( IsValidObject( BazInfo[i][bObject] ) )
  353. DestroyObject( BazInfo[i][bObject] );
  354.  
  355. format( BazInfo[i][bPlacedBy], 32, "None" );
  356. format( BazInfo[i][bDate], 64, "-" );
  357. break;
  358. }
  359. }
  360. }
  361.  
  362. return 1;
  363. }
  364.  
  365. CMD:removebazooka( playerid, params[] )
  366. {
  367. if( !IsPlayerAdmin( playerid ) )
  368. return SendClientMessage( playerid, -1, "You must be logged in as RCON." );
  369.  
  370. for( new i = 0; i != MAX_BAZOOKAS; i++ )
  371. {
  372. if( BazInfo[i][bCreated] == 1 )
  373. {
  374. if( IsPlayerInRangeOfPoint( playerid, 3.0, BazInfo[i][bx], BazInfo[i][by], BazInfo[i][bz] ) )
  375. {
  376. BazInfo[i][bCreated] = 0;
  377. BazInfo[i][bx] = 0;
  378. BazInfo[i][by] = 0;
  379. BazInfo[i][bz] = 0;
  380. BazInfo[i][bmx] = 0;
  381. BazInfo[i][bmy] = 0;
  382. BazInfo[i][bmz] = 0;
  383. BazInfo[i][ba] = 0;
  384. BazInfo[i][bBeingUsed] = -1;
  385.  
  386. if( IsValidObject( BazInfo[i][bMissil] ) )
  387. DestroyObject( BazInfo[i][bMissil] );
  388.  
  389. if( IsValidObject( BazInfo[i][bObject] ) )
  390. DestroyObject( BazInfo[i][bObject] );
  391.  
  392. format( BazInfo[i][bPlacedBy], 32, "None" );
  393. format( BazInfo[i][bDate], 64, "-" );
  394. SendClientMessage( playerid, -1, "You succesfully removed your nearest bazooka." );
  395. break;
  396. }
  397.  
  398. else
  399. return SendClientMessage( playerid, -1, "You're not near any bazooka." );
  400. }
  401. }
  402.  
  403. return 1;
  404. }
  405.  
  406. stock GetXYInFrontOfPoint(&Float:x, &Float:y, Float:angle, Float:distance) {
  407. x += (distance * floatsin(-angle, degrees));
  408. y += (distance * floatcos(-angle, degrees));
  409. }
  410.  
  411. stock CreateBazooka( playerid, Float:x, Float:y, Float:z, Float:a )
  412. {
  413. for( new i = 0; i != MAX_BAZOOKAS; i++ )
  414. {
  415. if( BazInfo[i][bCreated] == 0 )
  416. {
  417. new szName[24];
  418. GetPlayerName( playerid, szName, 24 );
  419. BazInfo[i][bCreated] = 1;
  420. BazInfo[i][bx] = x+0.5;
  421. BazInfo[i][by] = y+0.5;
  422. BazInfo[i][bz] = z-0.17;
  423.  
  424. BazInfo[i][bmx] = x;
  425. BazInfo[i][bmy] = y;
  426. BazInfo[i][bmz] = z-0.17;
  427. GetXYInFrontOfPoint( BazInfo[i][bmx], BazInfo[i][bmy], BazInfo[i][ba], 1.3 );
  428. BazInfo[i][ba] = a;
  429.  
  430. BazInfo[i][bBeingUsed] = -1;
  431. BazInfo[i][bMissil] = -1;
  432. BazInfo[i][bObject] = CreateObject( 2600, BazInfo[i][bx], BazInfo[i][by], BazInfo[i][bz], 0, 0, a);
  433. format( BazInfo[i][bPlacedBy], 32, "%s", szName );
  434.  
  435. new year, month, day, hour, minute, second;
  436. gettime( hour, minute, second );
  437. getdate( year, month, day );
  438. format( BazInfo[i][bDate], 64, "date: %d-%d-%d | time: %d-%d-%d", year, month, day, hour, minute, second );
  439. break;
  440. }
  441. else
  442. continue;
  443. }
  444. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement