zbizu
Legendary OT User
Based on @Eldin 's request
It adds items randomly to killed monsters. Configurable group of monsters and chance
events.xml
(this line exist in your file already, just set enabled to "1")
creature.lua event
below:
add:
creaturescripts.xml
extra_loot.lua creaturescript
It adds items randomly to killed monsters. Configurable group of monsters and chance
events.xml
(this line exist in your file already, just set enabled to "1")
Code:
<event class="Creature" method="onTargetCombat" enabled="1" />
creature.lua event
below:
Code:
function Creature:onTargetCombat(target)
Code:
if not self then return true end
if self:isPlayer() and target:isMonster() then
target:registerEvent("extra_loot_d")
end
creaturescripts.xml
Code:
<event type="death" name="extra_loot_d" script="extra_loot.lua"/>
extra_loot.lua creaturescript
Code:
local extra_loot = {
{hasName = "dragon", items = {
{id = 2152, count = 2, chance = 40000}, -- 40%
{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
Last edited: