• 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 TFS 1.3 Increase max health according to the amount of health player has

Icaraii

Member
Joined
Jan 5, 2020
Messages
169
Reaction score
21
Hello guys, I have this script and don't remember where I get it, but I'm trying to edit one thing on it, but the way I tried, I get error on TFS.

That's the script, it increases 1500 health to my max health points for 5 seconds.
Lua:
local time = 5 * 1000 -- 5 seconds
local gainedHealth = 1500 -- how much health the player will get

local condition = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, gainedHealth)
condition:setParameter(CONDITION_PARAM_SKILL_SWORDPERCENT, -150)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
condition:setParameter(CONDITION_PARAM_TICKS, time)

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:addCondition(condition)


function onCastSpell(creature, variant)
    combat:execute(creature, variant)
    return true
end

What I want to edit is to increase health according to player max health. Example:

Player has 1000 of max health, so when the player uses the spell, increase 10% of his max health, so it would be 1100 for 5 seconds.
So I tried to do this, but it doesn't "player":

Code:
local time = 5 * 1000 -- 5 seconds


local condition = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, gainedHealth)
condition:setParameter(CONDITION_PARAM_SKILL_SWORDPERCENT, -130)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
condition:setParameter(CONDITION_PARAM_TICKS, time)

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:addCondition(condition)


function onCastSpell(creature, variant, player)
local gainedHealth = player:getMaxHealth() * 2 -- how much health the player will get
    combat:execute(creature, variant, player)
    return true
end

What am I doing wrong?
 
Solution
I imagined I would have to move more stuff to the function.
So I did the changes, and I can cast the spell without error, but it does not increase player health.
move this line
Lua:
combat:addCondition(condition)
above
Lua:
combat:execute(creature, variant)

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,366
Solutions
352
Reaction score
3,475
Hello guys, I have this script and don't remember where I get it, but I'm trying to edit one thing on it, but the way I tried, I get error on TFS.

That's the script, it increases 1500 health to my max health points for 5 seconds.
Lua:
local time = 5 * 1000 -- 5 seconds
local gainedHealth = 1500 -- how much health the player will get

local condition = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, gainedHealth)
condition:setParameter(CONDITION_PARAM_SKILL_SWORDPERCENT, -150)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
condition:setParameter(CONDITION_PARAM_TICKS, time)

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:addCondition(condition)


function onCastSpell(creature, variant)
    combat:execute(creature, variant)
    return true
end

What I want to edit is to increase health according to player max health. Example:

Player has 1000 of max health, so when the player uses the spell, increase 10% of his max health, so it would be 1100 for 5 seconds.
So I tried to do this, but it doesn't "player":

Code:
local time = 5 * 1000 -- 5 seconds


local condition = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, gainedHealth)
condition:setParameter(CONDITION_PARAM_SKILL_SWORDPERCENT, -130)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
condition:setParameter(CONDITION_PARAM_TICKS, time)

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:addCondition(condition)


function onCastSpell(creature, variant, player)
local gainedHealth = player:getMaxHealth() * 2 -- how much health the player will get
    combat:execute(creature, variant, player)
    return true
end

What am I doing wrong?
Lua:
local time = 5 * 1000 -- 5 seconds

local condition = Condition(CONDITION_ATTRIBUTES)
-- condition:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, gainedHealth) -- set the parameter when you cast the spell
condition:setParameter(CONDITION_PARAM_SKILL_SWORDPERCENT, -130)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
condition:setParameter(CONDITION_PARAM_TICKS, time)

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:addCondition(condition)

 -- you can't just add player here, and expect it to work. xD
 -- You can change the variable names, but the information that is passed to the function is set in the source.
 -- You can't add new information to the function that doesn't exist.
 
--function onCastSpell(creature, variant, player)

function onCastSpell(creature, variant)

    local gainedHealth = creature:getMaxHealth() * 2 -- how much health the player will get
    condition:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, gainedHealth) -- set the parameter here instead
  
    combat:execute(creature, variant)
    return true
end
 
OP
I

Icaraii

Member
Joined
Jan 5, 2020
Messages
169
Reaction score
21
I imagined I would have to move more stuff to the function.
So I did the changes, and I can cast the spell without error, but it does not increase player health.
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,366
Solutions
352
Reaction score
3,475
I imagined I would have to move more stuff to the function.
So I did the changes, and I can cast the spell without error, but it does not increase player health.
move this line
Lua:
combat:addCondition(condition)
above
Lua:
combat:execute(creature, variant)
 
Solution
OP
I

Icaraii

Member
Joined
Jan 5, 2020
Messages
169
Reaction score
21
combat:addCondition(condition)
It worked, thanks
Post automatically merged:

@Xikini, when I just start the server and uses the spell, it doesn't add the health, do you know why? Also, when I change characters that has different amount of health, it increases the amount of health of the previous character. Example, Character 1 has 100 of life and the spell should add 100% of the player max health, so for character 1 it should be 200 of life. Character 2 has 500 of life and the spell should add 100% of the player max health, so for character 2 it should be 1000 of life, but what happens is that becames 600 of life. Do you know what could be happening?

local time = 5 * 1000 -- 5 seconds


local condition = Condition(CONDITION_ATTRIBUTES)

condition:setParameter(CONDITION_PARAM_SKILL_SWORDPERCENT, -150)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
condition:setParameter(CONDITION_PARAM_TICKS, time)

local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)


function onCastSpell(creature, variant)

local gainedHealth = creature:getMaxHealth() * 1
condition:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, gainedHealth)


combat:execute(creature, variant)
combat:addCondition(condition)
return true
end
Post automatically merged:

I found the solution @Xikini,

I needed to put all the condition inside the function. Now it works fines, thanks for your help
 
Last edited:
Top