• TibiaFace

    Tibiaface | Una comunidad Open Tibia donde encontras : mapas, scripts, Otserver, npc y amigos etc ...

    .
    demo menumenu

    Afiliados



    Votar:

    [Actions] ITEM UPGRADE SYSTEM

    Compartir:

    Ver el tema anterior Ver el tema siguiente Ir abajo  Mensaje (Página 1 de 1.)

    1[Actions] ITEM UPGRADE SYSTEM Empty [Actions] ITEM UPGRADE SYSTEM Vie Dic 30, 2016 12:07 am

    Andrés Montero

    Andrés Montero
    Nuevo Miembro
    Nuevo Miembro
    Agregar en actions.xml las siguientes líneas:

    Código:
    <action itemid="8306" event="script" value="upgrade.lua"/>
    <action itemid="8305" event="script" value="upgrade.lua"/>

    La primera linea es para el item 8306 que es el upgrader normal.
    La segunda es para el item 8305 que es para el upgrader con un chance adicional.

    2. Ahora creen "upgrade.lua" y copien dentro lo siguiente :


    Código:

    -- &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))',
    gainDefense='&d+(1*(#))',loseDefense='&d-(1*(#+1))',
    chance='(100/math.sqrt((((@/4)+(#*2))/@)*#))',
    maxlvl = 17,
    blocked_ids = {8881}
    }
    local it = {
    --[itemid] = [percent]
    [8306] = 0, -- 0% additional
    [8305] = 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 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, 12)
    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))
    elseif isWeapon(itemEx.uid) then
    setItemAttack(itemEx.uid, doTransform(gain.gainAttack,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))
    setItemDefense(itemEx.uid, doTransform(gain.loseDefense,itemEx))
    elseif isBow(itemEx.uid) then
    setItemAttack(itemEx.uid, doTransform(gain.loseAttack,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

    4 participantes

    2[Actions] ITEM UPGRADE SYSTEM Empty Re: [Actions] ITEM UPGRADE SYSTEM Vie Dic 30, 2016 12:22 am

    lleguite

    lleguite
    Nuevo Miembro
    Nuevo Miembro
    Es bueno, pero es la base andres! donde subiria los atrbitus asi como por ej (protection all, maxhppoints) o cosas asi...

    4 participantes
    http://tibia.com

    3[Actions] ITEM UPGRADE SYSTEM Empty [Actions] Agrega este Vie Dic 30, 2016 12:30 am

    Andrés Montero

    Andrés Montero
    Nuevo Miembro
    Nuevo Miembro
    Primero en el archivo actions.xml agrega esta linea:

    Código:
    <action itemid="8300" event="script" value="slot.lua"/>

    Ahora en la data/actions/scripts crea un archivo llamado slot.lua y dentro pega esto:

    Código:
    ---Config
    local conf = {
    maxSlotCount=2, -- aqui ponen el numero de upgrades que se les pueda dar a los items
    ignoredIds={} -- aqui ponen las Id de los items que no quieren que se les pueda hacer upgrade, recomendado para los donation items
    }
    --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.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('hp','mp','ml','cas','shield','dist')
     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
     return true
    end

    Ahora en creaturescripts.xml pega esta linea:

    Código:
    <event type="login" name="SlotLogin" script="slot.lua"/>


    Ahora en Data/craturescripts/scripts crea un archivo llamado slots.lua y dentro pon esto:

    Código:
    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

    4 participantes

    4[Actions] ITEM UPGRADE SYSTEM Empty Re: [Actions] ITEM UPGRADE SYSTEM Jue Ene 20, 2022 2:21 am

    Jose David Saucedo

    Jose David Saucedo
    Nuevo Miembro
    Nuevo Miembro
    Andrés Montero escribió:Primero en el archivo actions.xml agrega esta linea:

    Código:
    <action itemid="8300" event="script" value="slot.lua"/>

    Ahora en la data/actions/scripts crea un archivo llamado slot.lua y dentro pega esto:

    Código:
    ---Config
    local conf = {
    maxSlotCount=2, -- aqui ponen el numero de upgrades que se les pueda dar a los items
    ignoredIds={} -- aqui ponen las Id de los items que no quieren que se les pueda hacer upgrade, recomendado para los donation items
    }
    --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.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('hp','mp','ml','cas','shield','dist')
     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
     return true
    end

    Ahora en creaturescripts.xml pega esta linea:

    Código:
    <event type="login" name="SlotLogin" script="slot.lua"/>


    Ahora en Data/craturescripts/scripts crea un archivo llamado slots.lua y dentro pon esto:

    Código:
    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


    Me sirvio demaciado tu script amigo gracias



    Andrés Montero escribió:Primero en el archivo actions.xml agrega esta linea:

    Código:
    <action itemid="8300" event="script" value="slot.lua"/>

    Ahora en la data/actions/scripts crea un archivo llamado slot.lua y dentro pega esto:

    Código:
    ---Config
    local conf = {
    maxSlotCount=2, -- aqui ponen el numero de upgrades que se les pueda dar a los items
    ignoredIds={} -- aqui ponen las Id de los items que no quieren que se les pueda hacer upgrade, recomendado para los donation items
    }
    --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.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('hp','mp','ml','cas','shield','dist')
     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
     return true
    end

    Ahora en creaturescripts.xml pega esta linea:

    Código:
    <event type="login" name="SlotLogin" script="slot.lua"/>


    Ahora en Data/craturescripts/scripts crea un archivo llamado slots.lua y dentro pon esto:

    Código:
    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


    Oye amigo estoy usando tu script de upgrade muy bueno por cierto oye te queria preguntar si hay manera que los stats que ofrece no superen el 20% de bonus que dan

    4 participantes

    5[Actions] ITEM UPGRADE SYSTEM Empty Re: [Actions] ITEM UPGRADE SYSTEM Sáb Ene 22, 2022 1:21 pm

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    modifica esta linea

    Código:
    for i=1,100 do ---Carrega as conditions

    a

    Código:
    [code]for i=1,20 do ---Carrega as conditions[/code]


    y esta otra linea

    Código:

     t[mm] = t[mm] > 100 and 100 or t[mm]

    por

    Código:

     t[mm] = t[mm] > 20 and 20 or t[mm]



    [Actions] ITEM UPGRADE SYSTEM YNU5B25
    4 participantes
    http://www.tibiaface.com

    Contenido patrocinado


    4 participantes

    Ver el tema anterior Ver el tema siguiente Volver arriba  Mensaje (Página 1 de 1.)

    Permisos de este foro:
    No puedes responder a temas en este foro.

     

    BienvenidosTibiaFace es una comunidad de Open Tibia. Para participar debes estar registrado (click para Regístrate).