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

Health/Mana Potion for all vocations script help

berkeucuk

-Tengri
Joined
Jun 6, 2014
Messages
26
Reaction score
7
Hello someone can help me with this script?

I want one potion for all vocations
Example:
800-850 mana for mages.
400-450 Health and 350-400 Mana for paladins.
1300-1350 Health and 200-250 Mana for knights.

TFS 0.4

Lua:
local t = {level = 8, mana = {600, 650}, health = {1100, 1150},
voc_add = {
[{1,5,9,13}] = {"mana"},
[{2,6,10,14}] = {"mana"},
[{4,8,12,16}] = {"health"}}
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local check, p = {}, getPlayerPosition(cid)
    for id, v in pairs(t.voc_add) do
        if isInArray(id, getPlayerVocation(cid)) then
            check = v
            break
        end
    end
    if #check == 0 then
        doPlayerSendCancel(cid, "Your vocation can not use this item.")
        doSendMagicEffect(p, CONST_ME_POFF)
        return true
    end

    if(hasCondition(cid, CONDITION_EXHAUST)) then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
        doSendMagicEffect(p, CONST_ME_POFF)
        return true
    end

    if getPlayerLevel(cid) < t.level then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHLEVEL)
        doSendMagicEffect(p, CONST_ME_POFF)
        return true
    end

    for i = 1, #check do
        if check[i] == "mana" then
            doPlayerAddMana(cid, math.ceil(math.random(t.mana[1], t.mana[2])))
        else
            doCreatureAddHealth(cid, math.ceil(math.random(t.health[1], t.health[2])))
        end
    end
    doSendMagicEffect(p, CONST_ME_MAGIC_BLUE)
    doCreatureSay(cid, "Aaaah...", TALKTYPE_ORANGE_1)
    doAddCondition(cid, exhaust)
    return true
end
 
Solution
Hello someone can help me with this script?

I want one potion for all vocations
Example:
800-850 mana for mages.
400-450 Health and 350-400 Mana for paladins.
1300-1350 Health and 200-250 Mana for knights.

TFS 0.4

Lua:
local t = {level = 8, mana = {600, 650}, health = {1100, 1150},
voc_add = {
[{1,5,9,13}] = {"mana"},
[{2,6,10,14}] = {"mana"},
[{4,8,12,16}] = {"health"}}
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local check, p = {}, getPlayerPosition(cid)
    for id, v in pairs(t.voc_add) do
        if isInArray(id, getPlayerVocation(cid)) then...
Hello someone can help me with this script?

I want one potion for all vocations
Example:
800-850 mana for mages.
400-450 Health and 350-400 Mana for paladins.
1300-1350 Health and 200-250 Mana for knights.

TFS 0.4

Lua:
local t = {level = 8, mana = {600, 650}, health = {1100, 1150},
voc_add = {
[{1,5,9,13}] = {"mana"},
[{2,6,10,14}] = {"mana"},
[{4,8,12,16}] = {"health"}}
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local check, p = {}, getPlayerPosition(cid)
    for id, v in pairs(t.voc_add) do
        if isInArray(id, getPlayerVocation(cid)) then
            check = v
            break
        end
    end
    if #check == 0 then
        doPlayerSendCancel(cid, "Your vocation can not use this item.")
        doSendMagicEffect(p, CONST_ME_POFF)
        return true
    end

    if(hasCondition(cid, CONDITION_EXHAUST)) then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
        doSendMagicEffect(p, CONST_ME_POFF)
        return true
    end

    if getPlayerLevel(cid) < t.level then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHLEVEL)
        doSendMagicEffect(p, CONST_ME_POFF)
        return true
    end

    for i = 1, #check do
        if check[i] == "mana" then
            doPlayerAddMana(cid, math.ceil(math.random(t.mana[1], t.mana[2])))
        else
            doCreatureAddHealth(cid, math.ceil(math.random(t.health[1], t.health[2])))
        end
    end
    doSendMagicEffect(p, CONST_ME_MAGIC_BLUE)
    doCreatureSay(cid, "Aaaah...", TALKTYPE_ORANGE_1)
    doAddCondition(cid, exhaust)
    return true
end
try this.
I tried to change your code as little as possible.
Lua:
local t = {level = 8,
    voc_add = {         -- {min_mana, max_mana, min_health, max_health}
    [{1,5,9,13,2,6,10,14}] = {800, 850, 0, 0}, -- mages
    [{3,7,11,15}] = {400, 450, 350, 400}, -- paladin
    [{4,8,12,16}] = {1300, 1350, 200, 250} -- knight
    }
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local check, p = {}, getPlayerPosition(cid)
    for id, v in pairs(t.voc_add) do
        if isInArray(id, getPlayerVocation(cid)) then
            check = id
            break
        end
    end
    if #check == 0 then
        doPlayerSendCancel(cid, "Your vocation can not use this item.")
        doSendMagicEffect(p, CONST_ME_POFF)
        return true
    end
  
    if(hasCondition(cid, CONDITION_EXHAUST)) then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
        doSendMagicEffect(p, CONST_ME_POFF)
        return true
    end
  
    if getPlayerLevel(cid) < t.level then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHLEVEL)
        doSendMagicEffect(p, CONST_ME_POFF)
        return true
    end
  
    if t.voc_add[check][1] > 0 then
        doPlayerAddMana(cid, math.ceil(math.random(t.voc_add[check][1], t.voc_add[check][2])))
    end
    if t.voc_add[check][3] > 0 then
        doCreatureAddHealth(cid, math.ceil(math.random(t.voc_add[check][3], t.voc_add[check][4])))
    end
    doSendMagicEffect(p, CONST_ME_MAGIC_BLUE)
    doCreatureSay(cid, "Aaaah...", TALKTYPE_ORANGE_1)
    doAddCondition(cid, exhaust)
    return true
end
 
Last edited:
Solution
Hello someone can help me with this script?

I want one potion for all vocations
Example:
800-850 mana for mages.
400-450 Health and 350-400 Mana for paladins.
1300-1350 Health and 200-250 Mana for knights.

TFS 0.4

Lua:
local t = {level = 8, mana = {600, 650}, health = {1100, 1150},
voc_add = {
[{1,5,9,13}] = {"mana"},
[{2,6,10,14}] = {"mana"},
[{4,8,12,16}] = {"health"}}
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, (getConfigInfo('timeBetweenExActions') - 100))

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local check, p = {}, getPlayerPosition(cid)
    for id, v in pairs(t.voc_add) do
        if isInArray(id, getPlayerVocation(cid)) then
            check = v
            break
        end
    end
    if #check == 0 then
        doPlayerSendCancel(cid, "Your vocation can not use this item.")
        doSendMagicEffect(p, CONST_ME_POFF)
        return true
    end

    if(hasCondition(cid, CONDITION_EXHAUST)) then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
        doSendMagicEffect(p, CONST_ME_POFF)
        return true
    end

    if getPlayerLevel(cid) < t.level then
        doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHLEVEL)
        doSendMagicEffect(p, CONST_ME_POFF)
        return true
    end

    for i = 1, #check do
        if check[i] == "mana" then
            doPlayerAddMana(cid, math.ceil(math.random(t.mana[1], t.mana[2])))
        else
            doCreatureAddHealth(cid, math.ceil(math.random(t.health[1], t.health[2])))
        end
    end
    doSendMagicEffect(p, CONST_ME_MAGIC_BLUE)
    doCreatureSay(cid, "Aaaah...", TALKTYPE_ORANGE_1)
    doAddCondition(cid, exhaust)
    return true
end

Reposting from a private message..
@berkeucuk

Try to keep all the information in the specific thread.
If someone else if having the same issue, it's best for it to be on the open forum for them to find.

-------------
@berkeucuk said:

on knight vocation
[{4,8,12,16}] = {200, 250, 1300, 1350} -- knight
it gives mana & health but it shows only health
-------------

Does it show the mana value when a mage uses the potion?

If no, then you can add a line like 'doSendAnimatedText' to show the value of mana.
Lua:
if t.voc_add[check][1] > 0 then
    local mana = math.ceil(math.random(t.voc_add[check][1], t.voc_add[check][2]))
    doPlayerAddMana(cid, mana)
    doSendAnimatedText(getThingPosition(cid), mana, TEXTCOLOR_BLUE)
end

If yes, then the mana value is being hidden behind the text of the health value.
(in this case we could use an addEvent to slow down the text to appear after the health.)
Lua:
if t.voc_add[check][1] > 0 then
    local mana = math.ceil(math.random(t.voc_add[check][1], t.voc_add[check][2]))
    doPlayerAddMana(cid, mana)
    addEvent (
        function ()
            if isCreature(cid) then
                doSendAnimatedText(getThingPosition(cid), mana, TEXTCOLOR_BLUE)
            end
        end, 250 -- this is the delay (1000 = 1 second, 250 = 1/4 second)
    )
end

If you don't like the colour, you can find more colours in data/lib/000-constant.lua
 
Back
Top