The title is self explanatory, I am using the Mock the Bear upgrade system, slightly modified, I would like it at the highest level to become another item, or for an NPC to exchange the item at the maximum level for another item. The problem is that in this upgrade system, the item does not receive any ID modifications...
So, would it be possible to use "getItemAttributes" or something like that for the NPC to exchange only items at the maximum level?
e.g. You gives a Golden Armor+6, and receives a Dragon Scale Mail. Or use a "upgrade jewel" on +5 and it g armor turns a DSM at +6..
There is my upgrade system, I'm using TFS 0.4 3777.
So, would it be possible to use "getItemAttributes" or something like that for the NPC to exchange only items at the maximum level?
e.g. You gives a Golden Armor+6, and receives a Dragon Scale Mail. Or use a "upgrade jewel" on +5 and it g armor turns a DSM at +6..
There is my upgrade system, I'm using TFS 0.4 3777.
Lua:
--- Perfect refine system by Mock the bear (MTB).
--- Email: [email][email protected][/email]
-- &a = weapon attack
-- &d = weapon defense
-- &s = shield defense
-- &p = armor defense
-- # = nivel do item
-- @ = max level
local gain = {
gainArmor='&p+1',loseArmor='&p-0',
gainShield='&s+1',loseShield='&s-0',
gainAttack='&a+1',loseAttack='&a-0',
gainDefense='&d+1',loseDefense='&d-0',
chance='(60/math.sqrt((((@/4)+(#*2))/@)*#))',
maxlvl = 6,
allowed_ids = {2400, 2390, 2408, 6528, 7405, 8930, 8931, 8932, 12610, -- swords
2421, 2452, 2453, 7450, 7423, 7431, 8923, 12622, 8928, 8929, --clubs
2415, 2431, 2443, 6553, 7453, 7455, 7435, 8924, 8925, 8926, -- axes
2471, 2474, 2493, 2496, 2506, 9778, --helmets
2472, 2492, 2494, 8877, 8878, 8879, 8880, 2466}}
local it = {
--[itemid] = [percent]
[12639] = 0, -- 0% additional
[12640] = 100, -- 50%
}
if not setItemName then
function setItemName(uid,name)
return doItemSetAttribute(uid,'name',name)
end
function setItemArmor(uid,name)
return doItemSetAttribute(uid,'armor',name)
end
function setItemDefense(uid,name)
return doItemSetAttribute(uid,'defense',name)
end
function setItemAttack(uid,name)
return doItemSetAttribute(uid,'attack',name)
end
function getItemAttack(uid)
return getItemAttribute(uid,'attack')
end
function getItemDefense(uid)
return getItemAttribute(uid,'defense')
end
function getItemArmor(uid)
if type(uid) == 'number' then
return getItemAttribute(uid,'armor')
else
return getItemInfo(uid.itemid).armor
end
end
end
local function isArmor(uid) -- Function by Mock the bear.
if (getItemInfo(uid.itemid).armor ~= 0) and (getItemWeaponType(uid.uid) == 0) then
return true
end
return false
end
local 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
local function isShield(uid) -- Function by Mock the bear.
uid = uid or 0
if getItemWeaponType(uid) == 4 then
return true
end
return false
end
local function isBow(uid) -- Function by Mock the bear.
uid = uid or 0
if getItemWeaponType(uid) == 5 then
return true
end
return false
end
local function getWeaponLevel(uid) -- Function by Mock the bear.
uid = uid or 0
local name = getItemName(uid.uid) or getItemInfo(uid.itemid).name or ''
local lvl = string.match(name,'%s%+(%d+)%s*')
return tonumber(lvl) or 0
end
local function doTransform(s,i) -- Function by Mock the bear.
local c = string.gsub(s,'@',gain.maxlvl)
local c = string.gsub(c,'&a',(getItemAttack(i.uid) ~= 0 and getItemAttack(i.uid) or getItemInfo(i.itemid).attack))
local c = string.gsub(c,'&d',(getItemDefense(i.uid) ~= 0 and getItemDefense(i.uid) or getItemInfo(i.itemid).defense))
local c = string.gsub(c,'&s',(getItemDefense(i.uid) ~= 0 and getItemDefense(i.uid) or getItemInfo(i.itemid).defense))
local c = string.gsub(c,'&p',(getItemArmor(i.uid) ~= 0 and getItemArmor(i.uid) or getItemInfo(i.itemid).armor))
local c = string.gsub(c,'#',getWeaponLevel(i))
local q = assert(loadstring('return '..c))
return math.floor(assert(q()))
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.uid == 0 or item.itemid == 0 then return false end
toPosition.stackpos = 255
if not isInArray(gain.allowed_ids, itemEx.itemid)
or (not getItemWeaponType(itemEx.uid) or getItemWeaponType(itemEx.uid) > 5)
or (getItemWeaponType(itemEx.uid) == 0 and not isArmor(itemEx))
or itemEx.itemid == 0 or itemEx.type > 1 or isItemStackable(itemEx.uid) then
doPlayerSendTextMessage(cid,21,"You cant refine this item.")
return TRUE
end
if isCreature(itemEx.uid) == TRUE then
return FALSE
end
local level = getWeaponLevel(itemEx)
local chance = doTransform(gain.chance,itemEx)
if level == gain.maxlvl then
doSendMagicEffect(toPosition, 2)
return doPlayerSendTextMessage(cid,21,"Your item is on max level, you can't upgrade it.")
end
doPlayerSendTextMessage(cid,24,"Trying refine with "..(chance+it[item.itemid] > 100 and 100 or chance+it[item.itemid]).."% of sucess!")
if chance+it[item.itemid] >= math.random(0,100) then
local nm = getItemName(itemEx.uid)
local slot = nm:match('(%[.+%])') or '' ---If you server use slot system dont change it ^^
slot = slot~='' and ' '..slot or slot
setItemName(itemEx.uid, getItemNameById(itemEx.itemid)..' +'..(level+1)..slot)
addEvent(doPlayerSendTextMessage,500,cid,22,"Your item has been upgrated to +"..(level+1)..slot..".")
doSendMagicEffect(toPosition, 12)
if isArmor(itemEx) then
local get = doTransform(gain.gainArmor,itemEx)
setItemArmor(itemEx.uid,get)
elseif isBow(itemEx.uid) then
setItemDefense(itemEx.uid, doTransform(gain.gainDefense,itemEx))
elseif isWeapon(itemEx.uid) then
setItemAttack(itemEx.uid, doTransform(gain.gainAttack,itemEx))
setItemDefense(itemEx.uid, doTransform(gain.gainDefense,itemEx))
elseif isShield(itemEx.uid) then
setItemAttack(itemEx.uid, doTransform(gain.gainAttack,itemEx))
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, 21,"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-0))
doPlayerSendTextMessage(cid, 21,"You have failed in upgrade of your item.")
end
if isArmor(itemEx) == TRUE then
setItemArmor(itemEx.uid,doTransform(gain.loseArmor ,itemEx))
elseif isWeapon(itemEx.uid) == TRUE then
setItemAttack(itemEx.uid, doTransform(gain.loseAttack,itemEx))
setItemDefense(itemEx.uid, doTransform(gain.loseShield,itemEx))
elseif isShield(itemEx.uid) == TRUE then
setItemDefense(itemEx.uid, doTransform(gain.loseShield,itemEx))
end
end
doSendMagicEffect(toPosition, 9)
end
doRemoveItem(item.uid,1)
return TRUE
end
Post automatically merged:
Last edited: