• 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!

Action [TFS 1.1] Item's upgrading by jewels

oh i see .. i will try this. another thing. this script works just clicking on the item right?

or i need to have a special item (e.g: upgrade gem) for it to work?

@zbizu

hey man. i'm trying to check if target:isItem() by doing this:

if target:isItem() then
code ...
end

but i'm getting: attempt to call method 'isItem' (a nil value)
 
Last edited by a moderator:
weird. what rev are you using? consider reporting it on github
 
that's not 1.2
it's otx (portuguese fork, with mods and some old stuff)
 
oh fuck, hahaha.

i'm trying to work on the script. any news i'll post here

@zbizu

hey man. i'm almost finished. The only problem are on these two functions of the attributes function:

Item(uid):getAttribute(key) -> used on: local attr = Item(uid):getAttribute(key)

error:
Lua Script Error: [Action Interface]
data/actions/scripts/upgrading.lua:eek:nUse
data/global.lua:207: attempt to index a nil value
stack traceback:
[C]: in function '__index'
data/global.lua:207: in function 'getItemAttribute'
data/actions/scripts/upgrading.lua:81: in function <data/actions/scripts/upgrading.lua:79>

Item(uid):setAttribute(key, value) -> used on: return Item(uid):setAttribute(key, value)
error:
Lua Script Error: [Action Interface]
data/actions/scripts/upgrading.lua:eek:nUse
data/actions/scripts/upgrading.lua:86: attempt to index a nil value
stack traceback:
[C]: in function '__index'
data/actions/scripts/upgrading.lua:86: in function <data/actions/scripts/upgrading.lua:79>

Do you happen to know what is causing this issue?

edit: in my compat.lua i use the setAttribute function. obs: i didn't write this script. it already came with the files
function doSetItemText(uid, text)
local item = Item(uid)
if item == nil then
return false
end

if text ~= "" then
item:setAttribute(ITEM_ATTRIBUTE_TEXT, text)
else
item:removeAttribute(ITEM_ATTRIBUTE_TEXT)
end
return true
end

Ty :)
 
Last edited by a moderator:
@zbizu

i have already done that. the problem is with the Item(uid). If i try to do local item = Item(uid) the object item receives a null value
 
thanks man. that worked :)

@zbizu

now i have just one more problem. I have leveled the item to +1.
But when i try to go to +2 it just gets the lvl 0 instead of the actual level

I think it's happening because when i click the Item (in my case a Demon Armor) i'm getting the id of a regular Demon Armor

So it just keeps repeating the +1 step
 
Last edited by a moderator:
Hello! Im using 1.1 and i get this error! Did everything you said! :/

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/upgrading.lua:onUse
data/global.lua:53: attempt to index a nil value
stack traceback:
             [C]: in function '__index'
             data/global.lua:53: in function 'getItemAtttribute'
             data/actions/scripts/upgrading.lua:52: in Function <data/actions/scripts/upgrading.lua:50>
Any solution? thanks
 
hi, good job ! works fine here.
But is possible block to use in wands/staffs?
 
hi, good job ! works fine here.
But is possible block to use in wands/staffs?

Try changing this line:
Code:
if((it:getWeaponType() > 0 or getItemAttribute(itemEx.uid, ITEM_ATTRIBUTE_ARMOR) > 0) and not isItemStackable(itemEx.itemid))then

to:
Code:
if (((it:getWeaponType() > 0 and it:getWeaponType() ~= WEAPON_WAND) or getItemAttribute(itemEx.uid, ITEM_ATTRIBUTE_ARMOR) > 0) and not isItemStackable(itemEx.itemid)) then
 
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/upgrading.lua:onUse
data/actions/scripts/upgrading.lua:52: attempt to call method 'getWeaponType' (a nil value)
stack traceback:
        [C]: in function 'getWeaponType'
        data/actions/scripts/upgrading.lua:52: in function <data/actions/scripts/upgrading.lua:50>

i got this error. I changed function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
TFS1.2 help please that is ultra nice script

needs changing cid to player in onUse and declaring local cid as player:getId()
i dont get it can You explain?
 
Last edited:
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/upgrading.lua:onUse
data/actions/scripts/upgrading.lua:52: attempt to call method 'getWeaponType' (a nil value)
stack traceback:
        [C]: in function 'getWeaponType'
        data/actions/scripts/upgrading.lua:52: in function <data/actions/scripts/upgrading.lua:50>

i got this error. I changed function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
TFS1.2 help please that is ultra nice script


i dont get it can You explain?
Code:
18:11 You see a spike sword+1 (Atk:26, Def:23 +3).
It weighs 50.00 oz.
It can be enchanted with an element.
Item ID: 2383
Position: 95, 134, 7
18:11 Upgrade to level 1 successful!
18:11 You see a spike sword+1 (Atk:26, Def:23 +3).
It weighs 50.00 oz.
It can be enchanted with an element.
Item ID: 2383
Position: 95, 134, 7
18:12 Upgrade to level 2 successful!
18:12 You see a spike sword+2 (Atk:28, Def:25 +4).
It weighs 50.00 oz.
It can be enchanted with an element.
Item ID: 2383
Position: 95, 134, 7
18:12 Upgrade to level 3 successful!
18:12 You see a spike sword+3 (Atk:30, Def:27 +5).
It weighs 50.00 oz.
It can be enchanted with an element.
Item ID: 2383
Position: 95, 134, 7

The script works for me on latest TFS 1.2.
You have to add the functions to end of /data/global.lua


The only thing you need to change is:
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    cid = player:getId()
    itemEx = target

