athenso
Average Coder
- Joined
- May 31, 2011
- Messages
- 155
- Solutions
- 3
- Reaction score
- 24
I am looking for a global loot script, that i can have a table of items and counts that I can add to that will adjust the drop rate for all creatures. I want to use it for seasonal events, it would be a lot quicker than just editing the files individually.
I have tried
I have tried this script and I dont like that i have to add every monster, and the script is not working. It is not throwing an error either so I am not sure where to look. My knowledge of tables is very small.
I have tried
Code:
local extra_loot = {
{hasName = "Dragon", items = {
{id = 2688, count = 1, chance = 400000,}, -- 40%
{id = 2160, countMax = 4, chance = 10000}
}},
{hasName = "Rotworm", items = {
{id = 2688, count = 1, chance = 20000,}, -- 20%
{id = 2160, countMax = 4, chance = 10000}
}},
{hasName = "Dwarf", items = {
{id = 2688, count = 1, chance = 20000,}, -- 20%
{id = 2160, countMax = 4, chance = 10000}
}},
{items = {
{id = 2365, chance = 10000},
{id = 2392, chance = 1000}
}},
}
function Container:addExtraLoot(c, t)
if t.hasName then
local cn = c:getName():lower()
local cm = t.hasName:lower()
if not cn:match(cm) then
return true
end
end
for i = 1, #t.items do
local count = 1
if t.items[i].count then
if t.items[i].countMax then
count = math.random(t.items[i].count, t.items[i].countMax)
else
count = t.items[i].count
end
else
if t.items[i].countMax then
count = math.random(1, t.items[i].countMax)
end
end
if math.random(0, 100000) <= t.items[i].chance then
self:addItem(t.items[i].id, count)
end
end
end
function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
if not creature:isMonster() then return true end
if corpse and corpse:isContainer() then
for i = 1, #extra_loot do
corpse:addExtraLoot(creature, extra_loot[i])
end
end
return true
end
I have tried this script and I dont like that i have to add every monster, and the script is not working. It is not throwing an error either so I am not sure where to look. My knowledge of tables is very small.