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

Help with Leech/Mana Leech

Polarbear72

Member
Joined
Mar 3, 2013
Messages
63
Solutions
1
Reaction score
5
Location
USA
I'm running TFS 1.4 on 10.98

I'm trying to script Life Leech/Mana Leech. Any method to add these are greatly helpful. I would prefer to add them to a single item and give the effect to an amulet or weapon etc.

However, if it would be easier to just add a general script to give it to all players that is fine as well.

Thank you in advance for any help. I am new to this and still learning
 
Solution
E
XML:
        <attribute key="manaleechchance" value="100" />
        <attribute key="manaleechamount" value="50" />
        <attribute key="lifeleechchance" value="100" />
        <attribute key="lifeleechamount" value="50" />
at items.xml to the item you want and modify the values, and don't forget to register the item at movements.xml
I am not sure if you mean a weapon, but I have this club weapon that gives a little life steal per hit:

Lua:
    local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
    setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, 1)
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1.0, 0)
 
function onUseWeapon(cid, var)
    local skill = getPlayerSkill(cid,SKILL_CLUB) -- Change this to the type of weapon you are using
    local mat = 0.085*0.5*1*skill+(getPlayerLevel(cid)/5) -- Change 1 to the attack of the weapon
    local min = 5 -- this means 5% minimum healing
    local max = 15 -- this means 15% maximum healing
    local addhealth = math.random((mat * (min/100)), (mat * (max/100)))
 
    if getPlayerLevel(cid) >= 15 then
        doCreatureAddHealth(cid, addhealth)
        doSendAnimatedText(getPlayerPosition(cid),"+"..addhealth.."", TEXTCOLOR_GREEN)
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        doCombat(cid, combat, var)
    else
        doPlayerSendCancel(cid, 'You need level 15 to use this weapon.')
    end
end

Of course, register your club in weapons.xml:

<melee id="5620" level="15" function="script" script="lifesteal/lifestealclub.lua"/>

Things might be a little different for your version as this is OTHire, but hopefully it is a good starting point. Good luck!
 
XML:
        <attribute key="manaleechchance" value="100" />
        <attribute key="manaleechamount" value="50" />
        <attribute key="lifeleechchance" value="100" />
        <attribute key="lifeleechamount" value="50" />
at items.xml to the item you want and modify the values, and don't forget to register the item at movements.xml
 
Solution
I am not sure if you mean a weapon, but I have this club weapon that gives a little life steal per hit:

Lua:
    local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
    setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, 1)
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1.0, 0)
 
function onUseWeapon(cid, var)
    local skill = getPlayerSkill(cid,SKILL_CLUB) -- Change this to the type of weapon you are using
    local mat = 0.085*0.5*1*skill+(getPlayerLevel(cid)/5) -- Change 1 to the attack of the weapon
    local min = 5 -- this means 5% minimum healing
    local max = 15 -- this means 15% maximum healing
    local addhealth = math.random((mat * (min/100)), (mat * (max/100)))
 
    if getPlayerLevel(cid) >= 15 then
        doCreatureAddHealth(cid, addhealth)
        doSendAnimatedText(getPlayerPosition(cid),"+"..addhealth.."", TEXTCOLOR_GREEN)
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        doCombat(cid, combat, var)
    else
        doPlayerSendCancel(cid, 'You need level 15 to use this weapon.')
    end
end

Of course, register your club in weapons.xml:

<melee id="5620" level="15" function="script" script="lifesteal/lifestealclub.lua"/>

Things might be a little different for your version as this is OTHire, but hopefully it is a good starting point. Good luck!

where do I save this script and will it work with any weapon or just a specific one?
Post automatically merged:

XML:
        <attribute key="manaleechchance" value="100" />
        <attribute key="manaleechamount" value="50" />
        <attribute key="lifeleechchance" value="100" />
        <attribute key="lifeleechamount" value="50" />
at items.xml to the item you want and modify the values, and don't forget to register the item at movements.xml

where do i save this and does it work with everything on every char or certain things?
 
you don't save it, you add it to the item you want, for example spike sword:

XML:
    <item id="2383" article="a" name="spike sword">
        <attribute key="weight" value="5000" />
        <attribute key="defense" value="21" />
        <attribute key="attack" value="24" />
        <attribute key="weaponType" value="sword" />
        <attribute key="extradef" value="2" />
        <attribute key="manaleechchance" value="100" />
        <attribute key="manaleechamount" value="50" />
        <attribute key="lifeleechchance" value="100" />
        <attribute key="lifeleechamount" value="50" />
    </item>
 
