• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action [TFS 0.4/1.2] Tier upgrading system

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,643
Solutions
559
Reaction score
3,955
This is a simple script that is able to support multiple upgrader itemids without having to make a script for every single id.

edit: updated for tfs 1.2

Basic layout for each upgrader id
Code:
[UpgraderID] = {tier = x, upgraderType = 'str', chance = y,
    items = {
        [StartID] = NewID
    }
}

If you need help editing it, post here. (though it's self explanatory)
Code:
local cfg = {
    upgrade = {
        message = 'Upgrade!',
        color   = TEXTCOLOR_YELLOW,
        effect  = CONST_ME_FIREWORK_RED
    },

    fail = {
        message  = 'Upgrade Failed.',
        talkType = TALKTYPE_MONSTER,
        effect   = CONST_ME_POFF
    }
}

local gear = {
[2087] = {tier = 1, upgraderType = 'key', chance = 30,
        items = {
            [2505] = 2492,
            [2160] = 2148
        }
    },
[2088] = {tier = 2, upgraderType = 'key', chance = 80,
        items = {
            [2148] = 2160
        }
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local tmp  = gear[item.itemid]
    local upgradeid = tmp and tmp.items[itemEx.itemid]
    local name = (itemEx.uid == 0) and 'this' or (itemEx.type > 1) and getItemPluralName(itemEx.uid) or (getItemArticle(itemEx.uid) ~= '') and (''.. getItemArticle(itemEx.uid) .. ' ' .. getItemName(itemEx.uid)) or getItemName(itemEx.uid)
        if upgradeid then
            if itemEx.type <= 1 then
                if math.random(100) <= tmp.chance then
                    doSendMagicEffect(toPosition, cfg.upgrade.effect)
                    doSendAnimatedText(toPosition, cfg.upgrade.message, cfg.upgrade.color)
                    doTransformItem(itemEx.uid, upgradeid)
                else
                    doCreatureSay(cid, cfg.fail.message, cfg.fail.talkType)
                    doSendMagicEffect(toPosition, cfg.fail.effect)
                end
                doRemoveItem(item.uid, 1)
            else
                doPlayerSendCancel(cid, 'You may only upgrade '.. name ..' 1 at a time.')
                doSendMagicEffect(toPosition, CONST_ME_POFF)
            end
        else
            doPlayerSendCancel(cid, 'You are unable to upgrade '.. name ..' with a tier '.. tmp.tier .. ' '.. tmp.upgraderType ..'.')
            doSendMagicEffect(toPosition, CONST_ME_POFF)
        end
    return true
end

Code:
local cfg = {
    upgrade = {
        message  = 'Upgrade!',
        talkType = TALKTYPE_MONSTER_SAY,
        effect   = CONST_ME_FIREWORK_RED
    },

    fail = {
        message  = 'Upgrade Failed.',
        talkType = TALKTYPE_MONSTER_SAY,
        effect   = CONST_ME_POFF
    }
}

local gear = {
    [2087] = {tier = 1, upgraderType = 'key', chance = 30,
        items = {
            [2505] = 2492,
            [2160] = 2148
        }
    },
    [2088] = {tier = 2, upgraderType = 'key', chance = 80,
        items = {
            [2148] = 2160
        }
    }
}

local function shit(v, cfgu, cfgf, upgid)
    if v then
        return cfgu.message, cfgu.talkType, cfgu.effect, upgid
    else
        return cfgf.message, cfgf.talkType, cfgf.effect, 0
    end
end

local cfgu, cfgf  = cfg.upgrade, cfg.fail

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player == target then
        return true
    end
    local pos   = (toPosition.x == 65535) and player:getPosition() or toPosition
    local tmp   = gear[item.itemid]
    local upgid = tmp and tmp.items[target.itemid]
    local name  = (target.type > 1) and target:getPluralName() or (target:getArticle() ~= '') and (string.format('%s %s', target:getArticle(), target:getName())) or target:getName()
    local v     = (math.random(100) <= tmp.chance)
    if not upgid then
        player:sendCancelMessage(string.format('You are unable to upgrade %s with a tier %d %s.', (name == '') and 'this' or name, tmp.tier, tmp.upgraderType))
        pos:sendMagicEffect(CONST_ME_POFF)
        return true
    end
    if target.type > 1 then
        player:sendCancelMessage(string.format('You may only upgrade %s 1 at a time.', name))
        pos:sendMagicEffect(CONST_ME_POFF)
        return true
    end
    local message, talktype, effect, trans = shit(v, cfgu, cfgf, upgid)
    pos:sendMagicEffect(effect)
    player:say(message, talktype)
    target:transform(trans)
    item:remove(1)
    return true
end

11/4/16 - updated 1.2 script (shortened script and made it more readable)
11/4/16 - updated 1.2 script again (bugfixes)
 
Last edited:
the as script is working but have this error

Lua Script Error: [Action Interface]
data/actions/scripts/custom/upgrade items.lua:eek:nUse
data/actions/scripts/custom/upgrade items.lua:54: attempt to index global 'posit
ion' (a nil value)
stack traceback:
[C]: in function '__index'
data/actions/scripts/custom/upgrade items.lua:54: in function <data/acti
ons/scripts/custom/upgrade items.lua:32>
 
the as script is working but have this error

Lua Script Error: [Action Interface]
data/actions/scripts/custom/upgrade items.lua:eek:nUse
data/actions/scripts/custom/upgrade items.lua:54: attempt to index global 'posit
ion' (a nil value)
stack traceback:
[C]: in function '__index'
data/actions/scripts/custom/upgrade items.lua:54: in function <data/acti
ons/scripts/custom/upgrade items.lua:32>
check updated 1.2 script
 
Last edited:
I keep bumping into this error....?

Lua Script Error: [Action Interface]
data/actions/scripts/tiersystem/tier.lua: onUse
data/actions/scripts/tiersystem/tier.lua:47: attempt to call method 'getArticle' (a nil value)
stack traceback:
[C]: in function 'getArticle'
data/actions/scripts/tiersystem/tier.lua:47: in function <data/actions/scripts/tiersystem/tier.lua:40>
 
I keep bumping into this error....?
after
Lua:
    if player == target then
        return true
    end
add
Lua:
    if not target:isItem() then
        return true
    end
you're likely using it on something that isn't an item, or your tfs somehow doesn't have item:getArticle()
 
went over it all again.. Now I get this @Static_
Lua Script Error: [Action Interface]
data/actions/scripts/tiersystem/first.lua:eek:nUse
data/actions/scripts/tiersystem/first.lua:47: attempt to index local 'tmp' (a nil value)
stack traceback:
[C]: in function '__index'
data/actions/scripts/tiersystem/first.lua:47: in function <data/actions/scripts/tiersystem/first.lua:39>
 
Back
Top