container.lua

main 49 lines · 966 bytes Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1function Container.isContainer(self)
2 return true
3end
4
5function Container.createLootItem(self, item)
6 if self:getEmptySlots() == 0 then
7 return true
8 end
9
10 local itemCount = 0
11 local randvalue = getLootRandom()
12 if randvalue < item.chance then
13 if ItemType(item.itemId):isStackable() then
14 itemCount = randvalue % item.maxCount + 1
15 else
16 itemCount = 1
17 end
18 end
19
20 if itemCount > 0 then
21 local tmpItem = self:addItem(item.itemId, math.min(itemCount, 100))
22 if not tmpItem then
23 return false
24 end
25
26 if tmpItem:isContainer() then
27 for i = 1, #item.childLoot do
28 if not tmpItem:createLootItem(item.childLoot[i]) then
29 tmpItem:remove()
30 return false
31 end
32 end
33 end
34
35 if item.subType ~= -1 then
36 tmpItem:setAttribute(ITEM_ATTRIBUTE_CHARGES, item.subType)
37 end
38
39 if item.actionId ~= -1 then
40 tmpItem:setActionId(item.actionId)
41 end
42
43 if item.text and item.text ~= "" then
44 tmpItem:setText(item.text)
45 end
46 end
47 return true
48end
49
Top