Advertisement
Southclaw

Southclaw's Simple Item Script (v0.1)

Aug 24th, 2012
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.43 KB | None | 0 0
  1. #include <a_samp>
  2. #include <YSI\y_va>
  3. #include <YSI\y_timers>
  4. #include <formatex>
  5. #include <foreach>
  6. #include "../scripts/System/PlayerFunctions.pwn"
  7. #include <zcmd>
  8. #include <streamer>
  9. #include <colours>
  10.  
  11. #undef MAX_PLAYERS
  12. #define MAX_PLAYERS 16
  13.  
  14.  
  15. #define MAX_ITEMS           (8)
  16. #define ITM_ATTACH_INDEX    (0)
  17. #define ITM_ATTACH_BONE     (6)
  18.  
  19.  
  20. enum E_BOTTLE_DATA
  21. {
  22.     itm_objId,
  23.     itm_area,
  24.     itm_model,
  25.     Float:itm_posX,
  26.     Float:itm_posY,
  27.     Float:itm_posZ,
  28. }
  29.  
  30. new
  31.             itm_Data            [MAX_ITEMS][E_BOTTLE_DATA],
  32.             itm_Models          [5] = {1486, 1543, 1544, 1950, 1951},
  33. Iterator:   itm_Index<MAX_ITEMS>;
  34.  
  35. new
  36.             itm_Holding         [MAX_PLAYERS],
  37. Timer:      itm_InteractTimer   [MAX_PLAYERS],
  38. bool:       itm_Interacting     [MAX_PLAYERS];
  39.  
  40. AddItem(model, Float:x, Float:y, Float:z, Float:rx = 0.0, Float:ry = 0.0, Float:rz = 0.0)
  41. {
  42.     new id = Iter_Free(itm_Index);
  43.    
  44.     itm_Data[id][itm_model] = model;
  45.     itm_Data[id][itm_posX]  = x;
  46.     itm_Data[id][itm_posY]  = y;
  47.     itm_Data[id][itm_posZ]  = z;
  48.  
  49.     itm_Data[id][itm_objId] = CreateDynamicObject(itm_Data[id][itm_model], x, y, z, rx, ry, rz);
  50.     itm_Data[id][itm_area]  = CreateDynamicSphere(x, y, z+0.8568, 1.0);
  51.  
  52.     Iter_Add(itm_Index, id);
  53.     return id;
  54. }
  55. RemoveItem(id)
  56. {
  57.     DestroyDynamicObject(itm_Data[id][itm_objId]);
  58.     DestroyDynamicArea(itm_Data[id][itm_area]);
  59.  
  60.     itm_Data[id][itm_posX] = 0.0;
  61.     itm_Data[id][itm_posY] = 0.0;
  62.     itm_Data[id][itm_posZ] = 0.0;
  63.  
  64.     Iter_Remove(itm_Index, id);
  65. }
  66.  
  67. public OnFilterScriptInit()
  68. {
  69.     AddItem(itm_Models[random(sizeof(itm_Models))], 2108.67, -1875.41, 12.69);
  70.    
  71.     for(new i;i<MAX_PLAYERS;i++)
  72.     {
  73.         itm_Holding[i] = -1;
  74.     }
  75. }
  76.  
  77. public OnPlayerEnterDynamicArea(playerid, areaid)
  78. {
  79.     foreach(new i : itm_Index)
  80.     {
  81.         if(areaid == itm_Data[i][itm_area])
  82.         {
  83.             CallRemoteFunction("sffa_msgbox", "dsdd", playerid, "Hold F to pick up", 1000, 130);
  84.         }
  85.     }
  86. }
  87.  
  88. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  89. {
  90.     if(itm_Interacting[playerid])
  91.     {
  92.         ClearAnimations(playerid);
  93.         stop itm_InteractTimer[playerid];
  94.     }
  95.     if(newkeys & 16 && GetPlayerAnimationIndex(playerid) == 1189)
  96.     {
  97.         if(itm_Holding[playerid] != -1)
  98.         {
  99.             ApplyAnimation(playerid, "BOMBER", "BOM_PLANT_IN", 5.0, 1, 0, 0, 0, 400);
  100.             itm_InteractTimer[playerid] = defer PutDownItem(playerid);
  101.         }
  102.         else
  103.         {
  104.             foreach(new i : itm_Index)
  105.             {
  106.                 if(IsPlayerInDynamicArea(playerid, itm_Data[i][itm_area]))
  107.                 {
  108.                     ApplyAnimation(playerid, "BOMBER", "BOM_PLANT_IN", 5.0, 0, 0, 0, 0, 400);
  109.                     itm_InteractTimer[playerid] = defer PickUpItem(playerid, i);
  110.                     itm_Interacting[playerid] = true;
  111.                 }
  112.             }
  113.         }
  114.     }
  115. }
  116.  
  117. timer PickUpItem[400](playerid, id)
  118. {
  119.     RemoveItem(id);
  120.     ApplyAnimation(playerid, "BOMBER", "BOM_PLANT_2IDLE", 4.0, 0, 0, 0, 0, 0);
  121.     SetPlayerAttachedObject(
  122.         playerid, ITM_ATTACH_INDEX, itm_Data[id][itm_model], ITM_ATTACH_BONE,
  123.         0.0, 0.0, 0.0,
  124.         0.0, 0.0, 0.0);
  125.  
  126.     itm_Holding[playerid] = id;
  127.     itm_Interacting[playerid] = false;
  128. }
  129.  
  130. timer PutDownItem[400](playerid)
  131. {
  132.     new
  133.         Float:x,
  134.         Float:y,
  135.         Float:z,
  136.         Float:r;
  137.  
  138.     GetPlayerPos(playerid, x, y, z);
  139.     GetPlayerFacingAngle(playerid, r);
  140.     AddItem(itm_Data[itm_Holding[playerid]][itm_model],
  141.         x + (0.5 * floatsin(-r, degrees)),
  142.         y + (0.5 * floatcos(-r, degrees)), z-0.8568);
  143.  
  144.     ApplyAnimation(playerid, "BOMBER", "BOM_PLANT_2IDLE", 4.0, 0, 0, 0, 0, 0);
  145.     RemovePlayerAttachedObject(playerid, ITM_ATTACH_INDEX);
  146.  
  147.     itm_Holding[playerid] = -1;
  148.     itm_Interacting[playerid] = false;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement