Advertisement
Guest User

Untitled

a guest
May 22nd, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. stock AngleInRangeOfAngle(Float:a1, Float:a2, Float:range)
  2. {
  3. a1 -= a2;
  4. if((a1 < range) && (a1 > -range)) return true;
  5. return false;
  6. }
  7.  
  8. stock Float:DistanceCameraTargetToLocation( Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ ) {
  9.  
  10. new Float:TGTDistance;
  11. TGTDistance = floatsqroot(( CamX - ObjX ) * ( CamX - ObjX ) + ( CamY - ObjY ) * ( CamY - ObjY ) + ( CamZ - ObjZ ) * ( CamZ - ObjZ ));
  12. new Float:tmpX, Float:tmpY, Float:tmpZ;
  13.  
  14. tmpX = FrX * TGTDistance + CamX;
  15. tmpY = FrY * TGTDistance + CamY;
  16. tmpZ = FrZ * TGTDistance + CamZ;
  17.  
  18. return floatsqroot(( tmpX - ObjX ) * ( tmpX - ObjX ) + ( tmpY - ObjY ) * ( tmpY - ObjY ) + ( tmpZ - ObjZ ) * ( tmpZ - ObjZ ));
  19. }
  20.  
  21. stock Float:GetPointAngleToPoint( Float:x2, Float:y2, Float:_X, Float:_Y )
  22. {
  23.  
  24. new Float:DX, Float:DY;
  25. new Float:angle;
  26.  
  27. DX = floatabs( floatsub( x2,_X ));
  28. DY = floatabs( floatsub( y2,_Y ));
  29.  
  30. if( DY == 0.0 || DX == 0.0)
  31. {
  32. if( DY == 0 && DX > 0) angle = 0.0;
  33. else if( DY == 0 && DX < 0) angle = 180.0;
  34. else if( DY > 0 && DX == 0) angle = 90.0;
  35. else if( DY < 0 && DX == 0) angle = 270.0;
  36. else if( DY == 0 && DX == 0) angle = 0.0;
  37. }
  38. else
  39. {
  40. angle = atan( DX/DY );
  41.  
  42. if( _X > x2 && _Y <= y2 ) angle += 90.0;
  43. else if( _X <= x2 && _Y < y2 ) angle = floatsub( 90.0, angle );
  44. else if( _X < x2 && _Y >= y2 ) angle -= 90.0;
  45. else if( _X >= x2 && _Y > y2 ) angle = floatsub( 270.0, angle );
  46. }
  47.  
  48. return floatadd( angle, 90.0);
  49. }
  50.  
  51. stock IsPlayerAimingAt( playerid, Float:x, Float:y, Float:z, Float:radius )
  52. {
  53. new Float:camera_x,Float:camera_y,Float:camera_z,Float:vector_x,Float:vector_y,Float:vector_z;
  54. GetPlayerCameraPos( playerid, camera_x, camera_y, camera_z );
  55. GetPlayerCameraFrontVector( playerid, vector_x, vector_y, vector_z );
  56. new Float:vertical, Float:horizontal;
  57.  
  58. switch ( GetPlayerWeapon( playerid ))
  59. {
  60. case 34,35,36:
  61. {
  62. if( DistanceCameraTargetToLocation( camera_x, camera_y, camera_z, x, y, z, vector_x, vector_y, vector_z ) < radius ) return true;
  63. return false;
  64. }
  65. case 30,31: { vertical = 4.0; horizontal = -1.6;}
  66. case 33: { vertical = 2.7; horizontal = -1.0;}
  67. default: { vertical = 6.0; horizontal = -2.2;}
  68. }
  69.  
  70. new Float:angle = GetPointAngleToPoint( 0, 0, floatsqroot( vector_x*vector_x+vector_y*vector_y ), vector_z ) - 270.0;
  71. new Float:resize_x, Float:resize_y, Float:resize_z = floatsin( angle+vertical, degrees );
  72. GetXYInFrontOfPoint( resize_x, resize_y, GetPointAngleToPoint( 0, 0, vector_x, vector_y )+horizontal, floatcos( angle+vertical, degrees ));
  73.  
  74. if( DistanceCameraTargetToLocation( camera_x, camera_y, camera_z, x, y, z, resize_x, resize_y, resize_z ) < radius ) return true;
  75. return false;
  76. }
  77.  
  78. stock IsPlayerFacingPlayer(playerid, targetid, Float:dOffset)
  79. {
  80. new
  81. Float:pX,
  82. Float:pY,
  83. Float:pZ,
  84. Float:pA,
  85. Float:X,
  86. Float:Y,
  87. Float:Z,
  88. Float:ang;
  89.  
  90. if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
  91. GetPlayerPos(targetid, pX, pY, pZ);
  92. GetPlayerPos(playerid, X, Y, Z);
  93. GetPlayerFacingAngle(playerid, pA);
  94.  
  95. if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
  96. else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
  97. else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
  98. return AngleInRangeOfAngle(-ang, pA, dOffset);
  99.  
  100. }
  101.  
  102.  
  103. public OnPlayerUpdate( playerid )
  104. {
  105. new Keys,ud,lr;
  106. GetPlayerKeys(playerid,Keys,ud,lr);
  107.  
  108. if( Keys & KEY_FIRE )
  109. {
  110. if( GetPlayerTargetPlayer( playerid ) == npc )
  111. {
  112. if( GetPlayerWeaponState( playerid ) != WEAPONSTATE_NO_BULLETS && GetPlayerWeaponState( playerid ) != WEAPONSTATE_RELOADING )
  113. {
  114. if( GetPlayerCameraMode( playerid ) == 53 )
  115. {
  116. if( IsPlayerFacingPlayer( playerid, npc, 5.0 ) )
  117. {
  118. if( IsPlayerAimingAt( playerid, x, y, z, 4.2 ) )
  119. {
  120. new Float:dmg;
  121.  
  122. // Default GTA:SA weapon damages.
  123. switch( GetPlayerWeapon( playerid ) )
  124. {
  125. case 22: dmg = 17.0;
  126. case 23: dmg = 40.0;
  127. case 24: dmg = 70.0;
  128. case 32: dmg = 20.0;
  129. case 28: dmg = 20.0;
  130. case 29: dmg = 25.0;
  131. case 25: dmg = 50.0;
  132. case 26: dmg = 40.0;
  133. case 27: dmg = 20.0;
  134. case 31: dmg = 35.0;
  135. case 30: dmg = 30.0;
  136. case 33: dmg = 70.0;
  137. case 34: dmg = 125.0;
  138. default: dmg = 30.0;
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement