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

Mana rune tfs 1.x+

denkan97

Well-Known Member
Joined
Dec 27, 2011
Messages
327
Solutions
2
Reaction score
50
Hi, i have just started trying to learn a bit more about the basic scripting but i have run into a problem
Not made for TFS 1.x at the begining but have tryed to translate

The basic thing is that i want it to work one way if you are knight and one way if you are not

code:

Lua:
local runes = {
    [2298] = {
        voc = {1, 2, 3, 4, 5, 6, 7, 8},
        min = 'level * 1 + maglv * 6',
        max = 'level * 1 + maglv * 8'
    }
}
function onUse(player, item, fromPosition, itemEx, toPosition)
    local i = runes[item.itemid]
    if isInArray(i.voc, player:getVocation()) then
        if player == true then
            if player:getVocation()(player) == 4 or player:getVocation()(player) == 8 then
                level, maglv = getPlayerLevel(player), getPlayerMagLevel(player)
                player:addMana(itemEx.uid, (math.random( 125, 175)))
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
                player:say(itemEx.uid, "First Manarune", TALKTYPE_MONSTER_SAY)
            else
                level, maglv = getPlayerLevel(player), getPlayerMagLevel(player)
                player:addMana(itemEx.uid, math.random(loadstring('return '..i.min)(), loadstring('return '..i.max)()))
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
                player:say(itemEx.uid, "First Manarune", TALKTYPE_MONSTER_SAY)
            end
        else
            doPlayerSendDefaultCancel(player, RETURNVALUE_CANONLYUSETHISRUNEONCREATURES)
        end
    else
        doPlayerSendCancel(player, 'Your vocation cannot use this rune.')
    end
    return true
end

Error:

Lua:
Lua Script Error: [Action Interface]
data/actions/scripts/liquids/first_manarune.lua:onUse
data/actions/scripts/liquids/first_manarune.lua:10: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/liquids/first_manarune.lua:10: in function <data/actions/scripts/liquids/first_manarune.lua:8>
 
Code:
local runes = {
    [2298] = {
        voc = {1, 2, 3, 4, 5, 6, 7, 8},
        min = level * 1 + maglv * 6,
        max = level * 1 + maglv * 8
    }
}
function onUse(player, item, fromPosition, itemEx, toPosition)
    local i = runes[item.itemid]
    if isInArray(i.voc, player:getVocation():getId()) then
        if player then
            if player:getVocation():getId() == 4 or player:getVocation():getId() == 8 then
                level, maglv = getPlayerLevel(player), getPlayerMagLevel(player)
                player:addMana((math.random(125, 175)))
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
                player:say("First Manarune", TALKTYPE_MONSTER_SAY)
            else
                level, maglv = getPlayerLevel(player), getPlayerMagLevel(player)
                player:addMana((math.random(i.min, i.max)))
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
                player:say("First Manarune", TALKTYPE_MONSTER_SAY)
            end
        else
            doPlayerSendDefaultCancel(player, RETURNVALUE_CANONLYUSETHISRUNEONCREATURES)
        end
    else
        doPlayerSendCancel(player, 'Your vocation cannot use this rune.')
    end
    return true
end

Editedyours. :l
 
Last edited:
Lua:
local runes = {

    [2298] = {

        voc = {1, 2, 3, 4, 5, 6, 7, 8},

        min = {level = 1, maglv = 6},

        max = {level = 1, maglv = 8},

    }

}

local likePotions = true

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)

    local i = runes[item.itemid]
    
    if not i then return false end

    local player = Player(cid)
    
    if target:isPlayer() then

        if isInArray(i.voc, player:getVocation()) then
        
                level, maglv = target:getLevel(), target:getMagicLevel()
                
            if isInArray({4,8}, player:getVocation() then

                target:addMana(math.random(125, 175))

                target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)

                target:say("First Manarune", TALKTYPE_MONSTER_SAY)

            else

                target:addMana(math.random((i.min.level * level) + (i.min.maglv * maglv), (i.max.level * level) + (i.max.maglv * maglv)))

                target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)

                target:say("First Manarune", TALKTYPE_MONSTER_SAY)

            end

        else

                player:sendCancelMessage('Your vocation cannot use this rune.')

        end

    else

           player:sendCancelMessage(RETURNVALUE_CANONLYUSETHISRUNEONCREATURES)

    end

    return true

