Guest User

Untitled

a guest
Aug 23rd, 2010
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.56 KB | None | 0 0
  1. // Do not remove credits (c) Luksa
  2. // Thanks to: Y_Less
  3.  
  4. #include <a_samp>
  5. #include <foreach>
  6. #pragma tabsize 0
  7.  
  8. public OnFilterScriptInit()
  9. {
  10.     print("\n--------------------------------------");
  11.     print(" Gun System - By Luksa");
  12.     print("--------------------------------------\n");
  13.     return 1;
  14. }
  15.  
  16. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  17. {
  18.     if ((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE))
  19.     {
  20.         foreach (Player, i)
  21.         {
  22.                 if(i != playerid)
  23.                 {
  24.                     if(IsPlayerAimingAtPlayer(playerid,i) && GetPlayerWeapon(playerid) == 23 && GetDistanceBetweenPlayers(playerid,i) < 50)
  25.                     {
  26.                         new Float:health;
  27.                         GetPlayerHealth(i, health);
  28.                         SetPlayerHealth(i, health - 50.0);
  29.                     }
  30.                     else if(IsPlayerAimingAtPlayer(playerid,i) && GetPlayerWeapon(playerid) == 25 && GetDistanceBetweenPlayers(playerid,i) < 50)
  31.                     {
  32.                         new Float:health;
  33.                         GetPlayerHealth(i, health);
  34.                         SetPlayerHealth(i, health - 200.0);
  35.                     }
  36.                     else if(IsPlayerAimingAtPlayer(playerid,i) && GetPlayerWeapon(playerid) == 24 && GetDistanceBetweenPlayers(playerid,i) < 50)
  37.                     {
  38.                         new Float:health;
  39.                         GetPlayerHealth(i, health);
  40.                         SetPlayerHealth(i, health - 5.0);
  41.                     }
  42.                     else if(IsPlayerAimingAtPlayer(playerid,i) && GetPlayerWeapon(playerid) == 24 && GetDistanceBetweenPlayers(playerid,i) < 50)
  43.                     {
  44.                         new Float:health;
  45.                         GetPlayerHealth(i, health);
  46.                         SetPlayerHealth(i, health - 5.0);
  47.                     }
  48.                     else if(IsPlayerAimingAtPlayer(playerid,i) && GetPlayerWeapon(playerid) == 27 && GetDistanceBetweenPlayers(playerid,i) < 50)
  49.                     {
  50.                         new Float:health;
  51.                         GetPlayerHealth(i, health);
  52.                         SetPlayerHealth(i, health - 100.0);
  53.                     }
  54.                     else if(IsPlayerAimingAtPlayer(playerid,i) && GetPlayerWeapon(playerid) == 29 && GetDistanceBetweenPlayers(playerid,i) < 50)
  55.                     {
  56.                         new Float:health;
  57.                         GetPlayerHealth(i, health);
  58.                         SetPlayerHealth(i, health - 22.0);
  59.                     }
  60.                     else if(IsPlayerAimingAtPlayer(playerid,i) && GetPlayerWeapon(playerid) == 30 && GetDistanceBetweenPlayers(playerid,i) < 50)
  61.                     {
  62.                         new Float:health;
  63.                         GetPlayerHealth(i, health);
  64.                         SetPlayerHealth(i, health - 21.0);
  65.                     }
  66.                     else if(IsPlayerAimingAtPlayer(playerid,i) && GetPlayerWeapon(playerid) == 31 && GetDistanceBetweenPlayers(playerid,i) < 50)
  67.                     {
  68.                         new Float:health;
  69.                         GetPlayerHealth(i, health);
  70.                         SetPlayerHealth(i, health - 25.0);
  71.                     }
  72.                     else if(IsPlayerAimingAtPlayer(playerid,i) && GetPlayerWeapon(playerid) == 34 && GetDistanceBetweenPlayers(playerid,i) < 500)
  73.                     {
  74.                         new Float:health;
  75.                         GetPlayerHealth(i, health);
  76.                         SetPlayerHealth(i, health - 200.0);
  77.                     }
  78.                     else if(IsPlayerAimingAtPlayer(playerid,i) && GetPlayerWeapon(playerid) == 8 && GetDistanceBetweenPlayers(playerid,i) < 1)
  79.                     {
  80.                         new Float:health;
  81.                         GetPlayerHealth(i, health);
  82.                         SetPlayerHealth(i, health - 200.0);
  83.                     }
  84.                 }
  85.         }
  86.         return 1;
  87.     }
  88.     return 1;
  89. }
  90.  
  91. stock IsPlayerAimingAtPlayer(playerid, targetid) {
  92.  new Float:x, Float:y, Float:z;
  93.  GetPlayerPos(targetid, x, y, z);
  94.  if (IsPlayerAimingAt(playerid, x, y, z-0.75, 0.25)) return true;
  95.  if (IsPlayerAimingAt(playerid, x, y, z-0.25, 0.25)) return true;
  96.  if (IsPlayerAimingAt(playerid, x, y, z+0.25, 0.25)) return true;
  97.  if (IsPlayerAimingAt(playerid, x, y, z+0.75, 0.25)) return true;
  98.  return false;
  99. }
  100.  
  101. Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ) {
  102.  
  103.     new Float:TGTDistance;
  104.  
  105.     TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
  106.  
  107.     new Float:tmpX, Float:tmpY, Float:tmpZ;
  108.  
  109.     tmpX = FrX * TGTDistance + CamX;
  110.     tmpY = FrY * TGTDistance + CamY;
  111.     tmpZ = FrZ * TGTDistance + CamZ;
  112.  
  113.     return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
  114. }
  115.  
  116. stock Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y) {
  117.  
  118.   new Float:DX, Float:DY;
  119.   new Float:angle;
  120.  
  121.   DX = floatabs(floatsub(x2,X));
  122.   DY = floatabs(floatsub(y2,Y));
  123.  
  124.   if (DY == 0.0 || DX == 0.0) {
  125.     if(DY == 0 && DX > 0) angle = 0.0;
  126.     else if(DY == 0 && DX < 0) angle = 180.0;
  127.     else if(DY > 0 && DX == 0) angle = 90.0;
  128.     else if(DY < 0 && DX == 0) angle = 270.0;
  129.     else if(DY == 0 && DX == 0) angle = 0.0;
  130.   }
  131.   else {
  132.     angle = atan(DX/DY);
  133.  
  134.     if(X > x2 && Y <= y2) angle += 90.0;
  135.     else if(X <= x2 && Y < y2) angle = floatsub(90.0, angle);
  136.     else if(X < x2 && Y >= y2) angle -= 90.0;
  137.     else if(X >= x2 && Y > y2) angle = floatsub(270.0, angle);
  138.   }
  139.  
  140.   return floatadd(angle, 90.0);
  141. }
  142.  
  143. stock GetXYInFrontOfPoint(&Float:x, &Float:y, Float:angle, Float:distance) {
  144.     x += (distance * floatsin(-angle, degrees));
  145.     y += (distance * floatcos(-angle, degrees));
  146. }
  147.  
  148. stock IsPlayerAimingAt(playerid, Float:x, Float:y, Float:z, Float:radius) {
  149.   new Float:camera_x,Float:camera_y,Float:camera_z,Float:vector_x,Float:vector_y,Float:vector_z;
  150.   GetPlayerCameraPos(playerid, camera_x, camera_y, camera_z);
  151.   GetPlayerCameraFrontVector(playerid, vector_x, vector_y, vector_z);
  152.  
  153.     new Float:vertical, Float:horizontal;
  154.  
  155.     switch (GetPlayerWeapon(playerid)) {
  156.       case 34,35,36: {
  157.       if (DistanceCameraTargetToLocation(camera_x, camera_y, camera_z, x, y, z, vector_x, vector_y, vector_z) < radius) return true;
  158.       return false;
  159.       }
  160.       case 30,31: {vertical = 4.0; horizontal = -1.6;}
  161.       case 33: {vertical = 2.7; horizontal = -1.0;}
  162.       default: {vertical = 6.0; horizontal = -2.2;}
  163.     }
  164.  
  165.   new Float:angle = GetPointAngleToPoint(0, 0, floatsqroot(vector_x*vector_x+vector_y*vector_y), vector_z) - 270.0;
  166.   new Float:resize_x, Float:resize_y, Float:resize_z = floatsin(angle+vertical, degrees);
  167.   GetXYInFrontOfPoint(resize_x, resize_y, GetPointAngleToPoint(0, 0, vector_x, vector_y)+horizontal, floatcos(angle+vertical, degrees));
  168.  
  169.   if (DistanceCameraTargetToLocation(camera_x, camera_y, camera_z, x, y, z, resize_x, resize_y, resize_z) < radius) return true;
  170.   return false;
  171. }
  172.  
  173. forward Float:GetDistanceBetweenPlayers(p1,p2);
  174. public Float:GetDistanceBetweenPlayers(p1,p2)
  175. {
  176.     new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
  177.     if(!IsPlayerConnected(p1) || !IsPlayerConnected(p2))
  178.     {
  179.         return -1.00;
  180.     }
  181.     GetPlayerPos(p1,x1,y1,z1);
  182.     GetPlayerPos(p2,x2,y2,z2);
  183.     return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
  184. }
Advertisement
Add Comment
Please, Sign In to add comment