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

Lua [TFS 1.2] Upgrade Item System - Add magic level?

Eldora

Banned User
Joined
Oct 19, 2009
Messages
604
Reaction score
26
How can I add Magic Level as an upgrade to this script?
Right now it has: Attack, Defense, ExtraDefence, Armor and HitChance

I am using TFS 1.2

Lua:
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
 
there seems to be no expansion to those in the sources or no way to define those attributes.
i believe only way right now is by adding actionid and making onequip lua script for special action ids followed by description added to item?
 
To add Magic Level as an upgrade to this script, you need to modify the following parts:

  1. Add "magicLevel" to the conf table as a new upgrade attribute:

Lua:
conf["upgrade"] = {
attack = 1,
defense = 1,
extraDefense = 1,
armor = 1,
hitChance = 1,
magicLevel = 1 -- add this line
}

  1. Add a new line to the upgrade code block that sets the magic level attribute:

Code:
doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_MAGICLEVEL, upgrading.upValue(it:getMagicLevel(), nLevel, conf["upgrade"].magicLevel))

Here is the modified and optimized code:

Lua:
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))
doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_MAGICLEVEL, upgrading.upValue(it:getMagicLevel(), nLevel, conf["upgrade"].magicLevel))
doRemoveItem(item.uid, 1)
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your " .. it:getName() .. " is already on max level.")
end
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
end
end
 
To add Magic Level as an upgrade to this script, you need to modify the following parts:

  1. Add "magicLevel" to the conf table as a new upgrade attribute:

Lua:
conf["upgrade"] = {
attack = 1,
defense = 1,
extraDefense = 1,
armor = 1,
hitChance = 1,
magicLevel = 1 -- add this line
}

  1. Add a new line to the upgrade code block that sets the magic level attribute:

Code:
doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_MAGICLEVEL, upgrading.upValue(it:getMagicLevel(), nLevel, conf["upgrade"].magicLevel))

Here is the modified and optimized code:

Lua:
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))
doItemSetAttribute(itemEx.uid, ITEM_ATTRIBUTE_MAGICLEVEL, upgrading.upValue(it:getMagicLevel(), nLevel, conf["upgrade"].magicLevel))
doRemoveItem(item.uid, 1)
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your " .. it:getName() .. " is already on max level.")
end
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You cannot upgrade this item.")
end
end



I tried to do it here, but the error in getMagicLevel
 
Back
Top