Lua Script Error: [Action Interface]
data/actions/scripts/tools/minerar.luanUse
data/actions/scripts/tools/minerar.lua:63: attempt to compare number with nil
stack traceback:
[C]: in function '__le'
data/actions/scripts/tools/minerar.lua:63: in function <data/actions/scripts/tools/minerar.lua:52>
Lua:
-- Mining Skill by Ramirow
-- Skill System created by Codex NG -THANKS! (https://otland.net/members/codex-ng.213653/)
-- For TFS version 1.1
local name = "Mining" -- Name of the Custom Skill
local storage = SKILL_MINERADOR -- Storage used to store Custom Skill Levels
local minutes = 1 -- Minutes to recreate the stone
function doCreateStone(pos, itemid) -- Recreates the stone after given time
local tile = Tile(pos)
if tile:getTopCreature() then
pos:sendMagicEffect(CONST_ME_POFF)
return addEvent(doCreateStone, minutes * 60 * 1000, pos, itemid)
else
Game.createItem(itemid, 1, pos)
pos:sendMagicEffect(CONST_ME_MAGIC_RED)
end
end
local stones = { -- Contains all stones and their data
[8046] = {
itemid = 8046,
stonetype = 'piece of iron ore',
stonetype2 = 'iron ore',
item = 2225,
item2 = 5880,
level = {min = 1, max = 30},
bonusLevel = 15,
bonusChance = 20,
roundChance = {min = 1, max = 2},
chance = 2,
round = 8,
xp = 1,
xp2 = 2
},
[8047] = {
itemid = 8047,
stonetype = 'iron ore',
stonetype2 = 'piece of iron',
item = 5880,
item2 = 2225,
level = {min = 15, max = 30},
bonusLevel = 25,
roundChance = {min = 1, max = 2},
chance = 4,
round = 10,
xp = 3,
xp2 = 4
}
}
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local player = type(cid) == 'number' and Player(cid) or cid
local miningSkill = player:getCustomSkill(storage)
if stones[target.itemid] then
local miningLevel = stones[target.itemid].level
if miningSkill >= miningLevel.min then
local chance = math.floor((math.random(1, 100)) - (miningSkill / stones[target.itemid].chance))
if chance <= miningLevel.max then
local roundChance = stones[target.itemid].roundChance
local amount = math.floor((math.random(roundChance.min, roundChance.max)) + (miningSkill / stones[target.itemid].round))
if miningSkill >= stones[target.itemid].bonusLevel and math.random(1,100) <= stones[target.itemid].bonusChance then
local loop2 = stones[target.itemid].xp2
player:addItem(stones[target.itemid].item2, amount)
toPosition:sendMagicEffect(CONST_ME_MAGIC_GREEN)
target:remove()
addEvent(doCreateStone, minutes * 60 * 1000, toPosition, target.itemid)
for i = loop2, 1, -1 do
player:addCustomSkillTry(name, storage)
end
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You mined " .. amount .. " " .. stones[target.itemid].stonetype2 .. ".")
else
local loop = stones[target.itemid].xp
player:addItem(stones[target.itemid].item, amount)
toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
target:remove()
addEvent(doCreateStone, minutes * 60 * 1000, toPosition, target.itemid)
for i = loop, 1, -1 do
player:addCustomSkillTry(name, storage)
end
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You mined " .. amount .. " " .. stones[target.itemid].stonetype .. ".")
end
else
local failure = math.random(1,100)
if failure <= 50 then
toPosition:sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You failed and the rock was destroyed.")
target:remove()
addEvent(doCreateStone, minutes * 60 * 1000, toPosition, target.itemid)
else
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You couldn't mine anything.")
toPosition:sendMagicEffect(CONST_ME_HITAREA)
end
end
else
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need a " .. name .. " level of " .. miningLevel.min .. " to mine this stone.")
end
end
return true
end