Advertisement
Guest User

Untitled

a guest
Dec 9th, 2022
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1.  
  2. local isReloading=false; local bullets_fired=0; local last_fired = 0;
  3.  
  4. SetTimerEx( "ShootPlayer", 60, 0, pid );
  5.  
  6. function ShootPlayer( pid )
  7. {
  8. if( IsPlayerStreamedIn( pid ) && GetPlayerState(pid) != PLAYER_STATE_WASTED )
  9. {
  10. local pos = GetPlayerPos( pid );
  11.  
  12. local weapon = GetPlayerArmedWeapon( npcid );
  13.  
  14. if( GetDistanceFromMeToPoint( pos ) < 90.0 )
  15. {
  16. local now = GetTickCount();
  17.  
  18. if( !isReloading || now - last_fired >= 1000 )
  19. {
  20. isReloading = false;
  21.  
  22. /* Checking interval between 2 bullets. In milliseconds. */
  23.  
  24. if( now - last_fired >= 150 ) // 150ms is firing rate of rifle ruger
  25. {
  26. //Decrease Ammo by One.
  27.  
  28. local NewAmmo = GetLocalValue(I_CURWEP_AMMO) - 1;
  29.  
  30. if( NewAmmo <= 0 )
  31. NewAmmo = 1; //fool the server
  32.  
  33. SetLocalValue( I_CURWEP_AMMO, NewAmmo );
  34.  
  35. ShootAt( pos );
  36.  
  37. bullets_fired++;
  38.  
  39. if( bullets_fired % 30 == 0 ) //rifle has 30 bullets in one catridge
  40. isReloading = true;
  41.  
  42. last_fired = now; //Store tick
  43.  
  44. }else
  45. {
  46. //Send a packet, same as last one. ( for Sync Issues )
  47. SendOnFootSyncDataLV();
  48. }
  49. }else
  50. {
  51. //still reloading... Call function 'ShootAt' with 'isReloading' as 'true'
  52. ShootAt( pos, true );
  53. }
  54. }
  55. }
  56. }
  57. function ShootAt(tPos, isReloading = false, isHeadShot=false)
  58. {
  59. if(isHeadShot)
  60. tPos.z+=0.627299;
  61. local Pos= GetMyPos();
  62. local angle= atan2(-(tPos.x-Pos.x), tPos.y-Pos.y);
  63. local aimPos= Vector(tPos.x,tPos.y,tPos.z);
  64. local aimDir = Vector( PI, PI, -angle );
  65. SendOnFootSyncData( KEY_ONFOOT_FIRE, Pos.x,Pos.y, Pos.z, angle, GetPlayerHealth( npcid ), GetPlayerArmour( npcid ), GetPlayerArmedWeapon( npcid ),GetLocalValue(I_CURWEP_AMMO ), 0.0, 0.0, 0.0, aimPos.x, aimPos.y, aimPos.z, PI, PI, -angle, false, isReloading );
  66. }
  67. function OnNPCConnect(myplayerid)
  68. {
  69. npcid<-myplayerid;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement