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

Lua new spell message per level

rudger

Active Member
Joined
Oct 1, 2010
Messages
253
Solutions
1
Reaction score
32
Location
The Netherlands
Im using tfs 1.2 10.98 and I want to create a message that once you level up you can get to see a new spell.

(example: You reached level 38 and can now cast 'exevo vis hur'.)
But I'm getting an orange message with no text and no errors in console, can someone take a look please?

Lua:
local s = {
    repeatAfterDeath = false, -- true -> player will always get the msg at lvlup | false -> player will only get the 1st time the gets the new level
    detailedInfo = true, -- true -> player will get name, words, mana & mana% info of spells | false -> player will only get the name and the words of the spells
-- storage below is where the newlevel will be stored ONLY IF YOU USE repeatAfterDeath
    Storage = 10000,
    messageType = 'channel', -- options: 'popUp' or 'channel'
--this one below only used if messageType = channel
    channelClass = MESSAGE_EVENT_ORANGE
    }
   
function onAdvance(player, skill, oldlevel, newlevel)
    if skill == SKILL__LEVEL or not s.repeatAfterDeath and player:getStorageValue(s.Storage) >= newlevel then
        return true
    end
 
    local spells = {}
    for _, spell in ipairs(player:getInstantSpells()) do
        if(spell.level ~= 0) and spell.level == newlevel then
            if(spell.manapercent > 0) then
                spell.mana = spell.manapercent .. '%'
            end
            spells[#spells + 1] = spell
        end
    end

    table.sort(spells, function(a, b) return a.level < b.level end)

    local text, prevLevel = '', -1
    for i, spell in ipairs(spells) do
        local line = ''
        if(prevLevel ~= spell.level) then
            if(i ~= 1) then
                line = '\n'
            end

            line = line .. 'You have just advanced to level '..newlevel..' and learned new spells!\n'
            prevLevel = spell.level
        end
        text = text ..line..' ['..spell.name..'] "'..spell.words..'" '..(s.detailedInfo and 'Mana['..spell.mana..']'..(spell.mlevel > 0 and ' ML['..spell.mlevel..']' or '') or '')..'\n'
   --text = text .. line .. '  ' .. spell.words .. ' - ' .. spell.name .. ' : ' .. spell.mana .. '\n'
    end
 
    --if text == '' then
      --  return true
    --end
 
    player:setStorageValue(s.Storage, newlevel)
    --if s.messageType == 'popUp' then
        player:showTextDialog(2175, text)
    --elseif s.messageType == 'channel' then
      --  player:sendTextMessage(s.channelClass, text)
    --end
    return true
end
 
Last edited by a moderator:
Solution
You have just advanced to level 13 and learned new spells!
[Terra Strike] "exori tera" Mana[20]
[Great Light] "utevo gran lux" Mana[60]

Lua:
local config = {
    repeatAfterDeath = false,
    detailedInfo = true,
    storage = 10000,
    channelClass = MESSAGE_EVENT_ORANGE
}

function onAdvance(player, skill, oldlevel, newlevel)
    if skill == SKILL__LEVEL or not config.repeatAfterDeath and player:getStorageValue(config.storage) >= newlevel then
        return true
    end

    local spells = {}
    for _, spell in ipairs(player:getInstantSpells()) do
        if spell.level ~= 0 and spell.level == newlevel then
            if spell.manapercent > 0 then
                spell.mana = spell.manapercent .. '%'
            end...
You have just advanced to level 13 and learned new spells!
[Terra Strike] "exori tera" Mana[20]
[Great Light] "utevo gran lux" Mana[60]

Lua:
local config = {
    repeatAfterDeath = false,
    detailedInfo = true,
    storage = 10000,
    channelClass = MESSAGE_EVENT_ORANGE
}

function onAdvance(player, skill, oldlevel, newlevel)
    if skill == SKILL__LEVEL or not config.repeatAfterDeath and player:getStorageValue(config.storage) >= newlevel then
        return true
    end

    local spells = {}
    for _, spell in ipairs(player:getInstantSpells()) do
        if spell.level ~= 0 and spell.level == newlevel then
            if spell.manapercent > 0 then
                spell.mana = spell.manapercent .. '%'
            end
            spells[#spells + 1] = spell
        end
    end

    table.sort(spells, function(a, b) return a.level < b.level end)

    local text, prevLevel = '', -1
    for i, spell in ipairs(spells) do
        local line = ''
        if prevLevel ~= spell.level then
            if i ~= 1 then
                line = '\n'
            end

            line = line .. 'You have just advanced to level ' .. newlevel .. ' and learned new spells!\n'
            prevLevel = spell.level
        end

        text = text .. '[' .. spell.name .. '] "' .. spell.words .. '" '
        if config.detailedInfo then
            text = text .. 'Mana[' .. spell.mana .. ']' .. (spell.mlevel > 0 and ' ML['..spell.mlevel..']' or '') ..'\n'
        end

        text = string.format("%s %s", line, text)
    end

    if text == '' then
        return true
    end

    player:setStorageValue(config.storage, newlevel)
    player:sendTextMessage(config.channelClass, text)

    return true
end
 
Solution
Thanks though it doesn't show me that I learned 'exevo gran mas vis' at level 60, when I advanced from level 59 to level 61.

Tested it with a pally and sorc, are you sure you have the correct level set in spells.xml? And that it dosn't require to be learned from an NPC (the one in the Ivory Towers in Edron)
 
This is what I have:

Lua:
<instant group="attack" name="Hell's Core" words="exevo gran mas flam" lvl="60" mana="1200" prem="1" exhaustion="2000" selftarget="1" needlearn="0" script="attack/hells_core.lua">

It is thinking my magic level is my level, when I advanced in magic levels.

First it counts level then magic level:

Lua:
You have just advanced to level 35 and learned new spells!
[Invisibility] "utana vid" Mana[440]

Then

You have just advanced to level 8 and learned new spells!
[Find person]"exiva" Mana[20]
 
Last edited by a moderator:
Maybe edit line 12 with
Lua:
 if skill >= SKILL_LEVEL
or line 15
Lua:
 spell.level <= newlevel
but I feel like that would post all previous spells.

I'm not the most experienced person though so I could be wrong.
 
Last edited:
I just tried this to completely rule out counting level as magic level but now nothing happens:

Lua:
local config = {
    repeatAfterDeath = true,
    detailedInfo = true,
    storage = 10000,
    channelClass = MESSAGE_EVENT_ORANGE
}
function onAdvance(player, skill, oldlevel, newlevel)
    if skill >= SKILL__LEVEL and player:getStorageValue(config.storage) >= newlevel then
   
    local spells = {}
    for _, spell in ipairs(player:getInstantSpells()) do
        if spell.level ~= 0 and spell.level == newlevel then
            if spell.manapercent > 0 then
                spell.mana = spell.manapercent .. '%'
            end
            spells[#spells + 1] = spell
        end
    end
    table.sort(spells, function(a, b) return a.level < b.level end)
    local text, prevLevel = '', -1
    for i, spell in ipairs(spells) do
        local line = ''
        if prevLevel ~= spell.level then
            if i ~= 1 then
                line = '\n'
            end
            line = line .. 'You have just advanced to level ' .. newlevel .. ' and learned new spells!\n'
            prevLevel = spell.level
        end
        text = text .. '[' .. spell.name .. '] "' .. spell.words .. '" '
        if config.detailedInfo then
            text = text .. 'Mana[' .. spell.mana .. ']' .. (spell.mlevel > 0 and ' ML['..spell.mlevel..']' or '') ..'\n'
        end
        text = string.format("%s %s", line, text)
    end
    if text == '' then
        return true
    end
    player:setStorageValue(config.storage, newlevel)
    player:sendTextMessage(config.channelClass, text)
end   
    return true
end
 
That's the original script but it doesn't answer my questions.

Can you test it with a new char and adding 1 lvl at a time, /addskill charName, exp
15:48 You have just advanced to level 55 and learned new spells!
[Rage of the Skies] "exevo gran mas vis" Mana[600]
[Lightning] "exori amp vis" Mana[60]
15:49 You have just advanced to level 60 and learned new spells!
[Hell's Core] "exevo gran mas flam" Mana[1100]
 
Back
Top