end
 
"min = 'level * 1 + maglv * 6', max = 'level * 1 + maglv * 8'"

The "level * 1" is the same as "level + 0". Times one will do no difference.

so

min = 'level + maglvl * 6', max = 'level + maglvl * 8'
Example would a+b*c
a = level
b = mlvl
c = konstant(this value never change)
 
This script: V

Code:
local runes = {
    [2298] = {
        voc = {1, 2, 3, 4, 5, 6, 7, 8},
        min = level * 1 + maglv * 6,
        max = level * 1 + maglv * 8
    }
}
function onUse(player, item, fromPosition, itemEx, toPosition)
    local i = runes[item.itemid]
    if isInArray(i.voc, player:getVocation():getId()) then
        if player then
            if player:getVocation():getId() == 4 or player:getVocation():getId() == 8 then
                level, maglv = getPlayerLevel(player), getPlayerMagLevel(player)
                player:addMana((math.random(125, 175)))
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
                player:say("First Manarune", TALKTYPE_MONSTER_SAY)
            else
                level, maglv = getPlayerLevel(player), getPlayerMagLevel(player)
                player:addMana((math.random(i.min, i.max)))
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
                player:say("First Manarune", TALKTYPE_MONSTER_SAY)
            end
        else
            doPlayerSendDefaultCancel(player, RETURNVALUE_CANONLYUSETHISRUNEONCREATURES)
        end
    else
        doPlayerSendCancel(player, 'Your vocation cannot use this rune.')
    end
    return true
end

Editedyours. :l


Left me with this error: V

Code:
Lua Script Error: [Test Interface]
data/actions/scripts/liquids/first_manarune.lua
data/actions/scripts/liquids/first_manarune.lua:4: attempt to perform arithmetic on global 'level' (a nil value)
stack traceback:
        [C]: in function '__mul'
        data/actions/scripts/liquids/first_manarune.lua:4: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/liquids/first_manarune.lua



And this script didnt give any error but it didnt work. It only says that im not the right vocation whatever vocation i am. V

Lua:
local runes = {

    [2298] = {

        voc = {1, 2, 3, 4, 5, 6, 7, 8},

        min = {level = 1, maglv = 6},

        max = {level = 1, maglv = 8},

    }

}

local likePotions = true

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)

    local i = runes[item.itemid]
  
    if not i then return false end

    local player = Player(cid)
  
    if target:isPlayer() then

        if isInArray(i.voc, player:getVocation()) then
      
                level, maglv = target:getLevel(), target:getMagicLevel()
              
            if isInArray({4,8}, player:getVocation() then

                target:addMana(math.random(125, 175))

                target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)

                target:say("First Manarune", TALKTYPE_MONSTER_SAY)

            else

                target:addMana(math.random((i.min.level * level) + (i.min.maglv * maglv), (i.max.level * level) + (i.max.maglv * maglv)))

                target:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)

                target:say("First Manarune", TALKTYPE_MONSTER_SAY)

            end

        else

                player:sendCancelMessage('Your vocation cannot use this rune.')

        end

    else

           player:sendCancelMessage(RETURNVALUE_CANONLYUSETHISRUNEONCREATURES)

    end

    return true

end


The reason why 'level'l * 1' is still in there is becouse i might change it :)

"min = 'level * 1 + maglv * 6', max = 'level * 1 + maglv * 8'"

The "level * 1" is the same as "level + 0". Times one will do no difference.

so

min = 'level + maglvl * 6', max = 'level + maglvl * 8'
Example would a+b*c
a = level
b = mlvl
c = konstant(this value never change)
 
Back
Top