Advertisement
Southclaw

SA:MP Throwing Knives

Oct 19th, 2013
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.55 KB | None | 0 0
  1. #define FILTERSCRIPT
  2.  
  3. #include <a_samp>
  4. #include <SIF/SIF>
  5. #include <strlib>
  6. #include <YSI\y_timers>
  7.  
  8.  
  9. #define KNIFE_AIR_VELOCITY  (20.0) // (20.0)
  10. #define KNIFE_STEP_DISTANCE (2.0) // (20.0)
  11. #define KNIFE_STEP_LIMIT    (10)
  12.  
  13.  
  14. stock Float:Distance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
  15.     return floatsqroot((((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))+((z1-z2)*(z1-z2))));
  16.  
  17.  
  18. new
  19. ItemType:   item_Knife              = INVALID_ITEM_TYPE;
  20.  
  21. static
  22. Timer:      PlayerKnifeUpdateTimer[MAX_PLAYERS];
  23.  
  24.  
  25. public OnFilterScriptInit()
  26. {
  27.     for(new i; i < MAX_PLAYERS; i++)
  28.         Streamer_ToggleIdleUpdate(i, true);
  29.  
  30.     item_Knife      = DefineItemType("Knife", 335, ITEM_SIZE_SMALL);
  31.  
  32.     new
  33.         Float:x,
  34.         Float:y,
  35.         Float:z;
  36.  
  37.     GetPlayerPos(0, x, y, z);
  38.  
  39.     CreateItem(item_Knife, x, y, z - 0.8);
  40.  
  41.     return 1;
  42. }
  43.  
  44. public OnPlayerConnect(playerid)
  45. {
  46.     Streamer_ToggleIdleUpdate(playerid, true);
  47.  
  48.     return 1;
  49. }
  50.  
  51. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  52. {
  53.     if(newkeys & KEY_FIRE)
  54.     {
  55.         new
  56.             itemid,
  57.             ItemType:itemtype;
  58.  
  59.         itemid = GetPlayerItem(playerid);
  60.         itemtype = GetItemType(itemid);
  61.  
  62.         if(itemtype == item_Knife)
  63.         {
  64.             new
  65.                 Float:x,
  66.                 Float:y,
  67.                 Float:z,
  68.                 Float:angle,
  69.                 objectid;
  70.  
  71.             GetPlayerPos(playerid, x, y, z);
  72.             GetPlayerFacingAngle(playerid, angle);
  73.  
  74.             // Uncomment below to make knives consumable.
  75.             // Comment to make them infinite
  76.             DestroyItem(itemid);
  77.  
  78.             objectid = CreateDynamicObject(335, x, y, z + 0.3, 0.0, 0.0, angle + 90.0);
  79.  
  80.             ApplyAnimation(playerid, "GRENADE", "WEAPON_throw", 4.0, 0, 0, 0, 0, 0);
  81.  
  82.             PlayerKnifeUpdateTimer[playerid] = defer UpdateKnife(playerid, objectid, 0, 0, 100, angle);
  83.         }
  84.     }
  85. }
  86.  
  87. timer UpdateKnife[c](playerid, objectid, a, b, c, Float:heading)
  88. {
  89.     new
  90.         Float:x,
  91.         Float:y,
  92.         Float:z,
  93.         Float:rx,
  94.         Float:ry,
  95.         Float:rz;
  96.  
  97.     GetDynamicObjectPos(objectid, x, y, z);
  98.     GetDynamicObjectRot(objectid, rx, ry, rz);
  99.  
  100.     c = MoveDynamicObject(objectid,
  101.         x + (KNIFE_STEP_DISTANCE * floatsin(-heading, degrees)),
  102.         y + (KNIFE_STEP_DISTANCE * floatcos(-heading, degrees)),
  103.         z - 0.1, // Gravity
  104.         KNIFE_AIR_VELOCITY,
  105.         0.0,
  106.         ry + 179.0,
  107.         heading + 90.0);
  108.  
  109.     if(b < KNIFE_STEP_LIMIT) // knife flies for KNIFE_STEP_LIMIT * 100 milliseconds.
  110.     {
  111.         a = !a;
  112.         b++;
  113.         PlayerKnifeUpdateTimer[playerid] = defer UpdateKnife(playerid, objectid, a, b, c, heading);
  114.     }
  115.     else
  116.     {
  117.         DestroyDynamicObject(objectid);
  118.         CreateItem(item_Knife, x, y, z);
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement