• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

weird bug in smithing script all details inside pls help.

oshrigames

Active Member
Joined
Nov 9, 2012
Messages
222
Reaction score
47
Location
israel
Hello once again :D
Original post/system:

i use TFS 1.2 (protocol 10.98)
ive modified smithing stations to face north and not west, and with the help from Ramirow. made 5 tiers insted of only 2.
now, only script that work for me so far is the very first original script where there can be only one smithing station and two tiers with 1 fixed position.
Lua:
local anvilPos = Position(999, 987, 8)        --Anvil Position
local materialPos = Position(998, 987, 8)        --Material Position
local rewardPos = Position(1000, 987, 8)    --Item Craft Position

if i use his updated script (not modified at all by me) where you can have multiple smithing stations i get this error:
Error 2.png
no idea how to even deal with "0x7ff6dbcc2e20" error o -o`


here is my request more detailed if anyone willing to give it a go :3
1) make multiple smithing stations work.
2) go through my code of 5 tiers see where i screw things over (full script attached to the post)
3) go through my code see if my north faceing stations will work (same attached script)
heres first smithing station draft, Anvil middle (put 18413 on it), Basin left to the Anvil (by x: -1) and put 5887 on it, reward right to the Anvil (x: +1) where item go after i hit 18413 with hammer.
sslocation.png
if there's any more info that you need please. let me know

and i'll make sure to credit you in my server description & if you decide to play ill get u store credits for cosmetics :3

much appreciated
Thanks. ♥
 

Attachments

Last edited:
Solution
Downloaded a server just to help you out with it and test it by myself. My updated script also had that issue, you actually coded the tiers perfect so you didn't screw anything as you stated, after I fixed the createItem error everything went smoothly.

Here you have the code you need attached, works on multiple north stations and has the five tiers.

The issue was how I passed the parameters on the updated version, I will point out what it was so you can learn from it too.
The error itself was in the createItem function I called on the script. That function requires, if I recall correctly, 2 parameters to work.
Code:
Game.createItem(itemId, count)
Those parameters are "itemId" and "count" as you can see, and you can use a third...
Will try to help but, can't help to notice it points out ERROR in line 272. My script has way less lines, so that error is not popping up on the original version, don't have a server to test now. I will modify a version so you can test with only one added change, north smithing stations instead of the original ones.

Here you have, try this one:
Code:
-- 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

It should work without any errors using two tiers and north crafting stations (And yes, it should work with multiple stations too). If you can test it and it works fine I will adapt your 5 tiers into it.
 
Last edited:
Downloaded a server just to help you out with it and test it by myself. My updated script also had that issue, you actually coded the tiers perfect so you didn't screw anything as you stated, after I fixed the createItem error everything went smoothly.

Here you have the code you need attached, works on multiple north stations and has the five tiers.

The issue was how I passed the parameters on the updated version, I will point out what it was so you can learn from it too.
The error itself was in the createItem function I called on the script. That function requires, if I recall correctly, 2 parameters to work.
Code:
Game.createItem(itemId, count)
Those parameters are "itemId" and "count" as you can see, and you can use a third parameter which is optional. Position.
See, the function will expect a third parameter as a Table containing the position information and not 3 separate Number values (someone more knowledgeable please correct me if i'm wrong) and I was passing the wrong data.

It was expecting this:
Code:
Game.createItem(itemId, count, Position)
And I was passing this:
Code:
Game.createItem(itemId, count, x, y, z)

In order to solve that issue and pass only one parameter I did it like this:
Code:
Game.createItem(itemId, count, Position(x, y, z))

I hope you understand at least what happened, have a nice day n_n
 

Attachments

Solution
Downloaded a server just to help you out with it and test it by myself. My updated script also had that issue, you actually coded the tiers perfect so you didn't screw anything as you stated, after I fixed the createItem error everything went smoothly.

Here you have the code you need attached, works on multiple north stations and has the five tiers.

The issue was how I passed the parameters on the updated version, I will point out what it was so you can learn from it too.
The error itself was in the createItem function I called on the script. That function requires, if I recall correctly, 2 parameters to work.
Code:
Game.createItem(itemId, count)
Those parameters are "itemId" and "count" as you can see, and you can use a third parameter which is optional. Position.
See, the function will expect a third parameter as a Table containing the position information and not 3 separate Number values (someone more knowledgeable please correct me if i'm wrong) and I was passing the wrong data.

It was expecting this:
Code:
Game.createItem(itemId, count, Position)
And I was passing this:
Code:
Game.createItem(itemId, count, x, y, z)

In order to solve that issue and pass only one parameter I did it like this:
Code:
Game.createItem(itemId, count, Position(x, y, z))

I hope you understand at least what happened, have a nice day n_n

ye it's my bad, its the error from my 5 tier script.

also thank for take the time ot only help me out to unthinkable lengths, but also explain it to me so i can learn :D
you truly are great guy, and thanks a bunch for everything you do and share with us here.

works great. and i'll run few tests and balance/configure all the numbers right away to fit my server.
thanks again!

i'm a ok mapper if i say so myself, if there is anything you need let me know.
here's bit of my work.
 
Back
Top