Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Item = {
- list = {}
- }
- setmetatable(Item, {
- __call = function (self, ...)
- return self:create(...)
- end
- })
- function Item:create(name, weight, category)
- if Item.list[name] then
- return Item.list[name]
- end
- local new = {
- name = name,
- weight = weight,
- category = category
- }
- setmetatable(new, {__index = Item})
- Item.list[name] = new
- return new
- end
- function Item.exists(name)
- return Item.list[name] and true or false
- end
- function Item:getWeight()
- return self.weight
- end
- function Item:setWeight(weight)
- self.weight = weight
- end
- function Item:getName()
- return self.name
- end
- function Item:getCategory()
- return self.category
- end
- function Item:setCategory(category)
- self.category = category
- end
- -- Create consumable items
- Item("Apple", 2, "Consumable")
- Item("Banana", 3, "Consumable")
- Item("Orange", 1, "Consumable")
- Item("Water", 10, "Consumable")
- Item("Cola", 8, "Consumable")
- -- Create 2 weapons
- Item("M4A1", 50, "Weapon")
- Item("MP5", 30, "Weapon")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement