• 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

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,323
Solutions
26
Reaction score
2,690
Location
Poland
This is a very very old upgrade system(April 22 2010). It was so good that it deserved to be rewritten.

Credits: @Azi
original thread(0.3.6): http://otland.net/threads/items-upgrading-by-jewels-ver-3-for-tfs-0-3-6.79098/

07:15 You see a runed sword (Atk:45, Def:32 +2).
It can only be wielded properly by players of level 65 or higher.

07:16 You see a runed sword+5 (Atk:60, Def:42 +7).
It can only be wielded properly by players of level 65 or higher.

07:16 You see a runed sword+7 (Atk:67, Def:48 +9).
It can only be wielded properly by players of level 65 or higher.





This script requires these functions to work: [TFS 1.1] attributes functions from 0.3.7

Code:
<action itemid="xxxx" script="upgrading.lua"/>

upgrading.lua:
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(cid, item, fromPosition, itemEx, toPosition)
   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:
Awesome!

Thank You, well done!

Kind Regards,
Eldin.
 
This is also awesome, I'm so thankful for the scripts you're pushing out! Huge contributions to the community! Is there a way to restrict this to vocations? I have a blacksmith voc, and it'd be awesome if only he could upgrade items, if not no worries I'll still use this system :>
 
Is there a way to restrict this to vocations?
first line:
Code:
local vocations = {4, 8}

below:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
add:
Code:
if isInArray(vocations, Player(cid):getVocation():getId()) then

below:
Code:
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
end
add:
Code:
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your vocation cannot upgrade items.")
end
 
friend I get the following error when using

zpwCIXz.png


Uso otx alpha 3, es basado en tfs 1.1.1 ... greetings

Edit: already decided, thanks for the input ... sorry my english
 
May I have a request.
Instead of %, can it be only +1 ?
And for Wand, Rod ? This system is unfair to Sorcerer and druid, can we improve this ?
Also, can we add a modal windows to chose what to add on the item? --> + 1 skill, + 1 magic level, + HP, + mana ?

Ty :)
 
I get this error:
[06/08/2015 18:22:35] [Error - Action Interface]
[06/08/2015 18:22:35] data/actions/scripts/upgrade.lua:eek:nUse
[06/08/2015 18:22:35] Description:
[06/08/2015 18:22:35] data/actions/scripts/upgrade.lua:51: attempt to call global 'ItemType' (a nil value)
[06/08/2015 18:22:35] stack traceback:
[06/08/2015 18:22:35] data/actions/scripts/upgrade.lua:51: in function <data/actions/scripts/upgrade.lua:50>
 
I get this error:
[06/08/2015 18:22:35] [Error - Action Interface]
[06/08/2015 18:22:35] data/actions/scripts/upgrade.lua:eek:nUse
[06/08/2015 18:22:35] Description:
[06/08/2015 18:22:35] data/actions/scripts/upgrade.lua:51: attempt to call global 'ItemType' (a nil value)
[06/08/2015 18:22:35] stack traceback:
[06/08/2015 18:22:35] data/actions/scripts/upgrade.lua:51: in function <data/actions/scripts/upgrade.lua:50>
ItemType class doesn't exist.
Are you using TFS 1.1?
 
Hey zbizu, how can i modify your script so that if the upgrade fails, the item breaks?

is there a funtion deleteItem() ?

TY ;)
 
@zbizu

I am trying to update to 1.2, haha, but i'm getting this error:

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

Here is my line 179 of global.lua:

local i = ItemType(Item(uid):getId())

perhaps, the ItemType does not works like that anymore.

Could you help me with that?
 
Last edited:
@zbizu

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

inside onUse() function

@zbizu

one more thing: when i printed the value for the uid inside the getItemAttribute() function the value was 0.

idk if that helps on finding the error
 
Last edited by a moderator:
try printing:
itemEx.uid
is that nil or 0?
if yes, you'll have to use metatables
 
I'm not sure if it's a bug or it's intended
itemEx is a metatable now

onUse(player, item, fromPosition, target, toPosition, isHotkey)

so you'll have to check things using metatables and check if target:isItem()
 
Back
Top