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

Request: Upgrade item level with small topaz rep+++

masterjojje

Tibia geek! :D
Joined
Feb 10, 2009
Messages
158
Reaction score
1
Location
Sweden
Hello, Im in great need of an action script...I want this script to work for tfs 0.3.6pl1 I get this error code: [12/01/2010 04:55:11] [Error - Action Interface]
[12/01/2010 04:55:11] data/actions/scripts/other/upgrade.lua:eek:nUse
[12/01/2010 04:55:11] Description:
[12/01/2010 04:55:11] data/actions/scripts/other/upgrade.lua:54: attempt to index local 'upgradingItem' (a nil value)
[12/01/2010 04:55:11] stack traceback:
[12/01/2010 04:55:11] data/actions/scripts/other/upgrade.lua:54: in function <data/actions/scripts/other/upgrade.lua:50>
This is the script
Code:
local conf = {}


-- // config // --
conf.maxItemLevel = 50 -- max item level 
conf.successChance = 80 -- succes upgrade chance

conf["upgrade"] = { -- how many parcent attributes are rised?
attack = 5, -- attack %
extraAttack = 10, -- extra Attack %
defence = 5, -- defence %
extraDefence = 10, -- extra defence %
armor = 5, -- armor %
attackSpeed = 3, -- attack speed %
hitChance = 5, -- hit chance %
shootRange = 2, -- shoot range %
}

--// end // --

function getItemInfo(item)

local attr = {}
local name = string.explode(getItemAttribute(item), '+');
if #name == 1 then
attr.name = name[1]
attr.level = math.abs(0)
else
attr.level = math.abs(name[2])
attr.name = name[1]
end
attr.attack = (getItemAttack(item) > 0) and getItemAttack(item) or 0
attr.extraAttack = (getItemExtraAttack(item) > 0) and getItemExtraAttack(item) or 0
attr.defence = (getItemDefense(item) > 0) and getItemDefense(item) or 0
attr.extraDefence = (getItemExtraDefense(item) > 0) and getItemExtraDefense(item) or 0
attr.armor = (getItemArmor(item) > 0) and getItemArmor(item) or 0
attr.attackSpeed = (getItemAttackSpeed(item) > 0) and getItemAttackSpeed(item) or 0
attr.hitChance = (getItemHitChance(item) > 0) and getItemHitChance(item) or 0
attr.shootRange = (getItemShootRange(item) > 0) and getItemShootRange(item) or 0
attr.weight = (getItemWeight(item) > 0) and getItemWeight(item) or 0

return attr
end

function upgradeValue(value, parcent)
local newValue = math.ceil(((value/100)*parcent)+value)
return (newValue > 0) and newValue or 0
end

function onUse(cid, item, fromPosition, itemEx, toPosition)

if toPosition.x == 65535 then
local upgradingItem = getItemAttribute(itemEx.uid)
if (upgradingItem.attack > 0 or upgradingItem.defence > 0 or upgradingItem.armor > 0 or upgradingItem.shootRange > 1) then
if (upgradingItem.level < conf.maxItemLevel) then
if conf.successChance >= math.random(1,100) then
setItemName(itemEx.uid, upgradingItem.name.." + "..(upgradingItem.level+1))
setItemAttack(itemEx.uid, upgradeValue(upgradingItem.attack, conf["upgrade"].attack))
setItemExtraAttack(itemEx.uid, upgradeValue(upgradingItem.extraAttack, conf["upgrade"].extraAttack))
setItemDefense(itemEx.uid, upgradeValue(upgradingItem.defence, conf["upgrade"].defence))
setItemExtraDefense(itemEx.uid, upgradeValue(upgradingItem.extraDefence, conf["upgrade"].extraDefence))
setItemArmor(itemEx.uid, upgradeValue(upgradingItem.armor, conf["upgrade"].armor))
setItemAttackSpeed(itemEx.uid, upgradeValue(upgradingItem.attackSpeed, conf["upgrade"].attackSpeed))
setItemHitChance(itemEx.uid, upgradeValue(upgradingItem.hitChance, conf["upgrade"].hitChance))
setItemShootRange(itemEx.uid, upgradeValue(upgradingItem.shootRange, conf["upgrade"].shootRange))
doSendMagicEffect(toPosition, 30)
doPlayerSendTextMessage(cid, 22, "Upgraded was successful, your item has become stronger!")
else
doRemoveItem(itemEx.uid, itemEx.type)
doSendMagicEffect(toPosition, 2)
doPlayerSendTextMessage(cid, 22, "Upgrading fail... you lost upgraded item!")
end
doRemoveItem(item.uid, 1)
else
doPlayerSendCancel(cid, "This item is on max level!")
end
else
doPlayerSendCancel(cid, "You cannot upgrade this item!")
end
else
doPlayerSendCancel(cid, "You can upgrading items only in inventory!")
end
return TRUE;
end
I give rep+++
 
