Ramirow
Veteran OT User
- Joined
- Aug 22, 2009
- Messages
- 584
- Solutions
- 15
- Reaction score
- 301
- Location
- Argentina
- YouTube
- ramirogrant
First of all, I know I'm not a good scripter myself, but I made this and I wanted to share it.
Requirements:
CODEX NG's Spell Experience system: Player - Spell Experience - 1.2
Optional:
Zbizu's UISS: CreatureEvent - [TFS 1.1] Ultimate item stat system (elements, skills, exp, loot and more)
Just register the item you want to use it with in Actions.xml, change the position at the top of the script to suit your map and it's done.
I've commented the script almost everywhere so you understand how to config it. Feel free to ask any questions or anything.
Little picture of it:
HOW THIS WORKS:
1) You place crystals (Or any item you configure) and a material.
2) You hit them with the registered item of your choice (in Actions.xml)
3) You create an item or fail.
4) You gain exp towards advancing the skill (which increases your sucess rate and will unlock better items)
5) You may also get a refined item (+1, +2, etc) if you enable Zbizu's UISS option, higher skill gives you higher chance and more powerful refines.
Requirements:
CODEX NG's Spell Experience system: Player - Spell Experience - 1.2
Optional:
Zbizu's UISS: CreatureEvent - [TFS 1.1] Ultimate item stat system (elements, skills, exp, loot and more)
Just register the item you want to use it with in Actions.xml, change the position at the top of the script to suit your map and it's done.
I've commented the script almost everywhere so you understand how to config it. Feel free to ask any questions or anything.
Little picture of it:
HOW THIS WORKS:
1) You place crystals (Or any item you configure) and a material.
2) You hit them with the registered item of your choice (in Actions.xml)
3) You create an item or fail.
4) You gain exp towards advancing the skill (which increases your sucess rate and will unlock better items)
5) You may also get a refined item (+1, +2, etc) if you enable Zbizu's UISS option, higher skill gives you higher chance and more powerful refines.
Code:
-- Smithing Skill
-- 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 anvilPos = Position(1036, 550, 7) --Anvil Position
local materialPos = Position(1036, 551, 7) --Material Position
local rewardPos = Position(1036, 549, 7) --Item Craft Position
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 smithingSkill = player:getCustomSkill(storage)
if config[target.itemid] == nil then
return false
end
if config[target.itemid] and toPosition == anvilPos then
local itemLevel = config[target.itemid].level
if smithingSkill < itemLevel.min then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need smithing level " .. itemLevel.min .. " for this combination.")
return true
end
local hasReagent = Tile(materialPos):getItemById(config[target.itemid].material)
if not hasReagent then
materialPos:sendMagicEffect(CONST_ME_TUTORIALSQUARE)
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need materials in order to craft.")
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))
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(anvilPos):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(rewardPos):getTopDownItem()
if itemBefore ~= nil then
itemBefore:remove()
end
hasReagent:remove(1)
removeCrystal:remove(1)
Game.createItem(config[target.itemid].tierOneItems[tierDice], 1, rewardPos)
local b = Tile(rewardPos):getItemById(config[target.itemid].tierOneItems[tierDice])
b:generateLooted(refineDice)
player:say("REFINED item crafted!", TALKTYPE_MONSTER_SAY)
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
rewardPos: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(anvilPos):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(rewardPos):getTopDownItem()
if itemBefore ~= nil then
itemBefore:remove()
end
hasReagent:remove(1)
removeCrystal:remove(1)
Game.createItem(config[target.itemid].tierTwoItems[tierDice], 1, rewardPos)
local b = Tile(rewardPos):getItemById(config[target.itemid].tierTwoItems[tierDice])
b:generateLooted(refineDice)
player:say("REFINED item crafted!", TALKTYPE_MONSTER_SAY)
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
rewardPos: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(anvilPos):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(rewardPos):getTopDownItem()
if itemBefore ~= nil then
itemBefore:remove()
end
hasReagent:remove(1)
removeCrystal:remove(1)
Game.createItem(config[target.itemid].tierOneItems[tierDice], 1, rewardPos)
player:say("Item crafted!", TALKTYPE_MONSTER_SAY)
rewardPos: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(anvilPos):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(rewardPos):getTopDownItem()
if itemBefore ~= nil then
itemBefore:remove()
end
hasReagent:remove(1)
removeCrystal:remove(1)
Game.createItem(config[target.itemid].tierTwoItems[tierDice], 1, rewardPos)
player:say("Item crafted!", TALKTYPE_MONSTER_SAY)
rewardPos: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(anvilPos):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
elseif toPosition ~= anvilPos then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to go to an special shop in order to craft.")
else
return false
end
return true
end