• 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.2] - Define player in condition

Ascuas Funkeln

Rakkedo Game
Joined
Apr 14, 2013
Messages
549
Solutions
32
Reaction score
305
Location
Poland
GitHub
AscuasFunkeln
Hello,

Guys have you an a idea how i can define player here:

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

local condition = Condition(CONDITION_REGENERATION)
condition:setParameter(CONDITION_PARAM_SUBID, 1)
condition:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 20)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 3000)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
combat:setCondition(condition)

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

In this line:
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 20)
Example, change "20" to player level.

I need it exact in this code, not creating function spell.
 
Solution
Possible solution:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local function getConditionRegeneration(player)
    local condition = Condition(CONDITION_REGENERATION)
    condition:setParameter(CONDITION_PARAM_SUBID, 1)
    condition:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000)
    condition:setParameter(CONDITION_PARAM_HEALTHGAIN, player:getLevel())
    condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 3000)
    condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
    return condition
end

function onCastSpell(creature, variant)
    combat:setCondition(getConditionRegeneration(creature))
    return combat:execute(creature...
Possible solution:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local function getConditionRegeneration(player)
    local condition = Condition(CONDITION_REGENERATION)
    condition:setParameter(CONDITION_PARAM_SUBID, 1)
    condition:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000)
    condition:setParameter(CONDITION_PARAM_HEALTHGAIN, player:getLevel())
    condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 3000)
    condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
    return condition
end

function onCastSpell(creature, variant)
    combat:setCondition(getConditionRegeneration(creature))
    return combat:execute(creature, variant)
end
 
Last edited:
Solution
Possible solution:
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function getConditionRegeneration(player)
    local condition = Condition(CONDITION_REGENERATION)
    condition:setParameter(CONDITION_PARAM_SUBID, 1)
    condition:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000)
    condition:setParameter(CONDITION_PARAM_HEALTHGAIN, player:getLevel())
    condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 3000)
    condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
    return condition
end

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

Just improving your solution. :)

Its heavy to create Condition object (and Combat also) and set its parameters every time the spell is released.
You better should create them only once before the whole script, set the needed dynamic parameters within the spell function (in this example, level is the only one real-time data needed) and then set the condition into combat object.

Also, you used a global function just for this callback that is used only once.
If you still want to use a function for it, you could use a local function instead.

I like your codes.

Lua:
-- Static params attached only once

local condition = Condition(CONDITION_REGENERATION)
local combat = Combat()

condition:setParameter(CONDITION_PARAM_SUBID, 1)
condition:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 20)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 3000)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onCastSpell(creature, variant)
  -- Dynamic params attached every time the spell is used
  condition:setParameter(CONDITION_PARAM_HEALTHGAIN, creature:getLevel()) -- Get player's level dinamically

  -- Set condition into combat object
  combat:setCondition(condition)

  -- Execute combat and return its result (if combat returns true, spell should be released; if combat returns false, spell should not also)
  return combat:execute(creature, variant)
end

Note: I DID NOT test it.
 
Just improving your solution. :)

Its heavy to create Condition object (and Combat also) and set its parameters every time the spell is released.
You better should create them only once before the whole script, set the needed dynamic parameters within the spell function (in this example, level is the only one real-time data needed) and then set the condition into combat object.

Also, you used a global function just for this callback that is used only once.
If you still want to use a function for it, you could use a local function instead.

I like your codes.

Lua:
-- Static params attached only once

local condition = Condition(CONDITION_REGENERATION)
local combat = Combat()

condition:setParameter(CONDITION_PARAM_SUBID, 1)
condition:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000)
condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 20)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 3000)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onCastSpell(creature, variant)
  -- Dynamic params attached every time the spell is used
  condition:setParameter(CONDITION_PARAM_HEALTHGAIN, creature:getLevel()) -- Get player's level dinamically

  -- Set condition into combat object
  combat:setCondition(condition)

  -- Execute combat and return its result (if combat returns true, spell should be released; if combat returns false, spell should not also)
  return combat:execute(creature, variant)
end

Note: I DID NOT test it.
The parameters cannot be redefined, so a new condition must be created every time you want to use different parameters, however I understand your point about the global function, it's wrong, that's why I put a possible solution, it's weird that they can't be redefined, it's probably a problem in my sources, I don't know, but you should try to confirm it

