SHARE
TWEET

Untitled

a guest Mar 12th, 2019 30 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local ITEM = Clockwork.item:New();
  2.  
  3. ITEM.name = "Tall Drawers";
  4. ITEM.uniqueID = "talldrawers3";
  5. ITEM.model = "models/props_c17/FurnitureDrawer003a.mdl";
  6. ITEM.plural = "Tall Drawers";
  7. ITEM.weight = 4;
  8. ITEM.category = "Furniture";
  9. ITEM.batch = 1;
  10. ITEM.useText = "Open";
  11. ITEM.description = "Tall drawers. I wouldn't put anything heavy in here as it looks like it might collapse out of misery alone.";
  12. ITEM.storageSpace = 6;
  13.  
  14. ITEM:AddData("Inventory", nil);
  15. ITEM:AddData("Cash", 0);
  16.  
  17. function ITEM:OnSaved(newData)
  18.     if (newData["Inventory"] != nil) then
  19.         newData["Inventory"] = Clockwork.inventory:ToSaveable(newData["Inventory"]);
  20.        
  21.         if (CloudAuthX.Base64Encode) then
  22.             newData["Inventory"] = "@"..CloudAuthX.Base64Encode(newData["Inventory"]);
  23.         end;
  24.     end;
  25. end;
  26.  
  27. function ITEM:OnLoaded()
  28.     local inventory = self("Inventory");
  29.    
  30.     if (inventory != nil) then
  31.         if (CloudAuthX.Base64Decode and string.utf8sub(inventory, 1, 1) == "@") then
  32.             inventory = CloudAuthX.Base64Decode(string.utf8sub(inventory, 2));
  33.         end;
  34.        
  35.         self:SetData("Inventory", Clockwork.inventory:ToLoadable(inventory));
  36.     end;
  37. end;
  38.  
  39. if (SERVER) then
  40.     function ITEM:GetInventory()
  41.         local inventory = self:GetData("Inventory");
  42.        
  43.         if (inventory == nil) then
  44.             self:SetData("Inventory", {});
  45.         end;
  46.        
  47.         return inventory;
  48.     end;
  49.        
  50.     function ITEM:HasItem(itemTable)
  51.         if (type(itemTable) == "string") then
  52.             Clockwork.inventory:HasItemByID(self:GetInventory(), itemTable);
  53.         else
  54.             Clockwork.inventory:HasItemInstance(self:GetInventory(), itemTable);
  55.         end;
  56.     end;
  57.  
  58.     function ITEM:RemoveFromInventory(itemTable)
  59.         if (type(itemTable) == "string") then
  60.             Clockwork.inventory:RemoveUniqueID(self:GetInventory(), itemTable);
  61.         else
  62.             Clockwork.inventory:RemoveInstance(self:GetInventory(), itemTable);
  63.         end;
  64.     end;
  65.  
  66.     function ITEM:InventoryAsItemsList()
  67.         return Clockwork.inventory:GetAsItemsList(self:GetInventory());
  68.     end;
  69.  
  70.     function ITEM:AddToInventory(itemTable)
  71.         Clockwork.inventory:AddInstance(self:GetInventory(), itemTable);
  72.     end;
  73.  
  74.     function ITEM:GetCash()
  75.         return self("Cash");
  76.     end;
  77. end;
  78.  
  79. function ITEM:OnUse(player, itemEntity)
  80.     self:OpenFor(player, itemEntity);
  81.    
  82.     return false;
  83. end;
  84.  
  85. function ITEM:OpenFor(player, itemEntity)
  86.     local inventory = self:GetInventory();
  87.     local cash = self:GetCash();
  88.     local name = self("name");
  89.    
  90.     Clockwork.storage:Open(player, {
  91.         name = name,
  92.         weight = self("storageWeight"),
  93.         space = self("storageSpace"),
  94.         entity = itemEntity or false,
  95.         distance = 192,
  96.         cash = cash,
  97.         inventory = inventory,
  98.         OnGiveCash = function(player, storageTable, cash)
  99.             self:SetData("Cash", self:GetCash() + cash);
  100.         end,
  101.         OnTakeCash = function(player, storageTable, cash)
  102.             self:SetData("Cash", self:GetCash() - cash);
  103.         end
  104.     });
  105. end;
  106.  
  107. -- Called when a player drops the item.
  108. function ITEM:OnDrop(player, position) end;
  109.  
  110. ITEM:Register();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top