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

C++ Please can someone help me put Life Leech And Mana Leech Life e Mana Absorb For TFS 0.3.6 Tibia 8.60

samuel157

/root
Joined
Mar 19, 2010
Messages
518
Solutions
3
Reaction score
71
Location
São Paulo, Brazil
GitHub
Samuel10M
THIS WILL GIVE AN UPGRADE ID: 10559

You see a spooky blue eye.
It weighs 0.86 oz.
(Used to upgrade Life Leech and Mana Leech).

CAN SOMEONE COMPILE THIS SYSTEM FOR ME OR SHOW ME A TUTORIAL PLEASE?

I did it

but it doesn't work if anyone can help me I would appreciate it I used data/action/creaturescript instead of source


LUA:
local UPGRADE_ITEM_ID = 5902 -- O item de upgrade, ex: "spooky blue eye"
local LIFE_LEECH_INCREMENT = 1 -- Percentual que será adicionado de Life Leech
local MANA_LEECH_INCREMENT = 1 -- Percentual que será adicionado de Mana Leech
local LEACH_WEAPON_STORAGE = 10001 -- ID do storage para verificar leech na arma

function onUse(cid, item, fromPosition, itemEx, toPosition)
    -- Verifica se o jogador é válido
    if not isPlayer(cid) then
        return false
    end

    -- Obtém a arma que o jogador está segurando (mão esquerda ou direita)
    local weapon = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    if weapon.itemid == 0 then
        weapon = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    end

    -- Verifica se o jogador está segurando uma arma
    if weapon.itemid == 0 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "Você precisa estar segurando uma arma para aprimorá-la.")
        return false
    end

    -- Obtém os valores atuais de Life Leech e Mana Leech (se houver)
    local currentLifeLeech = tonumber(getItemAttribute(weapon.uid, "lifeLeech")) or 0
    local currentManaLeech = tonumber(getItemAttribute(weapon.uid, "manaLeech")) or 0

    -- Acumula os novos valores de leech
    local newLifeLeech = currentLifeLeech + LIFE_LEECH_INCREMENT
    local newManaLeech = currentManaLeech + MANA_LEECH_INCREMENT

    -- Aplica os novos valores de Life Leech e Mana Leech na arma
    doItemSetAttribute(weapon.uid, "lifeLeech", newLifeLeech)
    doItemSetAttribute(weapon.uid, "manaLeech", newManaLeech)

    -- Marca a arma com o storage para indicar que tem leech
    setPlayerStorageValue(cid, LEACH_WEAPON_STORAGE, 1)

    -- Modifica a descrição da arma para mostrar os novos valores de leech
    local description = getItemAttribute(weapon.uid, "description") or ""
    description = "Esta arma agora tem " .. newLifeLeech .. "% Life Leech e " .. newManaLeech .. "% Mana Leech."
    doItemSetAttribute(weapon.uid, "description", description)

    -- Mensagens e efeitos
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Sua arma foi aprimorada! Agora ela possui " .. newLifeLeech .. "% Life Leech e " .. newManaLeech .. "% Mana Leech.")
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)

    -- Remove o item de upgrade
    doRemoveItem(item.uid, 1)

    return true
end

LUA:
-- Configurações
local LEACH_WEAPON_STORAGE = 10001 -- Armazena o valor da arma com leech
local MAX_LEECH = 1000000000 -- O valor máximo que pode ser recuperado (ajuste conforme necessário)
local leechPercent = 0.01 -- 1% de life e mana leech
-- Função para aplicar o leech de vida e mana no jogador
local function applyLeechDamage(cid, damage, target)
    -- Verifica se a arma do jogador tem a habilidade de leech
    if getPlayerStorageValue(cid, LEACH_WEAPON_STORAGE) > 0 then
        -- Aplica o life leech
        local lifeLeech = math.floor(damage * leechPercent)
        if lifeLeech > MAX_LEECH then
            lifeLeech = MAX_LEECH -- Limita o leech de vida
        end
        doCreatureAddHealth(cid, lifeLeech)
        -- Aplica o mana leech
        local manaLeech = math.floor(damage * leechPercent)
        if manaLeech > MAX_LEECH then
            manaLeech = MAX_LEECH -- Limita o leech de mana
        end
        doPlayerAddMana(cid, manaLeech)
        -- Envia o efeito mágico para mostrar o leeching
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)
    end
end
-- Função de combate exemplo, onde o leech será aplicado
function onCombat(cid, target, damage, damageType)
    -- Aplica o leech se a arma tiver a habilidade de leech
    applyLeechDamage(cid, damage, target)
end
 

Attachments

Last edited:
:::CODE::: BY SAMUEL LIFE LEECH MANA LEECH ABSORB

[CREATURESCRIPT]


LUA:
local LEECH_WEAPON_STORAGE = 47892 -- Storage for leech weapon
local FIXED_DAMAGE = 100000000000 -- Adjusted to a more reasonable fixed damage value
local LEECH_PERCENT = 100 -- Percentage of leech for health and mana
local MAX_LEECH = 100 -- Maximum of 100% leech to avoid overpowering

-- Function to calculate and apply leech
local function applyLeech(cid, damage)
    -- Check if the player has the leech ability
    if getPlayerStorageValue(cid, LEECH_WEAPON_STORAGE) <= 0 then
        return
    end

    -- Ensure the damage value is reasonable
    if damage <= 0 then
        return
    end

    -- Calculate the leech amounts
    local lifeLeech = math.floor(damage * math.min(LEECH_PERCENT, MAX_LEECH) / 100)
    local manaLeech = math.floor(damage * math.min(LEECH_PERCENT, MAX_LEECH) / 100)

    -- Apply leech to the player's health and mana
    doCreatureAddHealth(cid, lifeLeech)
    doCreatureAddMana(cid, manaLeech)

    -- Send effect and feedback to the player
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You leeched " .. lifeLeech .. " health and " .. manaLeech .. " mana.")
end

-- Hook into the combat system (use this function in combat scripts)
function onCombat(cid, target)
    -- Check if the target is a valid creature
    if not isCreature(target) then
        return false
    end

    -- Apply fixed damage to the target
    local damageDealt = FIXED_DAMAGE -- Store the damage in a variable for reuse
    doTargetCombatHealth(cid, target, COMBAT_UNDEFINEDDAMAGE, -damageDealt, -damageDealt, CONST_ME_FIREATTACK)

    -- Apply leech based on the fixed damage dealt
    applyLeech(cid, damageDealt)

    return true
end

[ACTION]
LUA:
local UPGRADE_ITEM_ID = 5902 -- The upgrade item
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 -- Lowered fixed damage dealt to the target
local EFFECT_ON_USE = 23 -- Visual effect when used

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 current values of Life Leech and Mana Leech (if any)
    local currentLifeLeech = tonumber(getItemAttribute(weapon.uid, "lifeLeech")) or 0
    local currentManaLeech = tonumber(getItemAttribute(weapon.uid, "manaLeech")) or 0

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

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

    -- Modify the weapon 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."
    doItemSetAttribute(weapon.uid, "description", description)

    -- Messages and effects
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Your weapon has been upgraded! It now has " .. newLifeLeech .. "% Life Leech and " .. newManaLeech .. "% Mana Leech.")
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_FIREATTACK)

    -- Show animated text
    local position = getCreaturePosition(cid) -- Define the position for animated text
    doSendAnimatedText(position, "+Leech", 35) -- Display animated text with color 35 (green)

    -- Remove the upgrade item
    doRemoveItem(item.uid, 1)

    -- Combat logic: use all mana
    local maxMana = getCreatureMaxMana(cid)
    local currentMana = getCreatureMana(cid)
    
    -- Ensure the player has enough mana for the attack
    if currentMana >= maxMana then
        local target = getCreatureTarget(cid)
        
        if isCreature(target) then
            -- Deal fixed damage and reduce the target's mana
            doTargetCombatHealth(cid, target, COMBAT_UNDEFINEDDAMAGE, -FIXED_DAMAGE, -FIXED_DAMAGE, CONST_ME_SOUND_WHITE)

            -- Reduce the target's mana, ensuring it doesn't go below 0
            local targetMana = getCreatureMana(target)
            local drainedMana = math.min(targetMana, FIXED_DAMAGE)
            doCreatureAddMana(target, -drainedMana)

            -- Reduce the player's mana
            doCreatureAddMana(cid, -maxMana)

            -- Send a message about the attack
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You used all your mana to attack! Dealt damage: " .. FIXED_DAMAGE .. " and drained " .. drainedMana .. " mana from the target.")

            -- Apply effect to the target
            doSendMagicEffect(getCreaturePosition(target), EFFECT_ON_USE)
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You do not have a valid target to attack.")
        end
    else
        -- Message if there is not enough mana
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You do not have enough mana to perform the attack!")
    end

    return true
end

IT IS CAUSING A CONFLICT WITH THIS CALL STACK OVERFLOW CODE


LUA:
local lvlcrit = 48913 -- storage para criticos normais
local lvlcritDanger = 48904 -- storage para criticos perigosos
local multiplier = 1.5 -- multiplicador de dano

function onCombat(cid, target)
    if isPlayer(cid) and isCreature(target) then
        local criticalChance = getPlayerStorageValue(cid, lvlcrit) or 0
        local criticalDangerChance = getPlayerStorageValue(cid, lvlcritDanger) or 0
        local chance = math.random(1, 1000) -- Mantém um intervalo razoável

        -- Verifica se a chance de crítico BOOSTER é atingida
        if chance <= (criticalChance * 1) then
            local damage = 1000000000 -- Valor do dano crítico BOOSTER (ajuste conforme necessário)
            doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, -damage, -damage, 255)
            doSendAnimatedText(getCreaturePosition(target), "+DANGER!", 35)
            doSendMagicEffect(getCreaturePosition(cid), 54)
            return true
        end
        
        -- Verifica se a chance de crítico DANGER é atingida
        if chance <= (criticalDangerChance * 2) then
            local damage = 100000000000 -- Valor do dano crítico DANGER (ajuste conforme necessário)
            doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, -damage, -damage, 255)
            doSendAnimatedText(getCreaturePosition(target), "FATALITY!", 190)
            doSendMagicEffect(getCreaturePosition(cid), 52)
            return true
        end
    end
    return true
end
 

Similar threads

Replies
10
Views
405
Back
Top