Last edited:

Ahtor:
bearpaw.png
(Me XP)
Tested in: TFS 0.3.4
Version
: 1.1


Hello! Well, some months ago my server Pharenight is closed. In it have MANY scripts and alot of them are VERRY good and many peoples are looking for some like them, so i decided post some scripts of this otserv, all scripts made by me. I see many scripts of upgrade and i see an fail in all, its hard to configure items, you need add 1 to 1 in tables, one line by each weapon or one by armor, and 70% of this scripts dont work. But this is more dinamic, you add ONLY the blocked items, this blockd items dont will be upgraded, the script find if the item is an armor, an weapon or is an shield. ^^

So.. lets install it ^^

Got to data/actions/actions.xml and add this tag:

PHP:
<action itemid="8306" script="upgrade.lua"/>
Now go to scripts and create file called upgrade.lua and add it:

Lua:
--- Perfect refine system by Mock the bear (MTB).
--- Email: [email][email protected][/email]
local gain = {
gainArmor='&p+1',loseArmor='&p-1',
gainShield='&s+#',loseShield='&s-(#+1)',
gainAttack='&a+#+1',loseAttack='&a-(#+1)-1',
gainDefense='&d+#+2',loseDefense='&d-(#+1)-2',
chance='100/((#*(1/(@/2)))*(@/2))',  -- This equation its good to use items 0-7.
--- This equation must need return chance in % (0-100) 100 = always, 0 = never.
maxlvl = 7,
blocked_ids = {2488,8881}
}
-- &a = weapon attack
-- &d = weapon defense
-- &s = shield defense
-- &p = armor defense
-- # = weapon curr level
-- @ = max level
function isArmor(uid) -- Function by Mock the bear.
         uid = uid or 0
         if getItemArmor(uid) > 0 and getItemAttack(uid) == 0 and getItemDefense(uid) == 0 and getItemWeaponType(uid) == 0 then
             return TRUE
         end
         return FALSE
end
function isWeapon(uid) -- Function by Mock the bear.
         uid = uid or 0
         local f = getItemWeaponType(uid)
         if f == 1 or f == 2 or f == 3 then
             return TRUE
         end
         return FALSE         
end
function isShield(uid) -- Function by Mock the bear.
         uid = uid or 0
         if getItemWeaponType(uid) == 4 then
             return TRUE
         end
         return FALSE         
end

function getWeaponLevel(uid) -- Function by Mock the bear.
   uid = uid or 0
   local name = getItemName(uid)
   local _,_,lvl = string.find(name,'+(%d+)')
   return tonumber(lvl) or 0
