Shalaby
Time has made me wiser, but no more patient.
I'm trying to print a unique message for the monsters that are in the table if the player killed, For example when I killed Archmage monster this error appear
this the script i tried so far
I guess this error is likely occurring because the createLootItem function is returning false instead of an item object. This can happen if the function fails to create the loot item for some reason I don't know really :/
Code:
Lua Script Error: [Event Interface]
data/events/scripts/monster.lua:[email protected]
...ta\scripts\eventcallbacks\monster\default_onDropLoot.lua:41: attempt to index local 'item' (a boolean value)
stack traceback:
[C]: in function '__index'
...ta\scripts\eventcallbacks\monster\default_onDropLoot.lua:41: in function <...ta\scripts\eventcallbacks\monster\default_onDropLoot.lua:11>
...esktop\Unique 1.4.2\data\scripts/lib\event_callbacks.lua:127: in function 'EventCallback'
data/events/scripts/monster.lua:3: in function <data/events/scripts/monster.lua:1>
Lua:
local List_Monsters = {
{
name = "Archmage",
items = {6551}
},
}
local ec = EventCallback
ec.onDropLoot = function(self, corpse)
if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
return
end
local player = Player(corpse:getCorpseOwner())
local mType = self:getType()
local monsterLoot = mType:getLoot()
local increaseLoot = false
local extraLootPercent = 15
if player and player:getStorageValue(12500) > os.time() then
increaseLoot = true
end
for i = 1, #monsterLoot do
if increaseLoot then
local default = monsterLoot[i]
if default.chance < 100000 then
default.chance = default.chance + ((extraLootPercent * (default.chance / 1000) / 100) * 1000)
end
end
local item = corpse:createLootItem(monsterLoot[i])
if not item then
print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
else
-- Check if the looted item is in the table
for j = 1, #List_Monsters do
if mType:getName() == List_Monsters[j].name then
for k = 1, #List_Monsters[j].items do
if item:getId() == List_Monsters[j].items[k] then
player:sendTextMessage(MESSAGE_LOOT, "You have looted a special item from ".. List_Monsters[j].name .."!")
end
end
end
end
end
end
if player then
local text = ("%s of %s: %s"):format((increaseLoot and "Increased loot" or "Loot"), mType:getNameDescription(), corpse:getContentDescription())
player:sendTextMessage(MESSAGE_LOOT, text)
end
end
ec:register()