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

TFS 1.2 potion/spell multi Conditions

oshrigames

Active Member
Joined
Nov 9, 2012
Messages
222
Reaction score
47
Location
israel
hello :)
i'm using TFS 1.2 (protocol 10.98).

i simply in a lose.. šŸ˜…
i'm trying to create advanced potions that work on multiple Conditions but since i have no errors i don't know how to locate the issues or what goes worng.


example for 2 Conditions
first is: CONDITION_REGENERATION
heal 50 hp per 3 sec for 1 min (1 * 60 * 1000)
second is: CONDITION_ATTRIBUTES
gain 500 to max hp for 1 min (60000)


Lua:
local combat = Combat()
    combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
    combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)
    combat:setCondition(condition)
 
local condition = Condition(CONDITION_REGENERATION)
    condition:setParameter(CONDITION_PARAM_SUBID, 3)
    condition:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000) -- 1 minute
    condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 50) -- heal 50 every 3 sec
    condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 3000)
    condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local condition = Condition(CONDITION_ATTRIBUTES)
    condition:setParameter(CONDITION_PARAM_SUBID, 2)
    condition:setParameter(CONDITION_PARAM_TICKS, 60000) -- 1 minute
    condition:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, 500) -- gain 500 to max hp

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        player:addCondition(condition)
        if player:addCondition(condition) then
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        Item(item.uid):remove(1)
    end
    return true
end


[
CONDITION_NONE,

CONDITION_POISON = 1 << 0,
CONDITION_FIRE = 1 << 1,
CONDITION_ENERGY = 1 << 2,
CONDITION_BLEEDING = 1 << 3,
CONDITION_HASTE = 1 << 4,
CONDITION_PARALYZE = 1 << 5,
CONDITION_OUTFIT = 1 << 6,
CONDITION_INVISIBLE = 1 << 7,
CONDITION_LIGHT = 1 << 8,
CONDITION_MANASHIELD = 1 << 9,
CONDITION_INFIGHT = 1 << 10,
CONDITION_DRUNK = 1 << 11,
CONDITION_EXHAUST_WEAPON = 1 << 12, // unused
CONDITION_REGENERATION = 1 << 13,
CONDITION_SOUL = 1 << 14,
CONDITION_DROWN = 1 << 15,
CONDITION_MUTED = 1 << 16,
CONDITION_CHANNELMUTEDTICKS = 1 << 17,
CONDITION_YELLTICKS = 1 << 18,
CONDITION_ATTRIBUTES = 1 << 19,
CONDITION_FREEZING = 1 << 20,
CONDITION_DAZZLED = 1 << 21,
CONDITION_CURSED = 1 << 22,
CONDITION_EXHAUST_COMBAT = 1 << 23, // unused
CONDITION_EXHAUST_HEAL = 1 << 24, // unused
CONDITION_PACIFIED = 1 << 25, -- unable to melee attack during the debuff
CONDITION_SPELLCOOLDOWN = 1 << 26,
CONDITION_SPELLGROUPCOOLDOWN = 1 << 27,
CONDITION_DAMAGE_IMMUNE = 1 << 28,
CONDITION_IMMUNE = 1 << 29,


CONDITION_PARAM_OWNER = 1,
CONDITION_PARAM_TICKS = 2, -- timer to execute a condition
//CONDITION_PARAM_OUTFIT = 3,
CONDITION_PARAM_HEALTHGAIN = 4, -- gain hp
CONDITION_PARAM_HEALTHTICKS = 5, -- gain hp per sec
CONDITION_PARAM_MANAGAIN = 6, -- gain mana
CONDITION_PARAM_MANATICKS = 7, -- gain mana per sec
CONDITION_PARAM_DELAYED = 8,
CONDITION_PARAM_SPEED = 9, -- gain speed (100 = ingame 50)
CONDITION_PARAM_LIGHT_LEVEL = 10, -- light size
CONDITION_PARAM_LIGHT_COLOR = 11, -- light color
CONDITION_PARAM_SOULGAIN = 12,
CONDITION_PARAM_SOULTICKS = 13,
CONDITION_PARAM_MINVALUE = 14,
CONDITION_PARAM_MAXVALUE = 15,
CONDITION_PARAM_STARTVALUE = 16,
CONDITION_PARAM_TICKINTERVAL = 17,
CONDITION_PARAM_FORCEUPDATE = 18,
CONDITION_PARAM_SKILL_MELEE = 19, -- gain to melee
CONDITION_PARAM_SKILL_FIST = 20, -- gain to fist
CONDITION_PARAM_SKILL_CLUB = 21, -- gain to club
CONDITION_PARAM_SKILL_SWORD = 22, -- gain to sword
CONDITION_PARAM_SKILL_AXE = 23, -- gain to axe
CONDITION_PARAM_SKILL_DISTANCE = 24, -- gain to distance
CONDITION_PARAM_SKILL_SHIELD = 25, -- gain to shield
CONDITION_PARAM_SKILL_FISHING = 26, -- gain to fishing
CONDITION_PARAM_STAT_MAXHITPOINTS = 27, -- gain to max hp
CONDITION_PARAM_STAT_MAXMANAPOINTS = 28, -- gain to max mana
// CONDITION_PARAM_STAT_SOULPOINTS = 29,
CONDITION_PARAM_STAT_MAGICPOINTS = 30,
CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT = 31,
CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT = 32,
// CONDITION_PARAM_STAT_SOULPOINTSPERCENT = 33,
CONDITION_PARAM_STAT_MAGICPOINTSPERCENT = 34,
CONDITION_PARAM_PERIODICDAMAGE = 35,
CONDITION_PARAM_SKILL_MELEEPERCENT = 36,
CONDITION_PARAM_SKILL_FISTPERCENT = 37,
CONDITION_PARAM_SKILL_CLUBPERCENT = 38,
CONDITION_PARAM_SKILL_SWORDPERCENT = 39,
CONDITION_PARAM_SKILL_AXEPERCENT = 40,
CONDITION_PARAM_SKILL_DISTANCEPERCENT = 41,
CONDITION_PARAM_SKILL_SHIELDPERCENT = 42,
CONDITION_PARAM_SKILL_FISHINGPERCENT = 43,
CONDITION_PARAM_BUFF_SPELL = 44,
CONDITION_PARAM_SUBID = 45,
CONDITION_PARAM_FIELD = 46,
CONDITION_PARAM_IMMUNE_PARALYZE = 47,
,[/CODE]

i tried to figure it out using spells scripts that has multiple Conditions. (protector.lua has 3 conditions)
but after few days of non stop fails i figure i'll ask for help maybe someone can explain it and save me from some future heart problems. LOL :D

this potion is just a multiple condition potion for testing.
i want to be able to code them on my own so once i know how it works properly ill release a list of advanced potions to the community
(it has huge unused potential).

any help will be greatly appreciated.
 
Last edited:
Solution
you're overwriting the first condition by creating another with the same name.
the simplest way to do this is:
Lua:
local condition = Condition(CONDITION_REGENERATION)
    condition:setParameter(CONDITION_PARAM_SUBID, 3)
    condition:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000) -- 1 minute
    condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 50) -- heal 50 every 3 sec
    condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 3000)
    condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local condition2 = Condition(CONDITION_ATTRIBUTES)
    condition2:setParameter(CONDITION_PARAM_SUBID, 2)
    condition2:setParameter(CONDITION_PARAM_TICKS, 60000) -- 1 minute
    condition2:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS...
