Every time a player dies, the console shows this error:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/others/droploot.lua
nDeath
data/lib/core/tables.lua:17: bad argument #1 to 'pairs' (table expected, got number)
stack traceback:
[C]: at 0x7ff72bf30980
[C]: in function 'pairs'
data/lib/core/tables.lua:17: in function 'contains'
data/creaturescripts/scripts/others/droploot.lua:7: in function <data/creaturescripts/scripts/others/droploot.lua:1>
This is TFS 1.2
tables.lua
droploot.lua
SOLVED: deleted the file tables.lua and added the table.contains function in global.lua
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/others/droploot.lua
data/lib/core/tables.lua:17: bad argument #1 to 'pairs' (table expected, got number)
stack traceback:
[C]: at 0x7ff72bf30980
[C]: in function 'pairs'
data/lib/core/tables.lua:17: in function 'contains'
data/creaturescripts/scripts/others/droploot.lua:7: in function <data/creaturescripts/scripts/others/droploot.lua:1>
This is TFS 1.2
tables.lua
LUA:
table.append = table.insert
table.empty = function (t)
return next(t) == nil
end
table.find = function (table, value)
for i, v in pairs(table) do
if(v == value) then
return i
end
end
return nil
end
table.contains = function (txt, str)
for i, v in pairs(str) do
if(txt:find(v) and not txt:find('(%w+)' .. v) and not txt:find(v .. '(%w+)')) then
return true
end
end
return false
end
table.isStrIn = table.contains
table.count = function (table, item)
local count = 0
for i, n in pairs(table) do
if(item == n) then
count = count + 1
end
end
return count
end
table.countElements = table.count
table.getCombinations = function (table, num)
local a, number, select, newlist = {}, #table, num, {}
for i = 1, select do
a[#a + 1] = i
end
local newthing = {}
while(true) do
local newrow = {}
for i = 1, select do
newrow[#newrow + 1] = table[a[i]]
end
newlist[#newlist + 1] = newrow
i = select
while(a[i] == (number - select + i)) do
i = i - 1
end
if(i < 1) then
break
end
a[i] = a[i] + 1
for j = i, select do
a[j] = a[i] + j - i
end
end
return newlist
end
function table.serialize(x, recur)
local t = type(x)
recur = recur or {}
if(t == nil) then
return "nil"
elseif(t == "string") then
return string.format("%q", x)
elseif(t == "number") then
return tostring(x)
elseif(t == "boolean") then
return t and "true" or "false"
elseif(getmetatable(x)) then
error("Can not serialize a table that has a metatable associated with it.")
elseif(t == "table") then
if(table.find(recur, x)) then
error("Can not serialize recursive tables.")
end
table.append(recur, x)
local s = "{"
for k, v in pairs(x) do
s = s .. "[" .. table.serialize(k, recur) .. "]"
s = s .. " = " .. table.serialize(v, recur) .. ","
end
s = s .. "}"
return s
else
error("Can not serialize value of type '" .. t .. "'.")
end
end
function table.unserialize(str)
return loadstring("return " .. str)()
end
droploot.lua
LUA:
function onDeath(player, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
if getPlayerFlagValue(player, PlayerFlag_NotGenerateLoot) or player:getVocation():getId() == VOCATION_NONE then
return true
end
local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
if amulet and amulet.itemid == ITEM_AMULETOFLOSS and not table.contains({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
local isPlayer = false
if killer then
if killer:isPlayer() then
isPlayer = true
else
local master = killer:getMaster()
if master and master:isPlayer() then
isPlayer = true
end
end
end
if not isPlayer or not player:hasBlessing(6) then
player:removeItem(ITEM_AMULETOFLOSS, 1, -1, false)
end
else
for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
local item = player:getSlotItem(i)
if item then
if table.contains({SKULL_RED, SKULL_BLACK}, player:getSkull()) or math.random(item:isContainer() and 100 or 1000) <= player:getLossPercent() then
if not item:moveTo(corpse) then
item:remove()
end
end
end
end
end
if not player:getSlotItem(CONST_SLOT_BACKPACK) then
player:addItem(ITEM_BAG, 1, false, CONST_SLOT_BACKPACK)
end
return true
end
SOLVED: deleted the file tables.lua and added the table.contains function in global.lua
Last edited: