Nokturno
Not a human
- Joined
- Aug 7, 2009
- Messages
- 569
- Solutions
- 2
- Reaction score
- 402
hello ppl.
im working on a script but im currently stuck in the code
ERROR:
Cant get the function index the local 'item'
dont know if someone can help me out with this?
im working on a script but im currently stuck in the code
Lua:
local function classifyLoot(position)
local corpse = Tile(position):getTopDownItem()
if not corpse then
return false
end
-- Creating loot list
local itemList = {}
if ItemType(corpse:getId()):isContainer() then
for i = corpse:getSize() - 1, 0, -1 do
local item = corpse:getItem(i)
if item then
itemList[#itemList + 1] = item:getId()
end
end
end
-- Getting/Assigning tier
local itemMaxRarity = 0
local tierIndex, found = 0, false
for _, item in ipairs(itemList) do -- check all items in table
local itemRarity = item:getRarity() -- check rarity levels
-- need to add check for uncommon items
if itemRarity > itemMaxRarity then -- if current item is higher tier than previous item
local itemMaxRarity = itemRarity -- assign highest rarity level
end
found = true
end
-- Transforming corpse
local uncommon = {bag = 1991, effect = 36, tier = "uncommon"}
local rare = {bag = 1991, effect = 36, tier = "rare"}
local epic = {bag = 1993, effect = 207, tier = "epic"}
local legendary = {bag = 1997, effect = 177, tier = "legendary"}
if found then -- when tier item is found
if itemMaxRarity == 1 then
corpse:transform(uncommon.bag)
position:sendMagicEffect(uncommon.effect)
effectLoop(position, uncommon.effect)
local tierPhrase = uncommon.tier
elseif itemMaxRarity == 2 then
corpse:transform(rare.bag)
position:sendMagicEffect(rare.effect)
effectLoop(position, rare.effect)
local tierPhrase = rare.tier
elseif itemMaxRarity == 3 then
corpse:transform(epic.bag)
position:sendMagicEffect(epic.effect)
effectLoop(position, epic.effect)
local tierPhrase = epic.tier
elseif itemMaxRarity == 4 then
corpse:transform(legendary.bag)
position:sendMagicEffect(legendary.effect)
effectLoop(position, legendary.effect)
local tierPhrase = legendary.tier
end
local spectators = Game.getSpectators(position, false, true, 7, 7, 5, 5)
if #spectators > 0 then
for i = 1, #spectators do
spectators[i]:say(tierPhrase, TALKTYPE_MONSTER_SAY, false, spectators[i], position)
end
end
else
-- Default tier
corpse:transform(1996)
position:sendMagicEffect(31)
end
end
Code:
ERROR:
Lua:
data/creaturescripts/scripts/customLoot.lua:49: attempt to index local 'item' (a number value)
stack traceback:
[C]: in function '__inde
Code:
Cant get the function index the local 'item'
Code:
for _, item in ipairs(itemList) do
dont know if someone can help me out with this?