end
function doTransform(s,uid) -- Function by Mock the bear.
    local c = string.gsub(s,'@',gain.maxlvl)
    local c = string.gsub(c,'&a',getItemAttack(uid))
    local c = string.gsub(c,'&d',getItemDefense(uid))
    local c = string.gsub(c,'&s',getItemDefense(uid))
    local c = string.gsub(c,'&p',getItemArmor(uid))
    local c = string.gsub(c,'#',getWeaponLevel(uid))
    local q,err = loadstring('return '..c)
    assert(q,err)
    return assert(q())
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
         toPosition.stackpos = 255
         if isInArray(gain.blocked_ids, itemEx.itemid) == TRUE
          or getItemWeaponType(itemEx.uid) > 4
           or (getItemWeaponType(itemEx.uid) == 0
            and isArmor(itemEx.uid) == FALSE)
             or itemEx.itemid == 0 then
                doPlayerSendTextMessage(cid, 24,"You cant refine this item.")
                return TRUE
         end
         if isCreature(itemEx.uid) == TRUE then
            return FALSE
         end
        local level = getWeaponLevel(itemEx.uid)
        local chance = doTransform(gain.chance,itemEx.uid)
        if chance >= math.random(0,100) or item.actionid >= 1000 then
           if level+1 > gain.maxlvl then
              doSendMagicEffect(toPosition, 2)
              return doPlayerSendTextMessage(cid, 24,"Your item is on max level, you can't upgrade it.")
           else
              setItemName(itemEx.uid, getItemNameById(itemEx.itemid)..' +'..(level+1))
              doPlayerSendTextMessage(cid, 24,"Your item has been upgrated to +"..(level+1)..".")
              doSendMagicEffect(toPosition, 12)
              if isArmor(itemEx.uid) == TRUE then
                 local get = doTransform(gain.gainArmor,itemEx.uid)
                 setItemArmor(itemEx.uid,get)
              elseif isWeapon(itemEx.uid) == TRUE then
                  setItemAttack(itemEx.uid, doTransform(gain.gainAttack,itemEx.uid))
                  setItemDefense(itemEx.uid, doTransform(gain.gainDefense,itemEx.uid))              
              elseif isShield(itemEx.uid) == TRUE then
                  setItemDefense(itemEx.uid, doTransform(gain.gainShield,itemEx.uid))  
              end
           end
        else
           
           if level == 0 then
               doPlayerSendTextMessage(cid, 24,"No effect.")
               doSendMagicEffect(toPosition, 2)
           elseif level == gain.maxlvl then
                  doSendMagicEffect(toPosition, 2)
                  return doPlayerSendTextMessage(cid, 24,"Your item is on max level, you can't upgrade it.")
           elseif level > 0 then
               if level == 1 then
                   setItemName(itemEx.uid, getItemNameById(itemEx.itemid))
                   doPlayerSendTextMessage(cid, 24,"Your item back to normal.")
               else
                   setItemName(itemEx.uid, getItemNameById(itemEx.itemid)..' +'..(level-1))
                   doPlayerSendTextMessage(cid, 24,"Your item back to +"..(level-1)..".")
               end
              if isArmor(itemEx.uid) == TRUE then
                 setItemArmor(itemEx.uid,doTransform(gain.loseArmor,itemEx.uid))
              elseif isWeapon(itemEx.uid) == TRUE then
                  setItemAttack(itemEx.uid, doTransform(gain.loseAttack,itemEx.uid))
                  setItemDefense(itemEx.uid, doTransform(gain.loseDefense,itemEx.uid))              
              elseif isShield(itemEx.uid) == TRUE then
                  setItemDefense(itemEx.uid, doTransform(gain.loseShield,itemEx.uid))  
              end 
           end
           doSendMagicEffect(toPosition, 9)
        end
     doRemoveItem(item.uid,1)   
     return TRUE
end
Congratz, now your otserver have an item upgrade! now its just use itemid 8306 in some item (armor shield or weapon non distance) and this item will be upgraded! If you put actionid 1000 in itemid 8306 (pure energy) the fail chance will be = 0, and sucess chance == 100% ^^

Have fun!


fdssfdsfd.png

Sorry by the bad english XP

You like this script? So give-me rep ^^

repp me :D
 
[12/01/2010 23:06:47] [Error - Action Interface]
[12/01/2010 23:06:47] data/actions/scripts/other/upgrade.lua:eek:nUse
[12/01/2010 23:06:47] Description:
[12/01/2010 23:06:47] data/actions/scripts/other/upgrade.lua:50: attempt to call global 'getItemAttack' (a nil value)
[12/01/2010 23:06:47] stack traceback:
[12/01/2010 23:06:47] data/actions/scripts/other/upgrade.lua:50: in function 'doTransform'
[12/01/2010 23:06:47] data/actions/scripts/other/upgrade.lua:73: in function <data/actions/scripts/other/upgrade.lua:59>
Sorry that script is for 0.3.4 :S
 
Instead of copying all the content from the main post, you could as well link to it.
 
Last edited:
Back
Top