in this case I already modified my publication so that the function is local
 
Last edited:
The parameters cannot be redefined, so a new condition must be created every time you want to use different parameters, however I understand your point about the global function, it's wrong, that's why I put a possible solution, it's weird that they can't be redefined, it's probably a problem in my sources, I don't know, but you should try to confirm it

in this case I already modified my publication so that the function is local

The parameters can be redefined, just confirmed it.
You may try that also, if you want and have time for it.
I don't know why is not working in yours. :c

As I know, you should instantiate Combat, Condition and use functions like createCombatArea(...) outside the script's function (so they will instantiated only once).
After that, you can do whatever you want, however you want, whenever you want.

But, it's a common sense that the parameters are set also outside the script's function at the top because mostly of them are constant values (values that never changes), so makes sense to set them only once.
However, when you need to set parameters dynamically, like something based on player's level, you need to set them within script's function that will set the value on every execution of script's function. And the objects like Combat and Condition were developed, as I know, being able to set their parameters in any time. So you could set their parameters dynamically without doing the heavy process of the instantiation again.

Hope you don't get upset about anything I said.
Your code is not wrong, but could be a little bit improved.
I just wanted to help you to improve your skills with something I know, because I like you.

---

@Ascuas Funkeln Set her post as the answer if it works.
 
The parameters can be redefined, just confirmed it.
You may try that also, if you want and have time for it.
I don't know why is not working in yours. :c

As I know, you should instantiate Combat, Condition and use functions like createCombatArea(...) outside the script's function (so they will instantiated only once).
After that, you can do whatever you want, however you want, whenever you want.

But, it's a common sense that the parameters are set also outside the script's function at the top because mostly of them are constant values (values that never changes), so makes sense to set them only once.
However, when you need to set parameters dynamically, like something based on player's level, you need to set them within script's function that will set the value on every execution of script's function. And the objects like Combat and Condition were developed, as I know, being able to set their parameters in any time. So you could set their parameters dynamically without doing the heavy process of the instantiation again.

Hope you don't get upset about anything I said.
Your code is not wrong, but could be a little bit improved.
I just wanted to help you to improve your skills with something I know, because I like you.

---

@Ascuas Funkeln Set her post as the answer if it works.
uwu ok gentleman :v ty
 
The parameters can be redefined, just confirmed it.
You may try that also, if you want and have time for it.
I don't know why is not working in yours. :c

As I know, you should instantiate Combat, Condition and use functions like createCombatArea(...) outside the script's function (so they will instantiated only once).
After that, you can do whatever you want, however you want, whenever you want.

But, it's a common sense that the parameters are set also outside the script's function at the top because mostly of them are constant values (values that never changes), so makes sense to set them only once.
However, when you need to set parameters dynamically, like something based on player's level, you need to set them within script's function that will set the value on every execution of script's function. And the objects like Combat and Condition were developed, as I know, being able to set their parameters in any time. So you could set their parameters dynamically without doing the heavy process of the instantiation again.

Hope you don't get upset about anything I said.
Your code is not wrong, but could be a little bit improved.
I just wanted to help you to improve your skills with something I know, because I like you.

---

@Ascuas Funkeln Set her post as the answer if it works.
Hi, i already done it in little other way and forgott about this thread.
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

local condition = Condition(CONDITION_REGENERATION)
condition:setParameter(CONDITION_PARAM_SUBID, 2)
condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
combat:setCondition(condition)

local function eventRegeneration2(playerId, seconds)
    local player = Player(playerId)
    if seconds > 0 and player then
        local healvalue = (player:getMaxHealth() * 0.05)
        player:addHealth(healvalue)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        addEvent(eventRegeneration2, 1000, playerId, seconds - 1)
doPlayerAddSkillTry(player, SKILL_SHIELD, 1)
    end
    end

function onCastSpell(player, variant)
            player:say("Tension Stance",  TALKTYPE_MONSTER_SAY)
            eventRegeneration2(player:getId(), 10)
        return combat:execute(player, variant)
end

Anyway i tested script as and it works :)
 
Back
Top