-- Smithing Skill v1.1
-- For TFS versions 1.2+
-- Uses CODEX NG's Spell Experience: https://otland.net/threads/player-spell-experience-1-2.238208/
-- Optionals: Zbizu's Ultimate Item Stat System: https://otland.net/threads/tfs-1-1-ultimate-item-stat-system-elements-skills-exp-loot-and-more.229771/
local name = "Smithing" -- Spell Experience Skill Name
local storage = 15019 -- Spell Experience storage
local useItemStats = false --Enables or disables Zbizu's Ultimate Item Stat System
local config = {
[18417] = { --Brown Crystal Splinter
itemid = 18417,
tiers = {first = 1, second = 20}, --Level Tiers for different items
tierOneItems = {2376, 2386, 2448, 2412, 2398, 2388}, --IN ORDER: Sword, Axe, Studded Club, Katana, Mace, Hatchet
tierTwoItems = {2376, 2386, 2448, 2412, 2398, 2388, 2430, 8209, 2445}, --IN ORDER: Sword, Axe, Studded Club, Katana, Mace, Hatchet, Knight Axe, Crimson Sword, Crystal Mace
level = {min = 1, success = 35}, --Min stands for minimun level in order to craft, success stands for the base chance of success at such level
material = 5887, --The material needed to craft
skillSuccessIncrement = 1, --How much sucess rate you gain with each level in the skill
refine = {base = 1, increment = 0.1}, --Base refine rate and how much it increases per skill level (If using Zbizu's Ultimate Item Stat System)
refineLevel = 10, --Every X levels to get better refines (If using Zbizu's Ultimate Item Stat System)
xp = {normalItem = 2, refinedItem = 5} --Exp gained for succesful crafting or refined (refined requires Zbizu's System)
}
}
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local player = type(cid) == 'number' and Player(cid) or cid
local checkAnvil = Tile(toPosition):getItemCountById(18413)
local checkBasin = Tile(toPosition.x - 1, toPosition.y, toPosition.z):getItemCountById(1485)
if checkAnvil == 1 and checkBasin == 1 then
if config[target.itemid] then
local hasReagent = Tile(toPosition.x - 1, toPosition.y, toPosition.z):getItemById(config[target.itemid].material)
if not hasReagent then
Position(toPosition.x - 1, toPosition.y, toPosition.z):sendMagicEffect(CONST_ME_TUTORIALSQUARE)
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need materials in order to craft.")
return true
end
local itemLevel = config[target.itemid].level
local smithingSkill = player:getCustomSkill(storage)
if smithingSkill < itemLevel.min then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need smithing level " .. itemLevel.min .. " for this combination.")
return true
end
if hasReagent then
local rank = config[target.itemid].tiers
local chance = math.floor((math.random(1, 100)) - ((smithingSkill * config[target.itemid].skillSuccessIncrement) - itemLevel.min))
if chance <= itemLevel.success then
local bonusBase = config[target.itemid].refine
local bonusChance = math.floor(math.random(1, 100) - (smithingSkill * bonusBase.increment))
if bonusChance <= bonusBase.base and useItemStats == true then
if smithingSkill < rank.second then
local removeCrystal = Tile(toPosition):getItemById(target.itemid)
local refineDice = math.floor(math.random(1,smithingSkill / config[target.itemid].refineLevel))
if refineDice < 1 then
refineDice = 1
end
local tierAmount = 0
local getTable = config[target.itemid]
for k, v in pairs(getTable.tierOneItems) do
tierAmount = tierAmount + 1
end
local tierDice = math.floor(math.random(1,tierAmount))
local itemBefore = Tile(toPosition.x + 1, toPosition.y, toPosition.z):getTopDownItem()
if itemBefore ~= nil then
itemBefore:remove()
end
hasReagent:remove(1)
removeCrystal:remove(1)
Game.createItem(config[target.itemid].tierOneItems[tierDice], 1, toPosition.x + 1, toPosition.y, toPosition.z)
local b = Tile(toPosition.x + 1, toPosition.y, toPosition.z):getItemById(config[target.itemid].tierOneItems[tierDice])
b:generateLooted(refineDice)
player:say("REFINED item crafted!", TALKTYPE_MONSTER_SAY)
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
Position(toPosition.x + 1, toPosition.y, toPosition.z):sendMagicEffect(CONST_ME_MAGIC_RED)
toPosition:sendMagicEffect(CONST_ME_BLOCKHIT)
local loopExp = config[target.itemid].xp
for i = loopExp.refinedItem, 1, -1 do
player:addCustomSkillTry(name, storage)
end
else
local removeCrystal = Tile(toPosition):getItemById(target.itemid)
local refineDice = math.floor(math.random(1,smithingSkill / config[target.itemid].refineLevel))
if refineDice < 1 then
refineDice = 1
end
local tierAmount = 0
local getTable = config[target.itemid]
for k, v in pairs(getTable.tierTwoItems) do
tierAmount = tierAmount + 1
end
local tierDice = math.floor(math.random(1,tierAmount))
local itemBefore = Tile(toPosition.x + 1, toPosition.y, toPosition.z):getTopDownItem()
if itemBefore ~= nil then
itemBefore:remove()
end
hasReagent:remove(1)
removeCrystal:remove(1)
Game.createItem(config[target.itemid].tierTwoItems[tierDice], 1, toPosition.x + 1, toPosition.y, toPosition.z)
local b = Tile(toPosition.x + 1, toPosition.y, toPosition.z):getItemById(config[target.itemid].tierTwoItems[tierDice])
b:generateLooted(refineDice)
player:say("REFINED item crafted!", TALKTYPE_MONSTER_SAY)
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
Position(toPosition.x + 1, toPosition.y, toPosition.z):sendMagicEffect(CONST_ME_MAGIC_RED)
toPosition:sendMagicEffect(CONST_ME_BLOCKHIT)
local loopExp = config[target.itemid].xp
for i = loopExp.refinedItem, 1, -1 do
player:addCustomSkillTry(name, storage)
end
end
else
if smithingSkill < rank.second then
local removeCrystal = Tile(toPosition):getItemById(target.itemid)
local tierAmount = 0
local getTable = config[target.itemid]
for k, v in pairs(getTable.tierOneItems) do
tierAmount = tierAmount + 1
end
local tierDice = math.floor(math.random(1,tierAmount))
local itemBefore = Tile(toPosition.x + 1, toPosition.y, toPosition.z):getTopDownItem()
if itemBefore ~= nil then
itemBefore:remove()
end
hasReagent:remove(1)
removeCrystal:remove(1)
Game.createItem(config[target.itemid].tierOneItems[tierDice], 1, toPosition.x + 1, toPosition.y, toPosition.z)
player:say("Item crafted!", TALKTYPE_MONSTER_SAY)
Position(toPosition.x + 1, toPosition.y, toPosition.z):sendMagicEffect(CONST_ME_MAGIC_RED)
toPosition:sendMagicEffect(CONST_ME_BLOCKHIT)
local loopExp = config[target.itemid].xp
for i = loopExp.normalItem, 1, -1 do
player:addCustomSkillTry(name, storage)
end
else
local removeCrystal = Tile(toPosition):getItemById(target.itemid)
local tierAmount = 0
local getTable = config[target.itemid]
for k, v in pairs(getTable.tierTwoItems) do
tierAmount = tierAmount + 1
end
local tierDice = math.floor(math.random(1,tierAmount))
local itemBefore = Tile(toPosition.x + 1, toPosition.y, toPosition.z):getTopDownItem()
if itemBefore ~= nil then
itemBefore:remove()
end
hasReagent:remove(1)
removeCrystal:remove(1)
Game.createItem(config[target.itemid].tierTwoItems[tierDice], 1, toPosition.x + 1, toPosition.y, toPosition.z)
player:say("Item crafted!", TALKTYPE_MONSTER_SAY)
Position(toPosition.x + 1, toPosition.y, toPosition.z):sendMagicEffect(CONST_ME_MAGIC_RED)
toPosition:sendMagicEffect(CONST_ME_BLOCKHIT)
local loopExp = config[target.itemid].xp
for i = loopExp.normalItem, 1, -1 do
player:addCustomSkillTry(name, storage)
end
end
return true
end
else
local removeCrystal = Tile(toPosition):getItemById(target.itemid)
player:sendTextMessage(MESSAGE_STATUS_SMALL, "Crafting failed.")
toPosition:sendMagicEffect(CONST_ME_POFF)
hasReagent:remove(1)
removeCrystal:remove(1)
return true
end
return true
end
else
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to place crystals on top of the anvil.")
end
else
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to go to an special shop in order to craft.")
end
return true
end