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

Solved Lifesteal Melee Weapon [TFS 1.2]

X X X

Newb
Joined
Jul 26, 2015
Messages
146
Reaction score
13
As the title suggests, I have been trying to create a script for a melee weapon that damages a monster/player each turn, AND heals the user for a percentage of the damage dealt.

I've seen the different threads about "vampriric spell" and "vampiric touch" (Spell - +[Creaturescript] Vampiric touch(Lifesteal atk) Spell - Life steal / Life drain (for X seconds)) or whatever but I've read through those and they aren't what I'm looking for.

I want to be able to just change one club weapon so that it returns health to the user when you attack something with it.

I have a script that I've created, but I know I've done something wrong. I've tried to set up 2 different combats and I'm not good at that. Could someone point me in the right direction? Again, TFS 1.2.

Script:
Code:
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)

local combat2 = createCombatObject()
setCombatParam(combat2, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat2, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat2, COMBAT_PARAM_AGGRESSIVE, FALSE)
setCombatFormula(combat2, COMBAT_FORMULA_LEVELMAGIC, -0.2, -0.2, -0.2, -0.2)
 
function onUseWeapon(cid, var, creature)
    doCombat(cid, combat, var)
    doCombat(creature, combat2, var)
    return true
end

I'm not getting any console errors with the script, but it doesn't quite work. Attacking a monster with the weapon will deal damage to the monster, but it will also "heal" the monster (that is, the monster will have the blue sparkle effect but wont actually gain any HP) instead of healing the player.

Any help is appreciated, I feel like it's really close but I'm making a silly mistake
Regards,
X X X

edit: I know my script I have isn't for a %, but I was trying to get it to heal PERIOD before I worked on healing at a %.
 
Last edited:
Solution
You need to learn some on your own. Here...

Lua:
local combat = createCombatObject()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
local config = {
    weapon_type = 'club', --Options: 'sword' 'axe' 'club' 'distance' 'magic'
    percent_heal_health = 10, --10 percent is added
    combat_type = 'physical', --Options: energy, earth, fire, undefined, lifedrain, manadrain, drown, ice, holy, death
    magicEffect = 12
}
function onUseWeapon(player, var)
    if config.weapon_type == 'sword' then
        SKILL = SKILL_SWORD
    elseif config.weapon_type == 'axe' then
        SKILL = SKILL_AXE
    elseif config.weapon_type == 'club' then
        SKILL = SKILL_CLUB...
You need to learn some on your own. Here...

Lua:
local combat = createCombatObject()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
local config = {
    weapon_type = 'club', --Options: 'sword' 'axe' 'club' 'distance' 'magic'
    percent_heal_health = 10, --10 percent is added
    combat_type = 'physical', --Options: energy, earth, fire, undefined, lifedrain, manadrain, drown, ice, holy, death
    magicEffect = 12
}
function onUseWeapon(player, var)
    if config.weapon_type == 'sword' then
        SKILL = SKILL_SWORD
    elseif config.weapon_type == 'axe' then
        SKILL = SKILL_AXE
    elseif config.weapon_type == 'club' then
        SKILL = SKILL_CLUB
    elseif config.weapon_type == 'distance' then
        SKILL = SKILL_DISTANCE
    end
  
    if config.combat_type == 'energy' then
        COMBAT = COMBAT_ENERGYDAMAGE
    elseif config.combat_type == 'earth' then
        COMBAT = COMBAT_EARTHDAMAGE
    elseif config.combat_type == 'fire' then
        COMBAT = COMBAT_FIREDAMAGE
    elseif config.combat_type == 'undefined' then
        COMBAT = COMBAT_UNDEFINEDDAMAGE
    elseif config.combat_type == 'lifedrain' then
        COMBAT = COMBAT_LIFEDRAIN
    elseif config.combat_type == 'manadrain' then
        COMBAT = COMBAT_MANADRAIN
    elseif config.combat_type == 'drown' then
        COMBAT = COMBAT_DROWNDAMAGE
    elseif config.combat_type == 'ice' then
        COMBAT = COMBAT_ICEDAMAGE
    elseif config.combat_type == 'holy' then
        COMBAT = COMBAT_HOLYDAMAGE
    elseif config.combat_type == 'death' then
        COMBAT = COMBAT_DEATHDAMAGE
    elseif config.combat_type == 'physical' then
        COMBAT = COMBAT_PHYSICALDAMAGE
    end

    if SKILL then
        dmg_min = (player:getSkillLevel(SKILL) * 2) + (player:getLevel())
        dmg_max = (player:getSkillLevel(SKILL) * 2) + (player:getLevel() + 20)
    else
        dmg_min = (player:getMagicLevel() * 2) + (player:getLevel())
        dmg_max = (player:getMagicLevel() * 2) + (player:getLevel() + 20)
    end
    dmg_amount = math.random(dmg_min, dmg_max)
    heal_amount = (config.percent_heal_health / 100) * dmg_amount
    target = Creature(variantToNumber(var))
    doTargetCombatHealth(0, target, COMBAT, -dmg_amount, -dmg_amount, config.magicEffect)
    player:addHealth(heal_amount)
    doCombat(player, combat, var)
    return true
end

How can I make that the healing is calculated from the normal damage of a weapon, so I can use it on any weapon without adding a damage formula.
 
Back
Top