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

Lua Life Steal Help

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,480
Solutions
9
Reaction score
211
hello folks, I'm trying make a script just for fun, to heal the attacker with % of the damage ...
then I make it but don't work
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not attacker then 
        return true
    end
    if attacker:isPlayer() and attacker:getVocation():getBase():getId() == 4 then
        if isInArray({ORIGIN_MELEE, ORIGIN_RANGED, ORIGIN_SPELL}, origin) and primaryType ~= COMBAT_HEALING then
            local cure = primaryDamage / 100 * 50
            attacker:addHealth(cure, true) 
            attacker:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
I saw it in support board, then I'm trying make it work to help the guy, I don't remember who was D:
thanks in advice
 
hello folks, I'm trying make a script just for fun, to heal the attacker with % of the damage ...
then I make it but don't work
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not attacker then
        return true
    end
    if attacker:isPlayer() and attacker:getVocation():getBase():getId() == 4 then
        if isInArray({ORIGIN_MELEE, ORIGIN_RANGED, ORIGIN_SPELL}, origin) and primaryType ~= COMBAT_HEALING then
            local cure = primaryDamage / 100 * 50
            attacker:addHealth(cure, true)
            attacker:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
I saw it in support board, then I'm trying make it work to help the guy, I don't remember who was D:
thanks in advice
What doesn't work a little bit more information would be helpful?
Also why are you returning primaryDamage, primaryType, secondaryDamage, secondaryType when these values haven't changed?
 
What doesn't work a little bit more information would be helpful?
Also why are you returning primaryDamage, primaryType, secondaryDamage, secondaryType when these values haven't changed?
I don't know how it work exactly, I just take this function from another script ... just for test it
what don't work:
no errors in console when hit a monster or player
don't heal the attacker
 
If you're running TFS 1.0 or higher try this:
Code:
doCreatureAddHealth(cid, health)

In your case I suppose it would be something similar to this
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not attacker then
        return true
    end
    if attacker:isPlayer() and attacker:getVocation():getBase():getId() == 4 then
        if isInArray({ORIGIN_MELEE, ORIGIN_RANGED, ORIGIN_SPELL}, origin) and primaryType ~= COMBAT_HEALING then
            local cure = primaryDamage / 100 * 50
            doCreatureAddHealth(attacker, cure)
            attacker:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

I've not tested this and done it based on the knowledge I have(Which is little, but enough to get through lua with some debugging)


EDIT:
After checking some around I found this(metamethods):
http://pastebin.com/nws8xHmK

addHealth seems to only have 1 argument. You're passing 2
 
tfs 1.2, also I've tryed pass just one argument in the function addHealth(), also, I've printed some parts in the script, this don't run :eek: I don't know why doens't load the functions
 
Script in OP works fine over here. Are you sure the event is registered on the creature that is being hit and not the one who is doing the hitting?
 
yes...
what I did:
1 create the script in creaturescript
2 register the tag
3 register in login
4 load the server
5 login in the character
and nothing happen :eek:
well, the script really work there? :O
please cast the spell "exura gran mas res" near of the target to see if get some error in the console
 
It's the character that gets hit (loses health) that fires the event. Log in 2 characters (one with vocation id 4) and have them hit each other. Having it registered on yourself does nothing unless you get hit by another player and that player is the correct vocation.

I can help you further tomorrow, I need to sign off for today.
 
Back
Top