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

TFS 0.X Custom attributes in upgrade sys by mock the bear

dragon1155

Member
Joined
Mar 5, 2010
Messages
136
Reaction score
8
Hi, i have a problem with implement criticalhitchance to the upgrade runes in Perfect refine system by Mock the bear.
I managed to implement the criticalhitchance attribute in the sources, i modified the mock script so that the rune gives 1% criticalhitchance for each upgrade and this is work well, but problem starts when the weapon already has some critical hit chance attribute before the upgrade - for example, when a weapon has 15% criticalhitchance, after applying upgrade it has 1%

here is script:
LUA:
--- Perfect refine system by Mock the bear (MTB).
-- &a = weapon attack
-- &d = weapon defense
-- &s = shield defense
-- &p = armor defense
-- # = nivel do item
-- @ = max level
local gain = {
gainArmor='&p+(1)',loseArmor='&p-(1)',
gainShield='&s+#',loseShield='&s-(#+1)',
gainAttack='&a+(1*(#))',loseAttack='&a-(1*(#+1))',
gainCrit='&c+(1*(#))',loseCrit='&c-(1-(#+1))',
gainDefense='&d+(1*(#))',loseDefense='&d-(1*(#+1))',
chance='(100/math.sqrt((((@/4)+(#*2))/@)*#))',
maxlvl = 19,
blocked_ids = {8881}
}
local it = {
--[itemid] = [percent]
[8300] = 0, -- 0% additional
[8299] = 31, -- 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 setItemCrit(uid,name)
                return doItemSetAttribute(uid,'criticalhitchance',name)
        end
        function getItemAttack(uid)
                return getItemAttribute(uid,'attack')
        end
        function getItemCrit(uid)
                return getItemAttribute(uid,'criticalhitchance')
        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) == 5 then
                return true
        end
        return false
end
local function isBow(uid) -- Function by Mock the bear.
        uid = uid or 0
        if getItemWeaponType(uid) == 4 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,'&c',(getItemArmor(i.uid) ~= 0 and getItemArmor(i.uid) or getItemInfo(i.itemid).armor))
    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 isInArray(gain.blocked_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, 24,"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, 24,"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, 24,"Your item has been upgrated to +"..(level+1)..slot..".")
            doSendMagicEffect(toPosition, 36)
            if isArmor(itemEx) then
                                local get = doTransform(gain.gainArmor,itemEx)
                                setItemArmor(itemEx.uid,get)
                        elseif isBow(itemEx.uid) then
                                setItemAttack(itemEx.uid, doTransform(gain.gainAttack,itemEx))
                                setItemCrit(itemEx.uid, doTransform(gain.gainCrit,itemEx))
                        elseif isWeapon(itemEx.uid) then
                                setItemAttack(itemEx.uid, doTransform(gain.gainAttack,itemEx))
                                setItemCrit(itemEx.uid, doTransform(gain.gainCrit,itemEx))
                                setItemDefense(itemEx.uid, doTransform(gain.gainDefense,itemEx))
                        elseif isShield(itemEx.uid) then
                                setItemDefense(itemEx.uid, doTransform(gain.gainShield,itemEx))
                        end
        else
                        if level == 0 then
                                addEvent(doPlayerSendTextMessage,500,cid, 24,"No effect.")
                                doSendMagicEffect(toPosition, 2)
                        elseif level > 0 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
                                if level == 1 then
                                        setItemName(itemEx.uid, getItemNameById(itemEx.itemid)..slot)
                                        addEvent(doPlayerSendTextMessage,500,cid, 24,"Your item back to normal.")
                                else
                                        setItemName(itemEx.uid, getItemNameById(itemEx.itemid)..' +'..(level-1)..slot)
                                        addEvent(doPlayerSendTextMessage,500,cid, 24,"Your item back to +"..(level-1)..slot..".")
                                end
                                if isArmor(itemEx) then
                                        setItemArmor(itemEx.uid,doTransform(gain.loseArmor  ,itemEx))
                                elseif isWeapon(itemEx.uid) then
                                        setItemAttack(itemEx.uid, doTransform(gain.loseAttack,itemEx))
                                        setItemCrit(itemEx.uid, doTransform(gain.loseCrit,itemEx))
                                        setItemDefense(itemEx.uid, doTransform(gain.loseDefense,itemEx))
                                elseif isBow(itemEx.uid) then
                                        setItemAttack(itemEx.uid, doTransform(gain.loseAttack,itemEx))
                                        setItemCrit(itemEx.uid, doTransform(gain.loseCrit,itemEx))
                                elseif isShield(itemEx.uid) then
                                        setItemDefense(itemEx.uid, doTransform(gain.loseShield,itemEx))
                                end
                        end
                        doSendMagicEffect(toPosition, 9)
        end
        doRemoveItem(item.uid,1)
        return true
end

you may be wondering why i use this:
LUA:
local c = string.gsub(c,'&c',(getItemArmor(i.uid) ~= 0 and getItemArmor(i.uid) or getItemInfo(i.itemid).armor))
instead of this:
LUA:
local c = string.gsub(c,'&c',(getItemCrit(i.uid) ~= 0 and getItemCrit(i.uid) or getItemInfo(i.itemid).criticalhitchance))

the reason is simple, when I try to use this getItemCrit function, errors like tihs appear in console:
Code:
[16:0:50.281] [Error - Action Interface]
[16:0:50.284] data/actions/scripts/other/upgrade.lua:onUse
[16:0:50.288] Description:
[16:0:50.289] data/actions/scripts/other/upgrade.lua:95: bad argument #3 to 'gsub' (string/function/table expected)
[16:0:50.295] stack traceback:
[16:0:50.297]   [C]: in function 'gsub'
[16:0:50.299]   data/actions/scripts/other/upgrade.lua:95: in function 'doTransform'
[16:0:50.303]   data/actions/scripts/other/upgrade.lua:117: in function <data/actions/scripts/other/upgrade.lua:103>

i have the impression that the problem is very simple to solve, but i dont know what to do :D tfs 0.4
 
bro, im just so stupid
local c = string.gsub(c,'&c',(getItemCrit(i.uid) ~= 0 and getItemCrit(i.uid) or getItemInfo(i.itemid).criticalHitChance))
i forgot what i added to my own sources and i didnt pay attention to the character size. the topic can be closed, sorry for spam xD
 
i sorry for this post ... but i need help :( i post have 30 days + , 0 help

HELLO OTLANDERS I USE THIS SERVER 772 (OLD SERVER)

The SoftCores Version: (1.0.X.S - 4) - Codename: (LORD ZEDD)
Compiled with Microsoft Visual C++ version 14.0 for arch 32 Bits at May 3 2017 00:34:27
A server developed by: Mattyx14 and TFS Developers.

I need a script like refine ONLY 1 USE PER ITEM MANA OR HEALTH.

1 item that when used on another item adds life to this ITEM.
1 item that when used on another item adds mana to this ITEM.

EXAMPLE: I use SD and USE in plate armor.

NORMAL: You see a plate armor (Arm: 10).

AFTER USING "SD" ON PLATE ARMOR.

You see a plate armor (Arm: 10) + 100 Health

AFTER USING "UH" ON PLATE ARMOR.

You see a plate armor (Arm: 10) + 100 Mana

The SD SCRIPT would give +100 life to the player as soon as he used the plate armor. and when he removed the plate armor it would remove the added life.

THE UH SCRIPT would give +100 mana to the player as soon as he used the plate armor. and when he removed the plate armor it would remove the added mana.


I HAVE THIS SCRIPT WORKING IN MY SERVER THIS SCRIPT ADD +ARM +ATK IN ITEN COULD IT BE POSSIBLE TO MODIFY THE SCRIPT TO ADD 100 MANA, AND ANOTHER SCRIPT FOR 100 LIFE? OR A NEW SCRIPT? I WOULD BE VERY THANKFUL!

--- Perfect refine system by Mock the bear (MTB).
--- Email: mock_#####@hotmail.com
local gain = {
gainArmor='&p+1',loseArmor='&p-1',
gainShield='&s+#',loseShield='&s-(#+1)',
gainAttack='&a+(2*(#))',loseAttack='&a-(2*(#+1))',
gainDefense='&d+(2*(#))',loseDefense='&d-(2*(#+1))',
chance='38/((#(1/(@/2)))(@/2))', -- Eu fiz essa equação para variar de +0 a +7 o item
--- Essa equação deve retornar em % a chance do item se refinar (0-100) 100 = sempre, 0 = nunca
maxlvl = 5,
blocked_ids = {2488,8881}
}
-- &a = weapon attack
-- &d = weapon defense
-- &s = shield defense
-- &p = armor defense
-- # = nivel do item
-- @ = max level
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,'attack',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,'attack')
end
function getItemArmor(uid)
if type(uid) == 'number' then
return getItemAttribute(uid,'armor')
else
return getItemInfo(uid.itemid).armor
end
end
end
function isArmor(uid) -- Function by Mock the bear.
if (getItemArmor(uid) and getItemArmor(uid) ~= 0 and not getItemInfo(uid.itemid,'attack') and not getItemInfo(uid.itemid,'defense') and getItemWeaponType(uid.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.match(name,'+(%d)')
return tonumber(lvl) or 0
end
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) or getItemInfo(i.itemid).attack)
local c = string.gsub(c,'&d',getItemDefense(i.uid) or getItemInfo(i.itemid).attack)
local c = string.gsub(c,'&s',getItemDefense(i.uid) or getItemInfo(i.itemid).attack)
local c = string.gsub(c,'&p',getItemArmor(i.uid) or getItemInfo(i.itemid).armor)
local c = string.gsub(c,'#',getWeaponLevel(i.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) == 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)
if chance >= math.random(0,100) or item.actionid >= 1000 or (item.actionid == 500 and math.random(0,100) <= 25) 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) == TRUE then
local get = doTransform(gain.gainArmor,itemEx)
setItemArmor(itemEx.uid,get)
elseif isWeapon(itemEx.uid) == TRUE then
setItemAttack(itemEx.uid, doTransform(gain.gainAttack,itemEx))
setItemDefense(itemEx.uid, doTransform(gain.gainDefense,itemEx))
elseif isShield(itemEx.uid) == TRUE then
setItemDefense(itemEx.uid, doTransform(gain.gainShield,itemEx))
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) == 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.loseDefense,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


can help me ?
 
Back
Top