• 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.4] Slot system by Mock [modified]

royalpala

Active Member
Joined
Dec 31, 2019
Messages
76
Solutions
1
Reaction score
44
hello people, i did small changes on the script that Mock made long ago, this because i didnt like the function of random selection of attributes with just one item, instead I modified the script -just copy&paste and adding items ids- on the script to work with a specific item for a specific attribute (I know it is not perfect or optimal but I tried it and it works perfectly)
all credits to Mock :)

in actions/scripts --- make a file "slot.lua"
Code:
--[[
Slot system 100% by mock \o
]]
---Config
local conf = {
maxSlotCount=2,
ignoredIds={}
}
--End
function choose(...) --- Function by mock.
    local arg = {...}
    return arg[math.random(1,#arg)]
end
if not getItemAttack then
    function getItemAttack(uid)
        return getItemAttribute(uid,'attack')
    end
    function getItemDefense(uid)
        return getItemAttribute(uid,'defense')
    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 and not isItemStackable(uid) then
        return true
    end
    return false
end
function onUse(cid, item, fromPosition, itemEx, toPosition) -- Script by mock the bear (MTB)
    if item.itemid ==8300 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end
    local nam = getItemName(itemEx.uid)
    function getper()
        local n = 1
        for i=1,10 do
            n = n+math.random(0,10)
            if n < 8*i then
                break
            end
        end
        return n
    end
    function getSlotCount(nam)
        local c = 0
        for _ in nam:gmatch('%[(.-)%]') do
            c = c+1
        end
        return c
    end
    if getSlotCount(nam) < conf.maxSlotCount then
        local l = choose('ml','ml')
        local p = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..l..'.+'..p..'%]'
        doSendAnimatedText(toPosition,l..' '..p..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8303 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end
    local nam1 = getItemName(itemEx.uid)
    function getper()
        local nq = 1
        for iq=1,10 do
            nq = nq+math.random(0,10)
            if nq < 8*iq then
                break
            end
        end
        return nq
    end
    function getSlotCount(nam1)
        local cq = 0
        for _ in nam1:gmatch('%[(.-)%]') do
            cq = cq+1
        end
        return cq
    end
    if getSlotCount(nam1) < conf.maxSlotCount then
        local a = choose('hp','hp')
        local q = getper()

        doSendMagicEffect(toPosition,30)
        nam1 = nam1..' ['..a..'.+'..q..'%]'
        doSendAnimatedText(toPosition,a..' '..q..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam1)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8306 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end
    local nam2 = getItemName(itemEx.uid)
    function getper()
        local na = 1
        for ia=1,10 do
            na = na+math.random(0,10)
            if na < 8*ia then
                break
            end
        end
        return na
    end
    function getSlotCount(nam2)
        local cw = 0
        for _ in nam2:gmatch('%[(.-)%]') do
            cw = cw+1
        end
        return cw
    end
    if getSlotCount(nam2) < conf.maxSlotCount then
        local e = choose('mp','mp')
        local r = getper()

        doSendMagicEffect(toPosition,30)
        nam2 = nam2..' ['..e..'.+'..r..'%]'
        doSendAnimatedText(toPosition,e..' '..r..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam2)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8299 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end
    local nam3 = getItemName(itemEx.uid)
    function getper()
        local ns = 1
        for is=1,10 do
            ns = ns+math.random(0,10)
            if ns < 8*is then
                break
            end
        end
        return ns
    end
    function getSlotCount(nam3)
        local ce = 0
        for _ in nam3:gmatch('%[(.-)%]') do
            ce = ce+1
        end
        return ce
    end
    if getSlotCount(nam3) < conf.maxSlotCount then
        local vv = choose('cas','cas')
        local vb = getper()

        doSendMagicEffect(toPosition,30)
        nam3 = nam3..' ['..vv..'.+'..vb..'%]'
        doSendAnimatedText(toPosition,vv..' '..vb..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam3)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8301 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end
    local nam4 = getItemName(itemEx.uid)
    function getper()
        local nd = 1
        for id=1,10 do
            nd = nd+math.random(0,10)
            if nd < 8*id then
                break
            end
        end
        return nd
    end
    function getSlotCount(nam4)
        local cd = 0
        for _ in nam4:gmatch('%[(.-)%]') do
            cd = cd+1
        end
        return cd
    end
    if getSlotCount(nam4) < conf.maxSlotCount then
        local u = choose('dist','dist')
        local o = getper()

        doSendMagicEffect(toPosition,30)
        nam4 = nam4..' ['..u..'.+'..o..'%]'
        doSendAnimatedText(toPosition,u..' '..o..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam4)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8302 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end
    local nam5 = getItemName(itemEx.uid)
    function getper()
        local nb = 1
        for ib=1,10 do
            nb = nb+math.random(0,10)
            if nb < 8*ib then
                break
            end
        end
        return nb
    end
    function getSlotCount(nam5)
        local cb = 0
        for _ in nam5:gmatch('%[(.-)%]') do
            cb = cb+1
        end
        return cb
    end
    if getSlotCount(nam5) < conf.maxSlotCount then
        local g = choose('shield','shield')
        local h = getper()

        doSendMagicEffect(toPosition,30)
        nam5 = nam5..' ['..g..'.+'..h..'%]'
        doSendAnimatedText(toPosition,g..' '..h..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam5)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    return true
end


in actions XML


Code:
    <!-- slots -->
    <action itemid="8300" event="script" value="other/slot.lua"/>
    <action itemid="8306" event="script" value="other/slot.lua"/>
    <action itemid="8303" event="script" value="other/slot.lua"/>
    <action itemid="8299" event="script" value="other/slot.lua"/>
    <action itemid="8302" event="script" value="other/slot.lua"/>
    <action itemid="8301" event="script" value="other/slot.lua"/>

in creaturescripts --- make a file "slot.lua"

Code:
---Script by mock the bear!
local conditionMP,conditionHP,conditionML,conditionCLUB,conditionSHI,conditionDIST,conditionAMP = {},{},{},{},{},{},{}
for i=1,100 do ---Carrega as conditions
--- HP
conditionHP[i] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(conditionHP[i], CONDITION_PARAM_TICKS, -1)
setConditionParam(conditionHP[i], CONDITION_PARAM_STAT_MAXHEALTHPERCENT, 100+i)
setConditionParam(conditionHP[i], CONDITION_PARAM_BUFF, true)
setConditionParam(conditionHP[i], CONDITION_PARAM_SUBID, 50)
--MANA
conditionMP[i] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(conditionMP[i], CONDITION_PARAM_TICKS, -1)
setConditionParam(conditionMP[i], CONDITION_PARAM_STAT_MAXMANAPERCENT, 100+i)
setConditionParam(conditionMP[i], CONDITION_PARAM_BUFF, true)
setConditionParam(conditionMP[i], CONDITION_PARAM_SUBID, 51)
--Magic level
conditionML[i] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(conditionML[i], CONDITION_PARAM_TICKS, -1)
setConditionParam(conditionML[i], CONDITION_PARAM_STAT_MAGICLEVELPERCENT, 100+i)
setConditionParam(conditionML[i], CONDITION_PARAM_BUFF, true)
setConditionParam(conditionML[i], CONDITION_PARAM_SUBID, 52)
--club axe sword
conditionCLUB[i] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(conditionCLUB[i], CONDITION_PARAM_TICKS, -1)
setConditionParam(conditionCLUB[i], CONDITION_PARAM_SKILL_CLUBPERCENT, 100+i)
setConditionParam(conditionCLUB[i], CONDITION_PARAM_SKILL_SWORDPERCENT, 100+i)
setConditionParam(conditionCLUB[i], CONDITION_PARAM_SKILL_AXEPERCENT, 100+i)
setConditionParam(conditionCLUB[i], CONDITION_PARAM_BUFF, true)
setConditionParam(conditionCLUB[i], CONDITION_PARAM_SUBID, 53)
--- shield
conditionSHI[i] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(conditionSHI[i], CONDITION_PARAM_TICKS, -1)
setConditionParam(conditionSHI[i], CONDITION_PARAM_SKILL_SHIELDPERCENT, 100+i)
setConditionParam(conditionSHI[i], CONDITION_PARAM_BUFF, true)
setConditionParam(conditionSHI[i], CONDITION_PARAM_SUBID, 54)
--- dist
conditionDIST[i] = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(conditionDIST[i], CONDITION_PARAM_TICKS, -1)
setConditionParam(conditionDIST[i], CONDITION_PARAM_SKILL_DISTANCEPERCENT, 100+i)
setConditionParam(conditionDIST[i], CONDITION_PARAM_BUFF, true)
setConditionParam(conditionDIST[i], CONDITION_PARAM_SUBID, 55)
end
function getSlotType(n) --By mock the bear
if not n then
return false
end
if n:match('%[(.+)%]') then
n = n:match('%[(.+)%]')
if n == '?' then
return 0,n
else
return n:match('(.-)%.([+-])(%d+)%%')
end
else
return false
end

end
local function loadSet(cid)
local t = {}
for slot=1,9 do
t[slot] = ''

local s = getPlayerSlotItem(cid,slot).uid
if s ~= 0 then
t[slot] = getItemName(s)
end
end
return t
end
function isInArray2(arr,var) -- Because in some servers it return 1 and 0 and others true and false
for i,b in pairs(arr) do
if var == b then
return true
end
end
return false
end
function check2(cid,i)
if i == 5 or i == 6 then
if isInArray({'head','necklace','backpack','body','legs','feet','ring'},getItemValue(getPlayerSlotItem(cid,i).itemid,'slotType') or '') then
return false
end
end
return true
end
function chk(cid,f)
if not isPlayer(cid) then return end
local t = loadSet(cid)
for i=1,#f do
if f[i] ~= t[i] then
equip(cid,nil,slot)
break
end
end
addEvent(chk,2000,cid,t)
end
items = { ---- Only to get attr: slotType because getItemName dont return it -.-'
_VERSION='1.0 By mock',
XML_DIR='data/items/items.xml',
}
do
local ia = os.clock()
io.write('Loading items')
local i = io.open(items.XML_DIR,'r')
local u = i:read(-1)
i:close()
local u = u:match('<items>(.+)</items>')
for mi,id,mid,name,data,me in u:gmatch('<(%a-)%s*id%s*=%s*"(%d+)"%s*(.-)%s*name%s*=%s*"(.-)"%s*>(.-)</(%a*)>') do
if mi == 'item' and me == 'item' then
local td = {name=name,id=id,type=1}
for key,value in data:gmatch('<attribute key="(.-)" value="(.-)"/>') do
td[key] = value
end
for key,value in mid:gmatch('(.-)="(.-)"') do
td[key] = value
end
items[tonumber(id)] = td

items[name] = td
end
end
for mi,id,mid,name,data in u:gmatch('<(%a-)%s*id%s*=%s*"(%d*)"%s*(.-)%s*name%s*=%s*"(%a+)"%s*/>') do
if mi == 'item' then
local td = {name=name,id=id,type=2}
for key,value in mid:gmatch('(.-)="(.-)"') do
td[key] = value
end
items[tonumber(id)] = td
items[name] = td
end
end
io.write('[done '..os.clock()-ia..']\n')
end
function getItemValue(item,value)
return items[item] and items[item][value]
end
function equip(cid,item,slot) --By mock the bear
local HP = getCreatureHealth(cid)
local MP = getCreatureMana(cid)
local t = {}
if item then
local mm,sinal,qto = getSlotType(getItemName(item.uid))
t[mm] = tonumber(qto)
end
for i=1,9 do -- Not on slot 10 > arrow
if i ~= slot then
if getPlayerSlotItem(cid,i).itemid ~= 0 then
local aab = getPlayerSlotItem(cid,i).uid
if aab and check2(cid,i) then
for _ in getItemName(aab):gmatch('(%[.-%])') do
local mm,sinal,qto2 = getSlotType(_)
if mm then
if not t[mm] then
t[mm] = 0
end
t[mm] = t[mm]+tonumber(qto2)

t[mm] = t[mm] > 100 and 100 or t[mm]
end
end
end
end
end
end
local fu = 0
local ca = {}
local s = ''
for sl,n in pairs(t) do
fu = fu+1
s = s..''..n..'% more of '..sl..'\n'
if sl == 'hp' then
doAddCondition(cid,conditionHP[tonumber(n)])
doCreatureAddHealth(cid,HP-getCreatureHealth(cid))
ca[50] = 1
doPlayerSendTutorial(cid,19)
elseif sl == 'mp' then
doAddCondition(cid,conditionMP[tonumber(n)])
doCreatureAddMana(cid,HP-getCreatureMana(cid))
ca[51] = 1
doPlayerSendTutorial(cid,19)
elseif sl == 'ml' then
doAddCondition(cid,conditionML[tonumber(n)])
ca[52] = 1
elseif sl == 'cas' then
doAddCondition(cid,conditionCLUB[tonumber(n)])
ca[53] = 1
elseif sl == 'shield' then
doAddCondition(cid,conditionSHI[tonumber(n)])
ca[54] = 1
elseif sl == 'dist' then
doAddCondition(cid,conditionDIST[tonumber(n)])
ca[55] = 1
end
end
if fu > 0 then
addEvent(doPlayerSendTextMessage,100,cid,24,'You have:\n'..s)
for i=50,55 do
if not ca[i] then
doRemoveCondition(cid,CONDITION_ATTRIBUTES,i)
end
end
else
for i=50,55 do
doRemoveCondition(cid,CONDITION_ATTRIBUTES,i)
end
end
return true
end
function onLogin(cid) ---Script by mock the bear!
equip(cid,nil,slot)
addEvent(chk,2000,cid,loadSet(cid)) -- Here we check!
return TRUE
end

in creaturescripts XML

Code:
<event type="login" name="SlotLogin" script="slot.lua"/>

here´s the thread made by Mock in 2010
 
OP
royalpala

royalpala

Active Member
Joined
Dec 31, 2019
Messages
76
Solutions
1
Reaction score
44
this is the same script, I tried to make it shorter than before
and added a script (slot remover) made by Summ on Solved - Upgrading System Heko (https://otland.net/threads/upgrading-system-heko.172509/#post-1681118)
I don't know if it works well, going to try today or tomorrow.

Lua:
--[[
Slot system 100% by mock \o
]]
---Config
local conf = {
maxSlotCount=2,
ignoredIds={}
}
--End
function choose(...) --- Function by mock.
    local arg = {...}
    return arg[math.random(1,#arg)]
end
if not getItemAttack then
    function getItemAttack(uid)
        return getItemAttribute(uid,'attack')
    end
    function getItemDefense(uid)
        return getItemAttribute(uid,'defense')
    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 and not isItemStackable(uid) then
        return true
    end
    return false
end

local nam = getItemName(itemEx.uid)

local removeUpgrade = {
    [2898] = "last", -- "all", "last" or "first"
    [3010] = "first" -- "all", "last" or "first"
}
---------------------------------------------
----local function getper()
        -----local n = math.random(4,10)
       ----- return n
   ---- end
---------------------------------------------
local function getper()
        local n = 1
        for i=1,10 do
            n = n+math.random(0,10)
            if n < 8*i then
                break
            end
        end
        return n
    end

-----------------
local function getSlotCount(nam)
        local c = 0
        for _ in nam:gmatch('%[(.-)%]') do
            c = c+1
        end
        return c
end

local function getSlots(nam)
    local cx = {}
    for slot in nam:gmatch('%[(.-)%]') do
        table.insert(cx, slot)
    end
    return cx
end
----------------   

-------------------------------------INBUIMENT ROMOVER--------------------------------

function onUse(cid, item, fromPosition, itemEx, toPosition) -- Script by mock the bear (MTB)
    if removeUpgrade[item.itemid] then
        if item.uid == 0 or item.itemid == 0 then return false end
        toPosition.stackpos = 255
        if isInArray(conf.ignoredIds, 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 cannot remove a slot from this item. #")
            return true
        end
        if isCreature(itemEx.uid) then
            return false
        end
 
        
        if getSlotCount(nam) >= 1 then
            local slots = getSlots(nam)
            local newName = getItemInfo(itemEx.itemid).name
            for ix = 1, #slots do
                if removeUpgrade[item.itemid] ~= "all" and (not((removeUpgrade[item.itemid] == "first" and ix == 1) or (removeUpgrade[item.itemid] == "last" and ix == #slots))) then
                    newName = newName .. ' [' .. slots[ix] .. ']'
                end
        end

            doSendMagicEffect(toPosition,30)
            doSendAnimatedText(toPosition,'SLOT REMOVED',120)
            doItemSetAttribute(itemEx.uid,'name', newName)
            doRemoveItem(item.uid, 1)
        else
            doPlayerSendTextMessage(cid, 24,"You cannot remove a slot here.")
    end
end 
--------------------------END INBUIMENT REMOVER-----------checar ultimo end y el return antes del ultimo end-----------------

function onUse(cid, item, fromPosition, itemEx, toPosition) -- Script by mock the bear (MTB)
    if item.itemid ==8300 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end

    if getSlotCount(nam) < conf.maxSlotCount then
        local mlv = choose('ml','ml')
        local pml = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..mlv..'.+'..pml..'%]'
        doSendAnimatedText(toPosition,mlv..' '..pml..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8303 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end

    if getSlotCount(nam) < conf.maxSlotCount then
        local hpts = choose('hp','hp')
        local php = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..hpts..'.+'..php..'%]'
        doSendAnimatedText(toPosition,hpts..' '..php..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8306 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end

    if getSlotCount(nam) < conf.maxSlotCount then
        local mpts = choose('mp','mp')
        local pmp = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..mpts..'.+'..pmp..'%]'
        doSendAnimatedText(toPosition,mpts..' '..pmp..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8299 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end

    if getSlotCount(nam) < conf.maxSlotCount then
        local casw = choose('cas','cas')
        local pcas = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..casw..'.+'..pcas..'%]'
        doSendAnimatedText(toPosition,casw..' '..pcas..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8301 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end

    if getSlotCount(nam) < conf.maxSlotCount then
        local dis = choose('dist','dist')
        local pdist = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..dis..'.+'..pdist..'%]'
        doSendAnimatedText(toPosition,dis..' '..pdist..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8302 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end

    if getSlotCount(nam) < conf.maxSlotCount then
        local shi = choose('shield','shield')
        local pshield = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..shi..'.+'..pshield..'%]'
        doSendAnimatedText(toPosition,shi..' '..pshield..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    return true
end
 

itzbrhue3

New Member
Joined
Feb 21, 2017
Messages
31
Solutions
1
Reaction score
1
this is the same script, I tried to make it shorter than before
and added a script (slot remover) made by Summ on Solved - Upgrading System Heko (https://otland.net/threads/upgrading-system-heko.172509/#post-1681118)
I don't know if it works well, going to try today or tomorrow.

Lua:
--[[
Slot system 100% by mock \o
]]
---Config
local conf = {
maxSlotCount=2,
ignoredIds={}
}
--End
function choose(...) --- Function by mock.
    local arg = {...}
    return arg[math.random(1,#arg)]
end
if not getItemAttack then
    function getItemAttack(uid)
        return getItemAttribute(uid,'attack')
    end
    function getItemDefense(uid)
        return getItemAttribute(uid,'defense')
    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 and not isItemStackable(uid) then
        return true
    end
    return false
end

local nam = getItemName(itemEx.uid)

local removeUpgrade = {
    [2898] = "last", -- "all", "last" or "first"
    [3010] = "first" -- "all", "last" or "first"
}
---------------------------------------------
----local function getper()
        -----local n = math.random(4,10)
       ----- return n
   ---- end
---------------------------------------------
local function getper()
        local n = 1
        for i=1,10 do
            n = n+math.random(0,10)
            if n < 8*i then
                break
            end
        end
        return n
    end

-----------------
local function getSlotCount(nam)
        local c = 0
        for _ in nam:gmatch('%[(.-)%]') do
            c = c+1
        end
        return c
end

local function getSlots(nam)
    local cx = {}
    for slot in nam:gmatch('%[(.-)%]') do
        table.insert(cx, slot)
    end
    return cx
end
----------------  

-------------------------------------INBUIMENT ROMOVER--------------------------------

function onUse(cid, item, fromPosition, itemEx, toPosition) -- Script by mock the bear (MTB)
    if removeUpgrade[item.itemid] then
        if item.uid == 0 or item.itemid == 0 then return false end
        toPosition.stackpos = 255
        if isInArray(conf.ignoredIds, 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 cannot remove a slot from this item. #")
            return true
        end
        if isCreature(itemEx.uid) then
            return false
        end

       
        if getSlotCount(nam) >= 1 then
            local slots = getSlots(nam)
            local newName = getItemInfo(itemEx.itemid).name
            for ix = 1, #slots do
                if removeUpgrade[item.itemid] ~= "all" and (not((removeUpgrade[item.itemid] == "first" and ix == 1) or (removeUpgrade[item.itemid] == "last" and ix == #slots))) then
                    newName = newName .. ' [' .. slots[ix] .. ']'
                end
        end

            doSendMagicEffect(toPosition,30)
            doSendAnimatedText(toPosition,'SLOT REMOVED',120)
            doItemSetAttribute(itemEx.uid,'name', newName)
            doRemoveItem(item.uid, 1)
        else
            doPlayerSendTextMessage(cid, 24,"You cannot remove a slot here.")
    end
end
--------------------------END INBUIMENT REMOVER-----------checar ultimo end y el return antes del ultimo end-----------------

function onUse(cid, item, fromPosition, itemEx, toPosition) -- Script by mock the bear (MTB)
    if item.itemid ==8300 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end

    if getSlotCount(nam) < conf.maxSlotCount then
        local mlv = choose('ml','ml')
        local pml = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..mlv..'.+'..pml..'%]'
        doSendAnimatedText(toPosition,mlv..' '..pml..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8303 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end

    if getSlotCount(nam) < conf.maxSlotCount then
        local hpts = choose('hp','hp')
        local php = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..hpts..'.+'..php..'%]'
        doSendAnimatedText(toPosition,hpts..' '..php..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8306 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end

    if getSlotCount(nam) < conf.maxSlotCount then
        local mpts = choose('mp','mp')
        local pmp = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..mpts..'.+'..pmp..'%]'
        doSendAnimatedText(toPosition,mpts..' '..pmp..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8299 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end

    if getSlotCount(nam) < conf.maxSlotCount then
        local casw = choose('cas','cas')
        local pcas = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..casw..'.+'..pcas..'%]'
        doSendAnimatedText(toPosition,casw..' '..pcas..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8301 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end

    if getSlotCount(nam) < conf.maxSlotCount then
        local dis = choose('dist','dist')
        local pdist = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..dis..'.+'..pdist..'%]'
        doSendAnimatedText(toPosition,dis..' '..pdist..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    if item.itemid ==8302 then
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if item.uid == 0 or item.itemid == 0 then return false end
    toPosition.stackpos = 255
    if isInArray(conf.ignoredIds, 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 open a slot on this item.")
        return TRUE
    end
    if isCreature(itemEx.uid) then
        return FALSE
    end

    if getSlotCount(nam) < conf.maxSlotCount then
        local shi = choose('shield','shield')
        local pshield = getper()

        doSendMagicEffect(toPosition,30)
        nam = nam..' ['..shi..'.+'..pshield..'%]'
        doSendAnimatedText(toPosition,shi..' '..pshield..'%',120)
        doItemSetAttribute(itemEx.uid,'name',nam)
        doRemoveItem(item.uid,1)
    else
        doPlayerSendTextMessage(cid, 24,"You cant open a slot on this item.")
    end
    end
    return true
end
you can edit for works with flat values?
 
OP
royalpala

royalpala

Active Member
Joined
Dec 31, 2019
Messages
76
Solutions
1
Reaction score
44
BUMP! Hello its possible make it worked for wands ands rods??
only works with items that have atk and def

Do you have one with the slot option [Attack Speed + X%]?
nop, I acutually made another system for the attk sped by making new vocations, a little more complex due to edit equipments, spells etc.

Works on TFS 1.X?
I dont know bro, as far as i know you have to "update" all the script as if it were like 1.X

you can edit for works with flat values?
Im kind of in mid of hiatus so...
since this script is for skills it should be simple even for a begginer to make a script to use an object that give you skill
i.e. use rune on yourself = you get 1 skill level of sword

(i think you dont need a script as complex as this one if you want flat values)
 
Last edited:

secondlife

Member
Joined
Aug 1, 2009
Messages
295
Reaction score
21
@royalpala, first of all. Many thanks for this script optimization!

One question, is it possible to make the slot system only work on specific items? ex: only use in golden armor, dsm and mpa.

Thank you, guy!
 

Elgenady

Premium User
Premium User
Joined
Aug 5, 2011
Messages
1,578
Solutions
29
Reaction score
275
@royalpala, first of all. Many thanks for this script optimization!

One question, is it possible to make the slot system only work on specific items? ex: only use in golden armor, dsm and mpa.

Thank you, guy!
Lua:
local allowed_items = {vvvv,ccccc,xxxxx}
    if(not isInArray(allowed_items, itemEx.itemid)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Sorry, but you can't use this GEM on this item.")
        return true
    end
 
OP
royalpala

royalpala

Active Member
Joined
Dec 31, 2019
Messages
76
Solutions
1
Reaction score
44
is random stats or config in script?
sorry for taking so long to reply. Its been a year since I dont touch my files from my OT at all and I'm struggling to remember a couple of things... and Im not a PRO at all, I just copy & paste code and try a bunch of times until something works.


the following is above the imbuement section:

Lua:
local function getper()
        local n = 1           ------ this gives you at least 1% of imbuement i think
        for i=1,10 do
            n = n+math.random(0,10)  ---- here you assign the percentage of the imbuement, I assigned between 0 and 10%
----------------------------------------then you have n+whatever number you got between 0 and 10
---------------------------------------- minimum you can get is 1% and max is 11%
            if n < 8*i then
                break
            end
        end
        return n
    end
 
Top