Code:
local conf = {
    ["level"] = {
        -- [item_level] = {successPercent= CHANCE TO UPGRADE ITEM, downgradeLevel = ITEM GETS THIS LEVEL IF UPGRADE FAILS}
        [1] = {successPercent = 85, downgradeLevel = 0},
        [2] = {successPercent = 80, downgradeLevel = 1},
        [3] = {successPercent = 75, downgradeLevel = 2},
        [4] = {successPercent = 70, downgradeLevel = 3},
        [5] = {successPercent = 65, downgradeLevel = 4},
        [6] = {successPercent = 60, downgradeLevel = 5},
        [7] = {successPercent = 55, downgradeLevel = 0},
        [8] = {successPercent = 50, downgradeLevel = 0},
        [9] = {successPercent = 45, downgradeLevel = 0}
    },

    ["upgrade"] = { -- how many percent attributes are rised?
        attack = 5, -- attack %
        defense = 5, -- defense %
        extraDefense = 10, -- extra defense %
        armor = 5, -- armor %
        hitChance = 5, -- hit chance %
    }
}



-- // do not touch // --
-- Upgrading system by Azi [Ersiu] --
-- Edited for TFS 1.1 by Zbizu --

local upgrading = {
  upValue = function (value, level, percent)
  if value < 0 then return 0 end
     if level == 0 then return value end
     local nVal = value
     for i = 1, level do
       nVal = nVal + (math.ceil((nVal/100*percent)))
     end
  return nVal > 0 and nVal or value
  end,

  getLevel = function (item)
  local name = Item(item):getName():split('+')
     if (#name == 1) then
       return 0
     end

     return math.abs(name[2])
  end,
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    cid = player:getId()
    itemEx = target

    local it = ItemType(itemEx.itemid)

if((it:getWeaponType() > 0 or getItemAttribute(itemEx.uid, ITEM_ATTRIBUTE_ARMOR) > 0) and not isItemStackable(itemEx.itemid))then
    local level = upgrading.getLevel(itemEx.uid)
    if(level < #conf["level"])then
      local nLevel = (conf["level"][(level+1)].successPercent >= math.random(1,100)) and (level+1) or conf["level"][level].downgradeLevel
      if(nLevel > level)then
        doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Upgrade to level " .. nLevel .. " successful!")
      else
        doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Upgrade failed. Your " .. it:getName() .. " is now on level " .. nLevel .. "")
      end
      doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_NAME, it:getName()..((nLevel>0) and "+"..nLevel or ""))
      doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_ATTACK,  upgrading.upValue(it:getAttack(), nLevel, conf["upgrade"].attack))
      doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_DEFENSE, upgrading.upValue(it:getDefense(), nLevel, conf["upgrade"].defense))
      doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_EXTRADEFENSE, upgrading.upValue(it:getExtraDefense(), nLevel, conf["upgrade"].extraDefense))
      doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_ARMOR, upgrading.upValue(it:getArmor(), nLevel, conf["upgrade"].armor))
      doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_HITCHANCE, upgrading.upValue(it:getHitChance(), nLevel, conf["upgrade"].hitChance))
      doRemoveItem(item.uid, 1)
    else
      doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your " .. it:getName() .. " is on max level alredy.")
    end
  else
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
  end
end
 
Last edited:
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/upgrading.lua:onUse
data/global.lua:124: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/global.lua:124: in function 'getItemAttribute'
        data/actions/scripts/upgrading.lua:57: in function <data/actions/scripts/upgrading.lua:51>

Ill compile now TFS and check it with fresh compiled

With fresh TFS same problem



EDIT:
IT WORKS!
Problem was with item that I used to upgrade other item.
Item need to be (not sure) stackable and when you click on it there must be an option 'Use with...'
 
Last edited:
I did somtehing like that for removing items when someone enchant them for higher lvl than 3 and enchant fail but it doesnt removing items, Why?
Code:
if((it:getWeaponType() > 0 or getItemAttribute(itemEx.uid, ITEM_ATTRIBUTE_ARMOR) > 0) and not isItemStackable(itemEx.itemid))then
    local level = upgrading.getLevel(itemEx.uid)
    if(level < #conf["level"])then
      local nLevel = (conf["level"][(level+1)].successPercent >= math.random(1,100)) and (level+1) or conf["level"][level].downgradeLevel
      if(nLevel > level)then
        doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Upgrade to level " .. nLevel .. " successful!")
      elseif level >= 3 then
                doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Upgrade failed. Your " .. it:getName() .. " has broken.")
                item:remove(itemid)
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Upgrade failed. Your " .. it:getName() .. " is now on level " .. nLevel .. "")
                doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
           
        end

item:remove() - nothing happens, item still exist in backpack

MEh... The answer is:
target:remove() work but writing error in script :
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/upgrading.lua:onUse
data/global.lua:165: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/global.lua:165: in function 'doItemSetAttribute'
        data/actions/scripts/upgrading.lua:74: in function <data/actions/scripts/upgrading.lua:51>

meybe there is any solution for errors?

solution for this:

after
if((it:getWeaponType() > 0 or getItemAttribute(itemEx.uid, ITEM_ATTRIBUTE_ARMOR) > 0) and not isItemStackable(itemEx.itemid))then
add
local x = true

before:
doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_NAME, it:getName()..((nLevel>0) and "+"..nLevel or ""))
add:
if x then

after:
doRemoveItem(item.uid, 1)
add
end

no errors work perfect damn it 3 hours of watching in code and done ;d
 
Last edited:
Great script, I found that if you use this the items have to be items that get a crosshair when you rightclick them(rightclick->use with if you don't have classic controls).

Some good items for this if you want something that stacks would be 8299 or 9970.
Runes also work, for example spell runes that does not have anything set to them.

For non stack I would chose the item suggested already.
 
Back
Top