Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local inventory={items={}}
- local elementInventories={}
- function inventory:addItem(item,count)
- if count<=0 then
- outputDebugString("Error at iventory:addItem(), can't add negative ammount of tiems")
- return false
- end
- if self.items[item]==nil then
- self.items[item]=0
- end
- self.items[item]=self.items[item]+count
- return true
- end
- function inventory:takeItem(item,count)
- local itemCount=self.items[item]
- if itemCount==nil or itemCount<count then
- outputDebugString("Error at iventory:takeItem(), Not enough "..item.." in inventory.")
- return false,itemCount
- end
- self.items[item]=self.items[item]-count
- return true
- end
- function inventory:hasItems(item,count)
- local itemCount=self.items[item]
- if itemCount==nil then
- return 0
- end
- return itemCount
- end
- function inventory:getAllItems()
- return self.items
- end
- function setElementInventory(element)
- local inv={}
- for id,data in pairs(inventory) do
- outputChatBox(id..","..type(data))
- inv[id]=data
- end
- elementInventories[element]=inv
- end
- function getElementInventory(element)
- if elementInventories[element]==nil then
- setElementInventory(element)
- end
- return elementInventories[element]
- end
- local vehicle=createVehicle(463,0,0,3)
- local inv=getElementInventory(vehicle)
- inv:addItem("Weed",5)
- inv:takeItem("Weed",3)
- outputDebugString(toJSON(inv:getAllItems()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement