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

Uh for vocation

anyeor

Member
Joined
Jan 6, 2010
Messages
109
Solutions
2
Reaction score
18
Can anybody help me how i can make uh for voc?

my code didnt work:

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    if player:getVocation() == 4 or player:getVocation() == 8 then
        local min = (level * 2) + (maglevel * 16) --for knight
        local max = (level * 2) + (maglevel * 17.5) --for knight
    elseif getPlayerVocation(player) == 1 or player:getVocation() == 2 or player:getVocation() == 5 or player:getVocation() == 6 then
        local max = (level * 1) + (maglevel * 2.3) --for sorc&druid
        local max = (level * 1) + (maglevel * 2.5) --for sorc&druid
    end

    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

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

i dont know how to remake this script
 
Not tested
Lua:
-- assuming you do not have this function
function isInArray(a, f)
    if type(a) == 'table' then
        for k, v in pairs(a) do
            if v == f then
                return true
            end
        end
    end
    return false
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    local vocation = player:getVocation():getId()
    local min, max = 0, 0
    if isInArray({4, 8}, vocation) then
        min = (level * 2) + (maglevel * 16) --for knight
        max = (level * 2) + (maglevel * 17.5) --for knight
    elseif isInArray({1,2,5,6}, vocation) then
        min = (level * 1) + (maglevel * 2.3) --for sorc&druid
        max = (level * 1) + (maglevel * 2.5) --for sorc&druid
    end
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)
end
 
Not tested
Lua:
-- assuming you do not have this function
function isInArray(a, f)
    if type(a) == 'table' then
        for k, v in pairs(a) do
            if v == f then
                return true
            end
        end
    end
    return false
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    local vocation = player:getVocation():getId()
    local min, max = 0, 0
    if isInArray({4, 8}, vocation) then
        min = (level * 2) + (maglevel * 16) --for knight
        max = (level * 2) + (maglevel * 17.5) --for knight
    elseif isInArray({1,2,5,6}, vocation) then
        min = (level * 1) + (maglevel * 2.3) --for sorc&druid
        max = (level * 1) + (maglevel * 2.5) --for sorc&druid
    end
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)
end
why not table.contains :(
 
why not table.contains :(
It was late and I've grown accustomed to writing my own functions. And isn't it the same thing? I'll have have to look later.

table.contains is defined in global.lua to answer your question the difference between the function isInArray (the function I defined) and table.contains is my function checks to make sure it's a table where as table.contains does not and checking is important :)

table.contains
Lua:
table.contains = function(array, value)
    -- pairs will throw an error if array isn't a table
    for _, targetColumn in pairs(array) do
        if targetColumn == value then
            return true
        end
    end
    return false
end

isInArray
Lua:
function isInArray(a, f)
    -- type checking :)
    if type(a) == 'table' then
        for k, v in pairs(a) do
            if v == f then
                return true
            end
        end
    end
    return false
end
I could go even further by making sure that the table contains values
Lua:
function isInArray(a, f)
    -- type checking :)
    if type(a) == 'table' and next(a) then
        for k, v in pairs(a) do
            if v == f then
                return true
            end
        end
    end
    return false
end

Sometimes it's better to write your own functions.
 
Last edited:
It was late and I've grown accustomed to writing my own functions. And isn't it the same thing? I'll have have to look later.

table.contains is defined in global.lua to answer your question the difference between the function isInArray (the function I defined) and table.contains is my function checks to make sure it's a table where as table.contains does not and checking is important :)

table.contains
Lua:
table.contains = function(array, value)
    -- pairs will throw an error if array isn't a table
    for _, targetColumn in pairs(array) do
        if targetColumn == value then
            return true
        end
    end
    return false
end

isInArray
Lua:
function isInArray(a, f)
    -- type checking :)
    if type(a) == 'table' then
        for k, v in pairs(a) do
            if v == f then
                return true
            end
        end
    end
    return false
end
I could go even further by making sure that the table contains values
Lua:
function isInArray(a, f)
    -- type checking :)
    if type(a) == 'table' and next(a) then
        for k, v in pairs(a) do
            if v == f then
                return true
            end
        end
    end
    return false
end

Sometimes it's better to write your own functions.

I like writing functions myself as well, a bit because of ignorance but honestly its a bit more fun as well.
Out of curiosity, does the table.contains in global.lua extend the table property, meaning the type might be explicit?

So instead of
Lua:
if isInArray({4, 8}, vocation) then
    min = (level * 2) + (maglevel * 16) --for knight
    max = (level * 2) + (maglevel * 17.5) --for knight
elseif isInArray({1,2,5,6}, vocation) then
    min = (level * 1) + (maglevel * 2.3) --for sorc&druid
    max = (level * 1) + (maglevel * 2.5) --for sorc&druid
end

You might be able to do?
Lua:
if {4, 8}.contains(vocation) then
    min = (level * 2) + (maglevel * 16) --for knight
    max = (level * 2) + (maglevel * 17.5) --for knight
elseif {1,2,5,6}.contains(vocation) then
    min = (level * 1) + (maglevel * 2.3) --for sorc&druid
    max = (level * 1) + (maglevel * 2.5) --for sorc&druid
end

If the above example work, there would be no need to type check (since the function is a child of a table), but I kinda doubt that it works. In which case you might be on to a chance to submit a pull request on otland/forgottenserver. Sounds like something that should get fixed.
 
I like writing functions myself as well, a bit because of ignorance but honestly its a bit more fun as well.
Out of curiosity, does the table.contains in global.lua extend the table property, meaning the type might be explicit?

So instead of
Lua:
if isInArray({4, 8}, vocation) then
    min = (level * 2) + (maglevel * 16) --for knight
    max = (level * 2) + (maglevel * 17.5) --for knight
elseif isInArray({1,2,5,6}, vocation) then
    min = (level * 1) + (maglevel * 2.3) --for sorc&druid
    max = (level * 1) + (maglevel * 2.5) --for sorc&druid
end

You might be able to do?
Lua:
if {4, 8}.contains(vocation) then
    min = (level * 2) + (maglevel * 16) --for knight
    max = (level * 2) + (maglevel * 17.5) --for knight
elseif {1,2,5,6}.contains(vocation) then
    min = (level * 1) + (maglevel * 2.3) --for sorc&druid
    max = (level * 1) + (maglevel * 2.5) --for sorc&druid
end

If the above example work, there would be no need to type check (since the function is a child of a table), but I kinda doubt that it works. In which case you might be on to a chance to submit a pull request on otland/forgottenserver. Sounds like something that should get fixed.
Nice idea but idk if that would work. I tested a few theoretical examples on lua's demo page but just kept getting errors. I don't know which version of lua that demo page is using so I can't be 100% certain this would work or not since I am not home to test it on the server.
 
[Warning - Event::checkScript] Can not load script: scripts/healing/ultimate healing rune.lua
data/spells/scripts/healing/ultimate healing rune.lua:21: 'then' expected near '.'

Like this:
Lua:
table.contains = function(array, value)
    -- pairs will throw an error if array isn't a table
    for _, targetColumn in pairs(array) do
        if targetColumn == value then
            return true
        end
    end
    return false
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    local vocation = player:getVocation():getId()
    local min, max = 0, 0
    if {4,8}.contains(vocation) then
        min = (level * 2) + (maglevel * 16) --for knight
        max = (level * 2) + (maglevel * 17.5) --for knight
    elseif {1,2,5,6}.contains(vocation) then
        min = (level * 1) + (maglevel * 2.3) --for sorc&druid
        max = (level * 1) + (maglevel * 2.5) --for sorc&druid
    end
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)
end
 
[Warning - Event::checkScript] Can not load script: scripts/healing/ultimate healing rune.lua
data/spells/scripts/healing/ultimate healing rune.lua:21: 'then' expected near '.'

Like this:
Lua:
table.contains = function(array, value)
    -- pairs will throw an error if array isn't a table
    for _, targetColumn in pairs(array) do
        if targetColumn == value then
            return true
        end
    end
    return false
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    local vocation = player:getVocation():getId()
    local min, max = 0, 0
    if {4,8}.contains(vocation) then
        min = (level * 2) + (maglevel * 16) --for knight
        max = (level * 2) + (maglevel * 17.5) --for knight
    elseif {1,2,5,6}.contains(vocation) then
        min = (level * 1) + (maglevel * 2.3) --for sorc&druid
        max = (level * 1) + (maglevel * 2.5) --for sorc&druid
    end
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

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

I tend to mix Lua and javascript, sry.

I think child functions of a metatable should be defined with : symbol.
Although this might not be a metatable at all.?

player:getPosition, in that way, try {4,8}:contains(value)
 
I tend to mix Lua and javascript, sry.

I think child functions of a metatable should be defined with : symbol.
Although this might not be a metatable at all.?

player:getPosition, in that way, try {4,8}:contains(value)
same problem:
[Warning - Event::checkScript] Can not load script: scripts/healing/ultimate healing rune.lua
data/spells/scripts/healing/ultimate healing rune.lua:21: 'then' expected near ':'
 
same problem:
[Warning - Event::checkScript] Can not load script: scripts/healing/ultimate healing rune.lua
data/spells/scripts/healing/ultimate healing rune.lua:21: 'then' expected near ':'
Does the script I posted work? What Znote posted was a test.
 
Does the script I posted work? What Znote posted was a test.
This works:
Lua:
function isInArray(a, f)
    if type(a) == 'table' then
        for k, v in pairs(a) do
            if v == f then
                return true
            end
        end
    end
    return false
end

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    local vocation = player:getVocation():getId()
    local min, max = 0, 0
    if isInArray({4, 8}, vocation) then
        min = (level * 2) + (maglevel * 16) --for knight
        max = (level * 2) + (maglevel * 17.5) --for knight
    elseif isInArray({1,2,5,6}, vocation) then
        min = (level * 1) + (maglevel * 2.3) --for sorc&druid
        max = (level * 1) + (maglevel * 2.5) --for sorc&druid
    end
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

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