you're overwriting the first condition by creating another with the same name.
the simplest way to do this is:
Lua:
local condition = Condition(CONDITION_REGENERATION)
    condition:setParameter(CONDITION_PARAM_SUBID, 3)
    condition:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000) -- 1 minute
    condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 50) -- heal 50 every 3 sec
    condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 3000)
    condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local condition2 = Condition(CONDITION_ATTRIBUTES)
    condition2:setParameter(CONDITION_PARAM_SUBID, 2)
    condition2:setParameter(CONDITION_PARAM_TICKS, 60000) -- 1 minute
    condition2:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, 500) -- gain 500 to max hp

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        if player:addCondition(condition) then
            if player:addCondition(condition2) then
                player:getPosition():sendMagicEffect(CONST_ME_POFF)
                   Item(item.uid):remove(1)
            else
                player:removeCondition(condition)
            end
        end
    end
    return true
end
however this is a bit tedious when handling many conditions. so I've written this instead which is infinitely expandable. it will also not consume the potion if it is unable to add at least one of the conditions, and then remove any previous conditions it was able to add (so people can't use a broken potion infinitely to gain one or more conditions) and prints an error with the player's name and guid to the console so you can see that it happened.
I didn't test it so let me know if there's any issues.
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)
combat:setCondition(condition)

local conditions = {
    [8474] = { -- ItemID of the potion that will receive these conditions
        [1] = {
            condition = CONDITION_REGENERATION,
            params = {
                {CONDITION_PARAM_SUBID, 3},
                {CONDITION_PARAM_TICKS, 1 * 60 * 1000}, -- 1 minute
                {CONDITION_PARAM_HEALTHGAIN, 50}, -- heal 50 every 3 sec
                {CONDITION_PARAM_HEALTHTICKS, 3000},
                {CONDITION_PARAM_BUFF_SPELL, true},
            }
        },
        [2] = {
            condition = CONDITION_ATTRIBUTES,
            params = {
                {CONDITION_PARAM_SUBID, 2},
                {CONDITION_PARAM_TICKS, 60000}, -- 1 minute
                {CONDITION_PARAM_STAT_MAXHITPOINTS, 500}, -- gain 500 to max hp
            }
        },
    },
}


