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.
-
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 arquivocreaturescripts.xmlpara adicionar o novo script:
<event type="attack" name="WeaponLeech" script="leechAttack.lua"/>
3.No arquivologin.lua, adicione uma linha para registrar o eventoonAttack:
registerCreatureEvent(cid, "WeaponLeech")


info
Grupo: Artesão
Registrado: 01/03/20
Posts: 110
Reputação: +1
Gênero: Masculino
Char no Tibia: Samuel on Issobra
Editado Outubro 15 por Muvuka