• TibiaFace

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

    .
    demo menumenu

    Afiliados



    Votar:

    [Pedido] dodge por atributo

    Compartir:

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

    1[Pedido] dodge por atributo Empty [Pedido] dodge por atributo Mar Jun 21, 2022 11:42 pm

    akane

    akane
    Miembro
    Miembro
    Descripcion escribió:hola a todos, les quería pedir ayuda para agregar un atributo de dodge a mi server que pueda agregarse a los items y den un % de dodge.

    RakenOT me iba a ayudar, pero si alguien mas también puede, se lo agradecería mucho

    ocupo otx 3.10
    Captura del Error escribió:Imagen del error: [Pedido] dodge por atributo Empty
    El error radica en: Consola

    2 participantes

    2[Pedido] dodge por atributo Empty Re: [Pedido] dodge por atributo Miér Jun 22, 2022 10:12 am

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    este es el systema pero esta creado en un reverscripts mendiante un onlook eventcallbak pero el onlook se puede realizar mediante creaturescript.xml y desunir este reverscritps y hacerlos funcional para versiones menores a tfs 1.2

    Código:

    local function getPlayerDodge(player)
        local chance, amount = 0, 0
        for i = 0, 10 do
            local item = player:getSlotItem(i)
            if item then
                chance = chance + (item:getCustomAttribute("dodgeChance") or 0)
                amount = amount + (item:getCustomAttribute("dodgeAmount") or 0)
            end
        end
        return math.min(chance, 100), math.min(amount / 100, 1)
    end

    local function getItemLevel(item)
        local chance = (item:getCustomAttribute("dodgeChance") or 0)
        local amount = (item:getCustomAttribute("dodgeAmount") or 0)
        return math.ceil(math.min((chance / config.maxDodgeChance) * config.maxLevel, (amount / config.maxDodgeAmount)  * config.maxLevel))
    end

    local dodgeHealth = CreatureEvent("DodgeHealthEvent")
    local dodgeSayDelay = 0

    function dodgeHealth.onHealthChange(player, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
        if not attacker or not attacker:isPlayer() then
            return primaryDamage, primaryType, secondaryDamage, secondaryType
        end

        if attacker ~= player then
            local chance, amount = getPlayerDodge(player)
            if chance > 0 and amount > 0 then
                if chance >= math.random(100) then
                    if dodgeSayDelay <= os.mtime() then
                        player:say("Dodge!")
                        dodgeSayDelay = os.mtime() + 3000
                    end
                    if amount >= 1 then
                        player:getPosition():sendMagicEffect(CONST_ME_POFF)
                    end
                    return primaryDamage - (amount * primaryDamage), primaryType, secondaryDamage - (amount * secondaryDamage), secondaryType
                end
            end
        end
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    dodgeHealth:register()

    local dodgeMana = CreatureEvent("DodgeManaEvent")

    function dodgeMana.onManaChange(player, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
        if not attacker or not attacker:isPlayer() then
            return primaryDamage, primaryType, secondaryDamage, secondaryType
        end
       
        if attacker ~= player then
            local chance, amount = getPlayerDodge(player)
            if chance > 0 and amount > 0 then
                if chance >= math.random(100) then
                    if dodgeSayDelay <= os.mtime() then
                        player:say("Dodge!")
                        dodgeSayDelay = os.mtime() + 3000
                    end
                    if amount >= 1 then
                        player:getPosition():sendMagicEffect(CONST_ME_POFF)
                    end
                    return primaryDamage - (amount * primaryDamage), primaryType, secondaryDamage - (amount * secondaryDamage), secondaryType
                end
            end
        end
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end

    dodgeMana:register()

    local function isDodgeItem(iType)
        local weaponType = iType:getWeaponType()
        return weaponType ~= WEAPON_NONE or iType:getAttack() ~= 0 or iType:getDefense() ~= 0 or iType:getExtraDefense() ~= 0 or iType:getHitChance() ~= 0
    end

    local dodgeStone = Action()

    function dodgeStone.onUse(player, item, fromPos, target, toPos, isHotkey)
        if not target or target.uid == 0 or target:isCreature() then
            player:sendCancelMessage("This item only works on items.")
            return true
        end

        if not isDodgeItem(target:getType()) then
            player:sendCancelMessage("Only items with base attributes can be upgraded.")
            return true
        end

        if getItemLevel(target) >= config.maxLevel then
            player:sendCancelMessage("This item is already fully upgraded.")
            return true
        end

        target:setCustomAttribute("dodgeChance", (target:getCustomAttribute("dodgeChance") or 0) + (config.maxDodgeChance / config.maxLevel))
        target:setCustomAttribute("dodgeAmount", (target:getCustomAttribute("dodgeAmount") or 0) + (config.maxDodgeAmount / config.maxLevel))
        target:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
        local itemLevel = getItemLevel(target)
        player:say(string.format("DodgeSuccess +%d!", itemLevel))
        player:sendCancelMessage(string.format("The %s o has been upgraded to level %d!", target:getName(), itemLevel))
        return true
    end

    dodgeStone:id(config.dodgeItemId)
    dodgeStone:register()

    local dodgeBuy = Action()

    function dodgeBuy.onUse(player, item, fromPos, target, toPos, isHotkey)
        if not player:removeMoney(config.price) then
            player:sendCancelMessage(string.format("You don't have enough money, you need %s crystal coins.", config.price / 10000))
            return true
        end

        local dodgeItem = player:addItem(config.dodgeItemId, config.dodgeItemCount)
        if not dodgeItem then
            player:sendCancelMessage("You have no space, free up your inventory.")
            return true
        end

        local position = player:getPosition()
        fromPos:sendDistanceEffect(position, CONST_ANI_SMALLSTONE)
        player:say("DodgeBuySuccess!")
        position:sendMagicEffect(CONST_ME_STUN)

        local itemId = item:getId()
        if itemId == 1945 or itemId == 1946 then
            item:transform(itemId == 1945 and 1946 or 1945)
        end
        return true
    end

    dodgeBuy:aid(config.leverActionId)
    dodgeBuy:register()

    local dodgeLook = EventCallback

    function dodgeLook.onLook(player, thing, position, distance, description)
        if thing:isItem() then
            local chance = (thing:getCustomAttribute("dodgeChance") or 0)
            local amount = (thing:getCustomAttribute("dodgeAmount") or 0)
            if chance ~= 0 and amount ~= 0 then
                description = string.format("%s\n[ Dodge Chance: %s%%, Amount: %s%% ]", description, chance, amount)
            end
        elseif thing:isPlayer() then
            local chance, amount = getPlayerDodge(player)
            if chance ~= 0 and amount ~= 0 then
                description = string.format("%s\n[ Dodge Chance: %s%%, Amount: %s%% ]", description, chance, amount * 100)
            end
        end
        return description
    end

    dodgeLook:register(2)

    local dodgeLogin = CreatureEvent("DodgeLogin")

    function dodgeLogin.onLogin(player)
        player:registerEvent("DodgeHealthEvent")
        player:registerEvent("DodgeManaEvent")
        return true
    end

    dodgeLogin:register()


    este sistema funciona para item como un custom atribute


    Solo hay que configurar el itemId del dodge stone y el actionId de la palanca con la que se compra el dodge stone Características del

    sistema:
    * Agregado al final de la descripción de los items información sobre dodge chancey amountsi los tiene

    [Pedido] dodge por atributo 16205810

    * Se agregó al final de la descripción de la información de los jugadores sobre esquivar chance and amountexactamente el total de todos sus elementos equipados si los tiene

    [Pedido] dodge por atributo 16205811

    * Palanca para comprar esquivar piedras con actionIdleverActionId = 9999

    [Pedido] dodge por atributo 16205812

    [Pedido] dodge por atributo Gif_0910

    * Solo esquiva los daños de los jugadores solo



    [Pedido] dodge por atributo YNU5B25
    2 participantes
    http://www.tibiaface.com

    3[Pedido] dodge por atributo Empty Re: [Pedido] dodge por atributo Miér Jun 22, 2022 3:15 pm

    akane

    akane
    Miembro
    Miembro
    intente hacerlo , pero al usar la piedra en un item sale Only items with base attributes can be upgraded y no hace nada, tampoco da error en la consola ni nada

    Código:
    function onUse(player, item, fromPos, target, toPos, isHotkey)
        if not target or target.uid == 0 or target:isCreature() then
            player:sendCancelMessage("This item only works on items.")
            return true
        end

        if not target or target.uid == 0 or target:getType() then
            player:sendCancelMessage("Only items with base attributes can be upgraded.")
            return true
        end

        if getItemLevel(target) >= config.maxLevel then
            player:sendCancelMessage("This item is already fully upgraded.")
            return true
        end

        target:setCustomAttribute("dodgeChance", (target:getCustomAttribute("dodgeChance") or 0) + (config.maxDodgeChance / config.maxLevel))
        target:setCustomAttribute("dodgeAmount", (target:getCustomAttribute("dodgeAmount") or 0) + (config.maxDodgeAmount / config.maxLevel))
        target:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
        local itemLevel = getItemLevel(target)
        player:say(string.format("DodgeSuccess +%d!", itemLevel))
        player:sendCancelMessage(string.format("The %s o has been upgraded to level %d!", target:getName(), itemLevel))
        return true
    end

    así quedó el script

    2 participantes

    4[Pedido] dodge por atributo Empty Re: [Pedido] dodge por atributo Miér Jun 22, 2022 11:20 pm

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    poncex escribió:intente hacerlo , pero al usar la piedra en un item sale Only items with base attributes can be upgraded y no hace nada, tampoco da error en la consola ni nada

    Código:
    function onUse(player, item, fromPos, target, toPos, isHotkey)
        if not target or target.uid == 0 or target:isCreature() then
            player:sendCancelMessage("This item only works on items.")
            return true
        end

        if not target or target.uid == 0 or target:getType() then
            player:sendCancelMessage("Only items with base attributes can be upgraded.")
            return true
        end

        if getItemLevel(target) >= config.maxLevel then
            player:sendCancelMessage("This item is already fully upgraded.")
            return true
        end

        target:setCustomAttribute("dodgeChance", (target:getCustomAttribute("dodgeChance") or 0) + (config.maxDodgeChance / config.maxLevel))
        target:setCustomAttribute("dodgeAmount", (target:getCustomAttribute("dodgeAmount") or 0) + (config.maxDodgeAmount / config.maxLevel))
        target:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
        local itemLevel = getItemLevel(target)
        player:say(string.format("DodgeSuccess +%d!", itemLevel))
        player:sendCancelMessage(string.format("The %s o has been upgraded to level %d!", target:getName(), itemLevel))
        return true
    end

    así quedó el script


    me falto esto

    Código:

    -- Dodge System
    local config = {
        -- Dodge Stone Setting
        maxDodgeChance = 5,
        maxDodgeAmount = 8,
        maxLevel = 10,

        -- Buy Dodge Stone Settings
        dodgeItemId = 11106,
        dodgeItemCount = 1,
        price = 100 * 10000, -- 100 Crystal Coins
        leverActionId = 9999
    }



    [Pedido] dodge por atributo YNU5B25
    2 participantes
    http://www.tibiaface.com

    5[Pedido] dodge por atributo Empty Re: [Pedido] dodge por atributo Jue Jun 23, 2022 5:18 pm

    akane

    akane
    Miembro
    Miembro
    al final deje el script así

    Actions:

    Código:
    -- Dodge System
    local config = {
        -- Dodge Stone Setting
        maxDodgeChance = 5,
        maxDodgeAmount = 8,
        maxLevel = 10
    }

    function onUse(player, item, fromPos, target, toPos, isHotkey)
        if not target or target.uid == 0 or target:isCreature() then
            player:sendCancelMessage("This item only works on items.")
            return true
        end

        if not isDodgeItem or target:getType() then
            player:sendCancelMessage("Only items with base attributes can be upgraded.")
            return true
        end

        if getItemLevel(target) >= config.maxLevel then
            player:sendCancelMessage("This item is already fully upgraded.")
            return true
        end

        target:setCustomAttribute("dodgeChance", (target:getCustomAttribute("dodgeChance") or 0) + (config.maxDodgeChance / config.maxLevel))
        target:setCustomAttribute("dodgeAmount", (target:getCustomAttribute("dodgeAmount") or 0) + (config.maxDodgeAmount / config.maxLevel))
        target:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
        local itemLevel = getItemLevel(target)
        player:say(string.format("DodgeSuccess +%d!", itemLevel))
        player:sendCancelMessage(string.format("The %s o has been upgraded to level %d!", target:getName(), itemLevel))
        return true
    end

    pero sigue saliendo el mensaje

    y cuando trato de agregar en creaturescript me sale el siguiente error en la consola

    Código:
    [Error - CreatureEvent::configureEvent] Invalid type for creature event: DodgeSystem

    así lo agregue:

    Código:
    <event type="DodgeHealthEvent" name="DodgeSystem" script="dodge system.lua" />
       <event type="DodgeManaEvent" name="DodgeSystem" script="dodge system.lua" />

    2 participantes

    6[Pedido] dodge por atributo Empty Re: [Pedido] dodge por atributo Jue Jun 23, 2022 6:00 pm

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    poncex escribió:al final deje el script así

    Actions:

    Código:
    -- Dodge System
    local config = {
        -- Dodge Stone Setting
        maxDodgeChance = 5,
        maxDodgeAmount = 8,
        maxLevel = 10
    }

    function onUse(player, item, fromPos, target, toPos, isHotkey)
        if not target or target.uid == 0 or target:isCreature() then
            player:sendCancelMessage("This item only works on items.")
            return true
        end

        if not isDodgeItem or target:getType() then
            player:sendCancelMessage("Only items with base attributes can be upgraded.")
            return true
        end

        if getItemLevel(target) >= config.maxLevel then
            player:sendCancelMessage("This item is already fully upgraded.")
            return true
        end

        target:setCustomAttribute("dodgeChance", (target:getCustomAttribute("dodgeChance") or 0) + (config.maxDodgeChance / config.maxLevel))
        target:setCustomAttribute("dodgeAmount", (target:getCustomAttribute("dodgeAmount") or 0) + (config.maxDodgeAmount / config.maxLevel))
        target:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
        local itemLevel = getItemLevel(target)
        player:say(string.format("DodgeSuccess +%d!", itemLevel))
        player:sendCancelMessage(string.format("The %s o has been upgraded to level %d!", target:getName(), itemLevel))
        return true
    end

    pero sigue saliendo el mensaje

    y cuando trato de agregar en creaturescript me sale el siguiente error en la consola

    Código:
    [Error - CreatureEvent::configureEvent] Invalid type for creature event: DodgeSystem

    así lo agregue:

    Código:
    <event type="DodgeHealthEvent" name="DodgeSystem" script="dodge system.lua" />
       <event type="DodgeManaEvent" name="DodgeSystem" script="dodge system.lua" />

    primeramente te doy la idea el vento no se llma eso que colocaste se escribe asi de la siguiente manera

    Código:

    <event type="healthchange"



    [Pedido] dodge por atributo YNU5B25
    2 participantes
    http://www.tibiaface.com

    7[Pedido] dodge por atributo Empty Re: [Pedido] dodge por atributo Jue Jun 23, 2022 6:02 pm

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    y te falta agregar la funciones locales en tu global.lua sin local para que pueda leer el script y hacer comparaciones



    [Pedido] dodge por atributo YNU5B25
    2 participantes
    http://www.tibiaface.com

    Contenido patrocinado


    2 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).