localUPGRADE_ITEM_ID = 5902-- The upgrade item, e.g., "spooky blue eye"localLIFE_LEECH_INCREMENT = 1-- Percentage to be added to Life LeechlocalMANA_LEECH_INCREMENT = 1-- Percentage to be added to Mana LeechlocalMAX_LEECH_PERCENT = 100-- Maximum limit for Life Leech and Mana LeechlocalFIXED_DAMAGE = 100000000000-- Fixed damage that will be dealt to both the creature and the playerfunctiononUse(cid, item, fromPosition, itemEx, toPosition)-- Check if the player is validifnotisPlayer(cid) thenreturnfalseend-- Get the weapon the player is holding (left or right hand)localweapon = getPlayerSlotItem(cid, CONST_SLOT_LEFT)ifweapon.itemid == 0then
weapon = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)end-- Check if the player is holding a weaponifweapon.itemid == 0then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You need to be holding a weapon to upgrade it.")returnfalseend-- Get current values of Life Leech and Mana Leech (if any)localcurrentLifeLeech = tonumber(getItemAttribute(weapon.uid, "lifeLeech")) or0localcurrentManaLeech = tonumber(getItemAttribute(weapon.uid, "manaLeech")) or0-- Accumulate new leech valueslocalnewLifeLeech = math.min(currentLifeLeech + LIFE_LEECH_INCREMENT, MAX_LEECH_PERCENT)localnewManaLeech = 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 valueslocaldescription = 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 textlocalposition = 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 manalocalmaxMana = getCreatureMaxMana(cid)-- Check if the player has enough manaifgetCreatureMana(cid) >= maxManathenlocaltarget = getCreatureTarget(cid) -- Get the target of the creatureifisCreature(target) then-- Deal fixed damage to the target creature
doTargetCombatHealth(cid, target, COMBAT_UNDEFINEDDAMAGE, -FIXED_DAMAGE, -FIXED_DAMAGE, CONST_ME_SOUND_WHITE)-- Reduce the target's mana by the fixed damage amount (with a cap)localtargetMana = getCreatureMana(target)localnewTargetMana = math.max(0, targetMana - FIXED_DAMAGE) -- Ensure mana doesn't go below 0
doCreatureAddMana(target, -newTargetMana)-- 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! Damage dealt: " .. FIXED_DAMAGE .. " to your target, and drained " .. newTargetMana .. " mana from the target.")else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, "You do not have a valid target to attack.")endelse-- Message if there is not enough mana
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You do not have enough mana to perform the attack!")endreturntrueend
Pergunta
Muvuka 1
Link para o comentário
Compartilhar em outros sites
1 resposta a esta questão
Posts Recomendados