Advertisement
Southclaw

Southclaw's Ammo Crate Script

Jul 25th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.76 KB | None | 0 0
  1. #include <a_samp>
  2. #include <foreach>
  3. #include <YSI\y_timers>
  4. #include <streamer>
  5.  
  6. #undef MAX_PLAYERS
  7. #define MAX_PLAYERS 16
  8.  
  9. #define MAX_AMMO_CRATE 16
  10.  
  11.  
  12. new
  13.     gCrateObj           [MAX_AMMO_CRATE],
  14.     Float:gCratePos     [MAX_AMMO_CRATE][3],
  15.     gCrateArea          [MAX_AMMO_CRATE],
  16.     Iterator:gCrateTable<MAX_AMMO_CRATE>,
  17.     gCrateTick          [MAX_PLAYERS],
  18.     Timer:gCrateTimer   [MAX_PLAYERS],
  19.     gUsingCrate         [MAX_PLAYERS];
  20.  
  21.  
  22. public OnFilterScriptInit()
  23. {
  24.     CreateSupplyCrate(0.0, 0.0, 2.0, 90.0); // Debug
  25. }
  26.  
  27. stock CreateSupplyCrate(Float:x, Float:y, Float:z, Float:r=0.0)
  28. {
  29.     new
  30.         id = Iter_Free(gCrateTable);
  31.  
  32.     gCrateObj[id]   = CreateDynamicObject(964, x, y, z, 0, 0, r);
  33.     gCrateArea[id]  = CreateDynamicSphere(x, y, z, 1.0);
  34.     gCratePos[id][0]    = x,
  35.     gCratePos[id][1] = y,
  36.     gCratePos[id][2] = z;
  37.  
  38.     Iter_Add(gCrateTable, id);
  39.  
  40.     return id;
  41. }
  42.  
  43.  
  44. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  45. {
  46.     if(newkeys & 16) // 16 = F/Enter
  47.     {
  48.         for(new x;x<MAX_AMMO_CRATE;x++)
  49.         {
  50.             if(
  51.                 IsPlayerInRangeOfPoint(playerid, 2.0, gCratePos[x][0], gCratePos[x][1], gCratePos[x][2]) &&
  52.                 GetTickCount() - gCrateTick[playerid] > 30000) // Only works every 30s
  53.             {
  54.                 Crate_Use(playerid);
  55.                 break;
  56.             }
  57.         }
  58.     }
  59.     if(oldkeys & 16 && gUsingCrate[playerid]) // When the release the key
  60.     {
  61.         ClearAnimations(playerid);
  62.         stop gCrateTimer[playerid];
  63.     }
  64. }
  65.  
  66. Crate_Use(playerid)
  67. {
  68.     ApplyAnimation(playerid, "bomber", "bom_Plant", 1.0, 1, 0, 0, 0, 0);
  69.     gCrateTimer[playerid] = defer Crate_Refil(playerid);
  70.     gUsingCrate[playerid] = true;
  71. }
  72.  
  73. timer Crate_Refil[2000](playerid)
  74. {
  75.     gUsingCrate[playerid] = false;
  76.     gCrateTick[playerid] = GetTickCount();
  77.     ClearAnimations(playerid);
  78.     SendClientMessage(playerid, -1, "Ammo Refilled!");
  79.     // GivePlayerWeapon(...); etc
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement