Advertisement
Guest User

Throwing knife

a guest
Oct 8th, 2014
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.97 KB | None | 0 0
  1. new FireShot[MAX_PLAYERS];
  2. new gKnifeObj[MAX_PLAYERS];
  3.  
  4. public OnPlayerCommandText(playerid, cmdtext[])
  5. {
  6.     if (strcmp("/knife", cmdtext, true, 6) == 0)
  7.     {
  8.         GivePlayerWeapon(playerid, 4, 1);
  9.     }
  10.     return 1;
  11. }
  12.  
  13.  
  14.  
  15. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  16. {
  17.     if(GetPlayerWeapon(playerid) == 4 && FireShot[playerid] == 0 && (newkeys & KEY_AIM) && !IsValidObject(gKnifeObj[playerid]))
  18.     {
  19.         ApplyAnimation(playerid,"GRENADE","WEAPON_throw",4.1,0,0,0,1,1,1);
  20.         ApplyAnimation(playerid,"GRENADE","WEAPON_throw",4.1,0,0,0,1,1,1);
  21.         new
  22.             Float:x,
  23.             Float:y,
  24.             Float:z,
  25.             Float:r,
  26.             Float:HP,
  27.             Float:dist = 50.0,
  28.             Float:tmpang,
  29.             Float:tmpx,
  30.             Float:tmpy,
  31.             Float:tmpz;
  32.            
  33.  
  34.         FireShot[playerid] = 1;
  35.         SetTimerEx("ShotFire", 1000, 0, "i", playerid);
  36.         GetPlayerPos(playerid, x, y, z);
  37.         GetPlayerFacingAngle(playerid, r);
  38.         gKnifeObj[playerid] = CreateObject(335, x, y, z+0.7, -90, 0, r);
  39.         for(new i;i<MAX_PLAYERS;i++)
  40.         {
  41.             if(i == playerid)continue;
  42.             if(IsPlayerInRangeOfPoint(i, 50.0, x, y, z))
  43.             {
  44.                 GetPlayerPos(i, tmpx, tmpy, tmpz);
  45.  
  46.                 tmpang = (90-atan2(tmpy-y, tmpx-x));
  47.                 if(tmpang < 0)tmpang = 360.0+tmpang;
  48.                 tmpang = 360.0 - tmpang;
  49.                 if(floatabs(tmpang-r) < 5.0)
  50.                 {
  51.                     dist = GetPlayerDistanceFromPoint(i, x, y, z);
  52.                     GetPlayerHealth(i, HP);
  53.                     SetPlayerHealth(i, HP-35);
  54.                 }
  55.             }
  56.         }
  57.         MoveObject(gKnifeObj[playerid],x + (dist * floatsin(-r, degrees)),y + (dist * floatcos(-r, degrees)),z,20);                             // Nice and fast!
  58.     }
  59.     return 1
  60. }
  61.  
  62.  
  63.  
  64. forward ShotFire(playerid);
  65. public ShotFire(playerid)
  66. {
  67.     FireShot[playerid] = 0;
  68.     return 1;
  69. }
  70.  
  71.  
  72.  
  73. public OnObjectMoved(objectid)
  74. {
  75.     for(new i;i<MAX_PLAYERS;i++)
  76.     {
  77.         if(objectid == gKnifeObj[i])
  78.         {
  79.             new
  80.                 Float:x,
  81.                 Float:y,
  82.                 Float:z;
  83.  
  84.             GetObjectPos(gKnifeObj[i], x, y, z);
  85.             DestroyObject(gKnifeObj[i]);
  86.         }
  87.     }
  88.     return 1;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement