• 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.X+ TFS 1.4 Mana Rune depending on vocation

Rallelele

Member
Joined
Jun 11, 2017
Messages
62
Reaction score
8
Hey, I'm trying to get a manarune script to work that gives manapoints lower or higher depending on what vocation you are. But it does not work, no error in console and no reaction at all in-game. I'm using TFS 1.4.

This is my simplemanarune.lua located in actions-folder.
Lua:
local t = {
    -- [vocation, promotedvocation] = {mini = minimum heal, maxi = maximum heal}
    [{1, 2, 5, 6}] = {mp={1050,1150},hp={100,150}},
    [{3, 7}] = {mp={300,500}, hp={800,950}},
    [{4, 8}] = {mp={150,300}, hp={2100,2450}},
    [{9, 10}] = {mp={1200,1300},hp={200,250}},
    [{11}] = {mp={350,650}, hp={900,1050}},
    [{12}] = {mp={250,350}, hp={2200,2450}}
}

local exhaust = createConditionObject(CONDITION_EXHAUST)
setConditionParam(exhaust, CONDITION_PARAM_TICKS, 1000)
setConditionParam(exhaust, CONDITION_PARAM_SUBID, EXHAUST_HEALING)

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if not isPlayer(itemEx.uid) then
        return false
    elseif hasCondition(cid, CONDITION_EXHAUST, EXHAUST_HEALING) then
        return doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
    end

    local p = getPlayerVocation(cid)
    for k, v in pairs(t) do
        if isInArray(k, p) then
            doAddCondition(cid, exhaust)
            if v.mp then
                doCreatureAddMana(cid, math.random(v.mp[1], v.mp[2]))
            end
            if v.hp then
                doCreatureAddHealth(cid, math.random(v.hp[1], v.hp[2]))
            end
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
            return true
        end
    end

end

and actions.xml -
Code:
    <action itemid="2280" script="other/custom/simplemanarune.lua"/>
 
Solution
Now it at least reacts in-game, it shows the effect = 10 in-game, but I don't receive any mana or health.. hmm
Change
Lua:
            if v.randomHealth then
                targetPlayer:addHealth(math.random(v.randomHealth[1], v.randomHealth[2]))
            end
            if v.randomMana then
                targetPlayer:addMana(math.random(v.randomMana[1], v.randomMana[2]))
            end
to
Lua:
            if k.randomHealth then
                targetPlayer:addHealth(math.random(k.randomHealth[1], k.randomHealth[2]))
            end
            if k.randomMana then
                targetPlayer:addMana(math.random(k.randomMana[1], k.randomMana[2]))
            end
try remove this part:

Lua:
if not isPlayer(itemEx.uid) then
   return false

this rune seems to be on flag "use" not "use with".
 
Lua:
local config = { 
    [{1, 2, 5, 6}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{3, 7}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{4, 8}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{9, 10}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{11}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{12}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    
    effect = 10,
    exhaustTime = 1000, -- 1000 = 1 second
    itemId = 2300,
}

local manarune = Action()

local exhaust = Condition(CONDITION_EXHAUST_HEAL)
exhaust:setParameter(CONDITION_PARAM_TICKS, config.exhaustTime)

function manarune.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end
    
    local foundCondition = player:getCondition(CONDITION_EXHAUST_HEAL)
    if foundCondition and foundCondition:getEndTime() > os.mtime() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, 'you are exhausted.')
        return true
    end

    local voc = player:getVocation():getId()
    for v, k in pairs(config) do
        if isInArray(v, voc) then
            if v.randomHealth then
                targetPlayer:addHealth(math.random(v.randomHealth[1], v.randomHealth[2]))
            end
            if v.randomMana then
                targetPlayer:addMana(math.random(v.randomMana[1], v.randomMana[2]))
            end
            player:addCondition(exhaust)
            targetPlayer:getPosition():sendMagicEffect(config.effect)
            break
        end
    end
    return true
end

manarune:id(config.itemId)
manarune:allowFarUse(true)
manarune:register()
 
Last edited:
Lua:
local config = {
    [{1, 2, 5, 6}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{3, 7}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{4, 8}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{9, 10}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{11}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{12}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
   
    effect = 10,
    exhaustTime = 1000, -- 1000 = 1 second
    itemId = 2300,
}

local manarune = Action()

local exhaust = Condition(CONDITION_EXHAUST_HEAL)
exhaust:setParameter(CONDITION_PARAM_TICKS, config.exhaustTime)

function manarune.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end
   
    local foundCondition = player:getCondition(CONDITION_EXHAUST_HEAL)
    if foundCondition and foundCondition:getEndTime() > os.mtime() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, 'you are exhausted.')
        return true
    end

    local voc = player:getVocation():getId()
    for v, k in pairs(config) do
        if isInArray(v, voc) then
            if v.randomHealth then
                targetPlayer:addHealth(math.random(v.randomHealth[1], v.randomHealth[2]))
            end
            if v.randomMana then
                targetPlayer:addMana(math.random(v.randomMana[1], v.randomMana[2]))
            end
            player:addCondition(exhaust)
            targetPlayer:getPosition():sendMagicEffect(config.effect)
            break
        end
    end
    return true
end

manarune:id(config.itemId)
manarune:allowFarUse(true)
manarune:register()
Doesn't work for me, it shows no error in console but yet nothing happens in-game..
 
1e865997d70f1ba9aae104bc917e3355.png
Lua:
local voc = player:getVocation():getId()
    for v, k in pairs(config) do
        if isInArray(v, voc) then
            if v.randomHealth then
                targetPlayer:addHealth(math.random(v.randomHealth[1], v.randomHealth[2]))
            end
            if v.randomMana then
                targetPlayer:addMana(math.random(v.randomMana[1], v.randomMana[2]))
            end
            player:addCondition(exhaust)
            targetPlayer:getPosition():sendMagicEffect(config.effect)
            break
        end
    end
    return true
 
Lua:
local config = {
    [{1, 2, 5, 6}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{3, 7}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{4, 8}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{9, 10}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{11}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    [{12}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
   
    effect = 10,
    exhaustTime = 1000, -- 1000 = 1 second
    itemId = 2300,
}

local manarune = Action()

local exhaust = Condition(CONDITION_EXHAUST_HEAL)
exhaust:setParameter(CONDITION_PARAM_TICKS, config.exhaustTime)

function manarune.onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end
   
    local foundCondition = player:getCondition(CONDITION_EXHAUST_HEAL)
    if foundCondition and foundCondition:getEndTime() > os.mtime() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, 'you are exhausted.')
        return true
    end

    local voc = player:getVocation():getId()
    for v, k in pairs(config) do
        if isInArray(v, voc) then
            if v.randomHealth then
                targetPlayer:addHealth(math.random(v.randomHealth[1], v.randomHealth[2]))
            end
            if v.randomMana then
                targetPlayer:addMana(math.random(v.randomMana[1], v.randomMana[2]))
            end
            player:addCondition(exhaust)
            targetPlayer:getPosition():sendMagicEffect(config.effect)
            break
        end
    end
    return true
end

manarune:id(config.itemId)
manarune:allowFarUse(true)
manarune:register()
Doesn't work for me, it shows no error in console but yet nothing happens in-game..
It's because pairs doesn't guarantee execution order.

effect, exhaustTime, itemId needs to be moved outside of the config table, or separated from the vocations.

With that in mind, try this
Lua:
local config = {
    vocationInfo = {
        [{1, 2, 5, 6}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{3, 7}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{4, 8}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{9, 10}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{11}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{12}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    },
    
    effect = 10,
    exhaustTime = 1000, -- 1000 = 1 second
    itemId = 2300,
}

local manarune = Action()

local exhaust = Condition(CONDITION_EXHAUST_HEAL)
exhaust:setParameter(CONDITION_PARAM_TICKS, config.exhaustTime)

function manarune.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    
    local targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end
    
    local foundCondition = player:getCondition(CONDITION_EXHAUST_HEAL)
    if foundCondition and foundCondition:getEndTime() > os.mtime() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, 'you are exhausted.')
        return true
    end
    
    local voc = player:getVocation():getId()
    for v, k in pairs(config.vocationInfo) do
        if isInArray(v, voc) then
            if v.randomHealth then
                targetPlayer:addHealth(math.random(v.randomHealth[1], v.randomHealth[2]))
            end
            if v.randomMana then
                targetPlayer:addMana(math.random(v.randomMana[1], v.randomMana[2]))
            end
            player:addCondition(exhaust)
            targetPlayer:getPosition():sendMagicEffect(config.effect)
            break
        end
    end
    return true
end

manarune:id(config.itemId)
manarune:allowFarUse(true)
manarune:register()
 
It's because pairs doesn't guarantee execution order.

effect, exhaustTime, itemId needs to be moved outside of the config table, or separated from the vocations.

With that in mind, try this
Lua:
local config = {
    vocationInfo = {
        [{1, 2, 5, 6}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{3, 7}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{4, 8}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{9, 10}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{11}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{12}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    },
   
    effect = 10,
    exhaustTime = 1000, -- 1000 = 1 second
    itemId = 2300,
}

local manarune = Action()

local exhaust = Condition(CONDITION_EXHAUST_HEAL)
exhaust:setParameter(CONDITION_PARAM_TICKS, config.exhaustTime)

function manarune.onUse(player, item, fromPosition, target, toPosition, isHotkey)
   
    local targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end
   
    local foundCondition = player:getCondition(CONDITION_EXHAUST_HEAL)
    if foundCondition and foundCondition:getEndTime() > os.mtime() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, 'you are exhausted.')
        return true
    end
   
    local voc = player:getVocation():getId()
    for v, k in pairs(config.vocationInfo) do
        if isInArray(v, voc) then
            if v.randomHealth then
                targetPlayer:addHealth(math.random(v.randomHealth[1], v.randomHealth[2]))
            end
            if v.randomMana then
                targetPlayer:addMana(math.random(v.randomMana[1], v.randomMana[2]))
            end
            player:addCondition(exhaust)
            targetPlayer:getPosition():sendMagicEffect(config.effect)
            break
        end
    end
    return true
end

manarune:id(config.itemId)
manarune:allowFarUse(true)
manarune:register()
Now all of a sudden my commands doesnt work on my GOD. Only the basic /a 1 etc, not the /i and /m which worked just 1 minute ago. Tried checking all the documents I've been in but cant seem to find any reason why this would occur whatsoever. Still got my Account as type 5, and my character as group_id 6..
Post automatically merged:

It's because pairs doesn't guarantee execution order.

effect, exhaustTime, itemId needs to be moved outside of the config table, or separated from the vocations.

With that in mind, try this
Lua:
local config = {
    vocationInfo = {
        [{1, 2, 5, 6}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{3, 7}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{4, 8}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{9, 10}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{11}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
        [{12}] = {randomHealth = {1050, 1150}, randomMana = {1150, 1250}},
    },
   
    effect = 10,
    exhaustTime = 1000, -- 1000 = 1 second
    itemId = 2300,
}

local manarune = Action()

local exhaust = Condition(CONDITION_EXHAUST_HEAL)
exhaust:setParameter(CONDITION_PARAM_TICKS, config.exhaustTime)

function manarune.onUse(player, item, fromPosition, target, toPosition, isHotkey)
   
    local targetPlayer = Player(target)
    if not targetPlayer then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You may only use this on players!")
        return true
    end
   
    local foundCondition = player:getCondition(CONDITION_EXHAUST_HEAL)
    if foundCondition and foundCondition:getEndTime() > os.mtime() then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, 'you are exhausted.')
        return true
    end
   
    local voc = player:getVocation():getId()
    for v, k in pairs(config.vocationInfo) do
        if isInArray(v, voc) then
            if v.randomHealth then
                targetPlayer:addHealth(math.random(v.randomHealth[1], v.randomHealth[2]))
            end
            if v.randomMana then
                targetPlayer:addMana(math.random(v.randomMana[1], v.randomMana[2]))
            end
            player:addCondition(exhaust)
            targetPlayer:getPosition():sendMagicEffect(config.effect)
            break
        end
    end
    return true
end

manarune:id(config.itemId)
manarune:allowFarUse(true)
manarune:register()
Now it at least reacts in-game, it shows the effect = 10 in-game, but I don't receive any mana or health.. hmm
 
Last edited:
Now it at least reacts in-game, it shows the effect = 10 in-game, but I don't receive any mana or health.. hmm
Change
Lua:
            if v.randomHealth then
                targetPlayer:addHealth(math.random(v.randomHealth[1], v.randomHealth[2]))
            end
            if v.randomMana then
                targetPlayer:addMana(math.random(v.randomMana[1], v.randomMana[2]))
            end
to
Lua:
            if k.randomHealth then
                targetPlayer:addHealth(math.random(k.randomHealth[1], k.randomHealth[2]))
            end
            if k.randomMana then
                targetPlayer:addMana(math.random(k.randomMana[1], k.randomMana[2]))
            end
 
Solution
Change
Lua:
            if v.randomHealth then
                targetPlayer:addHealth(math.random(v.randomHealth[1], v.randomHealth[2]))
            end
            if v.randomMana then
                targetPlayer:addMana(math.random(v.randomMana[1], v.randomMana[2]))
            end
to
Lua:
            if k.randomHealth then
                targetPlayer:addHealth(math.random(k.randomHealth[1], k.randomHealth[2]))
            end
            if k.randomMana then
                targetPlayer:addMana(math.random(k.randomMana[1], k.randomMana[2]))
            end
Thank you so much.
 
Back
Top