ok so with that coding it has 100% chance to mana leech 50 mana and life leech 50 hp or is it 50% of damage?

Also if its not 50% of damage how can I make it % of the damage dealt?

Also is it possible to make an amulet give these attributes or only weapons?
Post automatically merged:

you don't save it, you add it to the item you want, for example spike sword:

XML:
    <item id="2383" article="a" name="spike sword">
        <attribute key="weight" value="5000" />
        <attribute key="defense" value="21" />
        <attribute key="attack" value="24" />
        <attribute key="weaponType" value="sword" />
        <attribute key="extradef" value="2" />
        <attribute key="manaleechchance" value="100" />
        <attribute key="manaleechamount" value="50" />
        <attribute key="lifeleechchance" value="100" />
        <attribute key="lifeleechamount" value="50" />
    </item>


I tried this if you look at the weapon it shows the life and mana leech however it does nothing in game but no errors pop up

You see a stonecutter axe (Atk:50, Def:30 +3, hitpoints leech chance +100%, hitpoints leech amount +50%, manapoints leech chance +100%, mana points leech amount +50%).
It can only be wielded properly by players of level 90 or higher.
It weighs 0.99 oz.
You feel the power of this mighty axe. [ID 3319]
Post automatically merged:

I am not sure if you mean a weapon, but I have this club weapon that gives a little life steal per hit:

Lua:
    local combat = createCombatObject()
    setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
    setCombatParam(combat, COMBAT_PARAM_BLOCKSHIELD, 1)
    setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    setCombatFormula(combat, COMBAT_FORMULA_SKILL, 0, 0, 1.0, 0)
 
function onUseWeapon(cid, var)
    local skill = getPlayerSkill(cid,SKILL_CLUB) -- Change this to the type of weapon you are using
    local mat = 0.085*0.5*1*skill+(getPlayerLevel(cid)/5) -- Change 1 to the attack of the weapon
    local min = 5 -- this means 5% minimum healing
    local max = 15 -- this means 15% maximum healing
    local addhealth = math.random((mat * (min/100)), (mat * (max/100)))
 
    if getPlayerLevel(cid) >= 15 then
        doCreatureAddHealth(cid, addhealth)
        doSendAnimatedText(getPlayerPosition(cid),"+"..addhealth.."", TEXTCOLOR_GREEN)
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        doCombat(cid, combat, var)
    else
        doPlayerSendCancel(cid, 'You need level 15 to use this weapon.')
    end
end

Of course, register your club in weapons.xml:

<melee id="5620" level="15" function="script" script="lifesteal/lifestealclub.lua"/>

Things might be a little different for your version as this is OTHire, but hopefully it is a good starting point. Good luck!

I tried this with no luck there are no errors just doesn't do anything
 
Last edited:
It looks like 2 systems here; I would suspect Puncker's is more accurate to your version, mine is for a different older engine and was just meant as a starting point. So for Puncker's, it looks like you added his script to your items.xml. Did you add it to the movements.xml?
Perhaps look in movements.xml and try to copy another thing that looks correct, but change the item id to your axe.

For the script I posted, items.xml gets no modifications, and in your weapons.xml you add
<melee id="5620" level="15" function="script" script="lifesteal/lifestealclub.lua"/> (change 5620 to your axe id, and script location is where you place the first script. It will only work for that specific club; in my case the club with id 5620.

Again, mine is likely outdated, try with Puncker's in full first, good luck!
 
I didn't know i needed to put it in movements.

Do i put it in only movements or movements and items?

Also how do i put it in movements just copy and paste the whole item like this? Or something different
<item id="2383" article="a" name="spike sword">
<attribute key="weight" value="5000" />
<attribute key="defense" value="21" />
<attribute key="attack" value="24" />
<attribute key="weaponType" value="sword" />
<attribute key="extradef" value="2" />
<attribute key="manaleechchance" value="100" />
<attribute key="manaleechamount" value="50" />
<attribute key="lifeleechchance" value="100" />
<attribute key="lifeleechamount" value="50" />
</item>
 
Last edited:
I didn't know i needed to put it in movements.

Do i put it in only movements or movements and items?

Also how do i put it in movements just copy and paste the whole item like this? Or something different
XML:
    <movevent event="Equip" itemid="2383" slot="hand" function="onEquipItem" />
    <movevent event="DeEquip" itemid="2383" slot="hand" function="onDeEquipItem"/>
 
It works perfect thank you for all the responses and help

Now I just need to create custom weapons. Is it possible to create the same weapon but with different stats?

For example could I have Spike Sword that is normal and then could I have Vampiric Spike Sword with life leech on it?
 
Back
Top