Ir para conteúdo
  • 1

TFS 0.3.6 8.60 O PROBLEMA DESSE CODIGO ELE SÓ TIRA DANO SE DE USE NA CRIATURA TANTO PLAYER QUANTO MONSTRO. ACTION EXEMPLO SUA ARMA FICA 100% AI TEM QUE USE ITEM LEECH PRA DA DANO JUNTO COM ATK


Muvuka

Pergunta

local UPGRADE_ITEM_ID = 5902 -- The upgrade item, in this case, the "scary blue eye"
local LIFE_LEECH_INCREMENT = 1 -- Percentage to be added to Life Leech
local MANA_LEECH_INCREMENT = 1 -- Percentage to be added to Mana Leech
local MAX_LEECH_PERCENT = 100 -- Maximum limit for Life Leech and Mana Leech
local FIXED_DAMAGE = 100000000000 -- Fixed damage to be dealt

function onUse(cid, item, fromPosition, itemEx, toPosition)
    -- Check if the player is valid
    if not isPlayer(cid) then
        return false
    end

    -- Get the weapon the player is holding (left or right hand)
    local weapon = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    if weapon.itemid == 0 then
        weapon = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    end

    -- Check if the player is holding a weapon
    if weapon.itemid == 0 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You need to be holding a weapon to upgrade it.")
        return false
    end

    -- Get the current Life Leech and Mana Leech values (if they exist)
    local currentLifeLeech = tonumber(getItemAttribute(weapon.uid, "lifeLeech")) or 0
    local currentManaLeech = tonumber(getItemAttribute(weapon.uid, "manaLeech")) or 0

    -- Accumulate new leech values, limited by the maximum
    local newLifeLeech = math.min(currentLifeLeech + LIFE_LEECH_INCREMENT, MAX_LEECH_PERCENT)
    local newManaLeech = math.min(currentManaLeech + MANA_LEECH_INCREMENT, MAX_LEECH_PERCENT)

    -- Apply the new Life Leech and Mana Leech values to the weapon
    doItemSetAttribute(weapon.uid, "lifeLeech", newLifeLeech)
    doItemSetAttribute(weapon.uid, "manaLeech", newManaLeech)

    -- Modify the weapon's description to show the new leech values
    local description = getItemAttribute(weapon.uid, "description") or ""
    description = "This weapon now has " .. newLifeLeech .. "% Life Leech and " .. newManaLeech .. "% Mana Leech. The maximum is 100%."
    doItemSetAttribute(weapon.uid, "description", description)

    -- Send a message to the player informing about the upgrade
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your weapon has been upgraded! It now has " .. newLifeLeech .. "% Life Leech and " .. newManaLeech .. "% Mana Leech. The maximum is 100%.")

    -- Display animated text "+Leech!!!" in green (color 35)
    local position = getCreaturePosition(cid)
    doSendAnimatedText(position, "+Leech!!!", 35)

    -- The line that removed the upgrade item has been removed to allow infinite use
    -- doRemoveItem(item.uid, 1) -- REMOVED

    -- Combat logic: damage with the weapon
    local target = getCreatureTarget(cid)
    if isCreature(target) then
        -- Check if the weapon has reached the limit for Life Leech and Mana Leech
        if newLifeLeech == MAX_LEECH_PERCENT and newManaLeech == MAX_LEECH_PERCENT then
            -- Fixed damage from the weapon
            local damage = FIXED_DAMAGE 

            -- Apply the damage to the target
            doTargetCombatHealth(cid, target, COMBAT_UNDEFINEDDAMAGE, -damage, -damage, CONST_ME_EXPLOSIONHIT)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You dealt " .. damage .. " damage with your weapon!")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "Your weapon has not reached the limit to deal damage.")
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You do not have a valid target to attack.")
    end

    return true
end

 

Editado por Muvuka
Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0
local UPGRADE_ITEM_ID = 5902 -- Item para ativar leech
local LIFE_LEECH_INCREMENT = 1 -- Incremento de Life Leech
local MANA_LEECH_INCREMENT = 1 -- Incremento de Mana Leech
local MAX_LEECH_PERCENT = 100 -- Máximo de leech permitido

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if not isPlayer(cid) then
        return false
    end

    local weapon = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    if weapon.itemid == 0 then
        weapon = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    end

    if weapon.itemid == 0 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You need to be holding a weapon to upgrade it.")
        return false
    end

    local currentLifeLeech = tonumber(getItemAttribute(weapon.uid, "lifeLeech")) or 0
    local currentManaLeech = tonumber(getItemAttribute(weapon.uid, "manaLeech")) or 0
    local newLifeLeech = math.min(currentLifeLeech + LIFE_LEECH_INCREMENT, MAX_LEECH_PERCENT)
    local newManaLeech = math.min(currentManaLeech + MANA_LEECH_INCREMENT, MAX_LEECH_PERCENT)

    doItemSetAttribute(weapon.uid, "lifeLeech", newLifeLeech)
    doItemSetAttribute(weapon.uid, "manaLeech", newManaLeech)

    local description = "This weapon now has " .. newLifeLeech .. "% Life Leech and " .. newManaLeech .. "% Mana Leech. The maximum is 100%."
    doItemSetAttribute(weapon.uid, "description", description)

    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your weapon has been upgraded with " .. newLifeLeech .. "% Life Leech and " .. newManaLeech .. "% Mana Leech.")
    local position = getCreaturePosition(cid)
    doSendAnimatedText(position, "+Leech!!!", 35)

    return true
end



 

Agora, configure o dano e o leech para funcionar sempre que a arma equipada atingir uma criatura. Este script pode ser adicionado ao creature scripts do servidor, ativando o leech no evento onAttack.

  1. Adicione este código no arquivo de creature scripts:
    function onAttack(cid, target)
        if not isPlayer(cid) or not isCreature(target) then
            return true
        end
    
        local weapon = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
        if weapon.itemid == 0 then
            weapon = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
        end
    
        local lifeLeech = tonumber(getItemAttribute(weapon.uid, "lifeLeech")) or 0
        local manaLeech = tonumber(getItemAttribute(weapon.uid, "manaLeech")) or 0
    
        if lifeLeech > 0 or manaLeech > 0 then
            local damage = math.random(50, 150) -- Dano variável para cada ataque (ajuste conforme necessário)
            
            doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, -damage, -damage, CONST_ME_EXPLOSIONHIT)
    
            -- Calcula o leech
            local lifeSteal = math.floor((damage * lifeLeech) / 100)
            local manaSteal = math.floor((damage * manaLeech) / 100)
    
            doCreatureAddHealth(cid, lifeSteal)
            doPlayerAddMana(cid, manaSteal)
    
            -- Mensagem opcional para mostrar o leech
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Life Leech: " .. lifeSteal .. " | Mana Leech: " .. manaSteal)
        end
    
        return true
    end


    2.Atualize o arquivo creaturescripts.xml para adicionar o novo script:
     

    <event type="attack" name="WeaponLeech" script="leechAttack.lua"/>


    3.No arquivo login.lua, adicione uma linha para registrar o evento onAttack:
     

registerCreatureEvent(cid, "WeaponLeech")
 

Link para o comentário
Compartilhar em outros sites

  • Quem Está Navegando   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.
×
×
  • Criar Novo...