function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local temp = {}
    local potion = conditions[item:getId()]
    if not potion then return false end
    for k, v in ipairs(potion) do
        local condition = Condition(v.condition)
        for _, param in pairs(params) do
            condition:setParamater(param[1], param[2])
        end
        table.insert(temp, condition)
        if player:addCondition(condition) then
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
            Item(item.uid):remove(1)
        else
            print("Error (Potion Multi Condition): Cannot add all conditions to player " .. player:getName() .. "(" .. player:getGuid() .. "). Failed to add condition " .. k .. " of potion " .. item:getId() .. "!")
            for _, c in pairs(temp) do
                player:removeCondition(c)
            end
            return false
        end
    end
    return true
end
 
Solution
thanks for take the time and help :)

about the conditions names, ive tried to change them but the potion never worked after that. (not even for one condition)
so i stuck with same name for both. lol

as for your code, it seems more advanced so thank you.

getting this error tho
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/s_potion.lua:onUse
data/actions/scripts/custom/s_potion.lua:31: attempt to call global 'itemgetId' (a nil value)
stack traceback:
        [C]: in function 'itemgetId'
        data/actions/scripts/custom/s_potion.lua:31: in function <data/actions/scripts/custom/s_potion.lua:29>

not sure but extra info:

i use this 21441 as potion
called it in potions.lua

like that:
Lua:
local s potion = 21441

called it in action.xml like that:
Lua:
 <action itemid="21441" script="custom/s_potion.lua"/>
 
Last edited:
I think you screwed something up, his script isn't missing a : (it's item:getId(), but it's saying yours is itemgetId()). Add it back to that line, and your local potion has an extra s after the word local, which will cause an error.
 
you right, copy paste issue (never had this before).

first copy paste i was missing * and *
{CONDITION_PARAM_TICKS, 1 60 1000}

then i was missing all the "

print(Error (Potion Multi Condition): Cannot add all conditions to player .. player:getName() .. ( .. player:getGuid() .. ). Failed to add condition .. k .. of potion .. item:getId() .. !)

should i be worried about my pc or what? šŸ˜Ø


anyway ive made sure its all 1:1 copy paste this time.
get this error once i use potion.

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/s_potion.lua:onUse
data/actions/scripts/custom/s_potion.lua:36: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
        [C]: at 0x7ff7a8432e20
        [C]: in function 'pairs'
        data/actions/scripts/custom/s_potion.lua:36: in function <data/actions/scripts/custom/s_potion.lua:30>
 
Last edited:
when potion being used getting this


Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/s_potion.lua:onUse
data/actions/scripts/custom/s_potion.lua:37: attempt to call method 'setParamater' (a nil value)
stack traceback:
        [C]: in function 'setParamater'
        data/actions/scripts/custom/s_potion.lua:37: in function <data/actions/scripts/custom/s_potion.lua:30>
 
well, thanks to RazorBlade
Lua:
 if player:addCondition(condition2) then

now i know what was missing..

btw this is the code that working for me. :)

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

local condition = Condition(CONDITION_REGENERATION)
    condition:setParameter(CONDITION_PARAM_SUBID, 3)
    condition:setParameter(CONDITION_PARAM_TICKS, 1 * 60 * 1000) -- 1 minute
    condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 50) -- heal 50 every 3 sec
    condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 3000)
    condition:setParameter(CONDITION_PARAM_BUFF_SPELL, true)

local condition1 = Condition(CONDITION_ATTRIBUTES)
    condition1:setParameter(CONDITION_PARAM_SUBID, 2)
    condition1:setParameter(CONDITION_PARAM_TICKS, 60000) -- 1 minute
    condition1:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, 500) -- gain 500 to max hp

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        player:addCondition(condition)
        if player:addCondition(condition1) then
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        Item(item.uid):remove(1)
    end
    return true
end
 
when potion being used getting this


Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/s_potion.lua:onUse
data/actions/scripts/custom/s_potion.lua:37: attempt to call method 'setParamater' (a nil value)
stack traceback:
        [C]: in function 'setParamater'
        data/actions/scripts/custom/s_potion.lua:37: in function <data/actions/scripts/custom/s_potion.lua:30>
Parameter is spelt wrong big oops
Find where itā€™s spelt ā€œparamaterā€ at line 37 and just correct it xD
 
Back
Top