athenso
Average Coder
- Joined
- May 31, 2011
- Messages
- 155
- Solutions
- 3
- Reaction score
- 23
I am very sleep deprived, I know the solution is easy. I am working on a script that reduces stamina from mining items. I tried a few methods, but all of which return full stamina and not reduce. Not my script, just tweaking it for stamina.
Code:
-- 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 = 15002 -- Storage used to store Custom Skill Levels
local minutes = 1 -- Minutes to recreate the stone
local charge = 10
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
[8639] = {
itemid = 8639,
stonetype = 'strange red powder',
stonetype2 = 'red gem',
item = 13213,
item2 = 2156,
level = {min = 1, max = 30},
bonusLevel = 15,
bonusChance = 20,
roundChance = {min = 1, max = 2},
chance = 2,
round = 8,
xp = 1,
xp2 = 2
},
[8635] = {
itemid = 8635,
stonetype = 'strange red powder',
stonetype2 = 'red gem',
item = 13213,
item2 = 2156,
level = {min = 15, max = 30},
bonusLevel = 25,
roundChance = {min = 1, max = 2},
chance = 4,
round = 10,
xp = 3,
xp2 = 5
},
[8637] = {
itemid = 8637,
stonetype = 'strange blue powder',
stonetype2 = 'blue gem',
item = 13215,
item2 = 2158,
level = {min = 25, max = 45},
bonusLevel = 29,
roundChance = {min = 1, max = 2},
chance = 4,
round = 10,
xp = 3,
xp2 = 5
},
[8633] = {
itemid = 8633,
stonetype = 'strange blue powder',
stonetype2 = 'blue gem',
item = 13215,
item2 = 2158,
level = {min = 45, max = 99},
bonusLevel = 25,
roundChance = {min = 1, max = 2},
chance = 4,
round = 10,
xp = 3,
xp2 = 5
},
[1285] = {
itemid = 1285,
stonetype = 'iron ore',
stonetype2 = 'vein of ore',
item = 5880,
item2 = 18429,
level = {min = 1, max = 30},
bonusLevel = 5,
bonusChance = 20,
roundChance = {min = 1, max = 2},
chance = 2,
round = 8,
xp = 3,
xp2 = 5
}
}
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 and player:getStamina() >= 10 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 .. ".")
player:setStamina(-charge)
else
local loop = stones[target.itemid].xp
player:addItem(stones[target.itemid].item, amount)
toPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
player:setStamina(-charge)
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 .. ".")
player:setStamina(-charge)
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.")
player:setStamina(-charge)
target:remove()
addEvent(doCreateStone, minutes * 60 * 1000, toPosition, target.itemid)
else
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You couldn't mine anything.")
player:setStamina(-charge)
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