darkmu
Well-Known Member
CreatureEvent - [TFS 1.1] Extra loot system
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: function Creature:onTargetCombat(target) add: if not self then return true end...
otland.net
I'm trying to adapt the script above so that instead of the items go to the player, in which case I would add the item to the animal's body, could you help me?
Lua:
local extra_loot = {
{hasName = {"infernal demon", "infernal phantom", "branchy crawler", "rotten golem", "vibrant phantom", "courage leech", "cloak of terror", "turbulent elemental", "bony sea devil", "capricious phantom", "brachiodemon", "knight's apparition", "sorcerer's apparition", "paladin's apparition", "mould phantom"}, items = {
{id = 38944, count = 1, chance = 80000}, -- 4%
}}
}
function onDeath(monster, corpse, killer, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
if not monster:isMonster() or monster:getMaster() then
return true
end
if not corpse then
return false
end
local owner = mostdamagekiller
if killer and killer:isPlayer() then
owner = killer
end
local player = Player(owner)
if corpse and corpse:isContainer() then
for i = 1, #extra_loot do
corpse:addExtraLoot(player, monster, extra_loot[i])
end
end
return true
end
Lua:
function Container:addExtraLoot(self, c, t)
if t.hasName then
local cn = c:getName():lower()
local cm = t.hasName
if not isInArray(cm, cn) then
return true
end
end
local mType = c:getType()
local monsterLoot = mType:getLoot()
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