• 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 Spells when you level up script, upgrade for TFS 1.1

Mezara

Member
Joined
Dec 25, 2013
Messages
68
Reaction score
6
Hello!
I recently tried to install this script by cbrm: http://otland.net/threads/spells-on-level-up-let-players-know-which-spells-do-they-learn.91213/
Code:
--[[------------------------------------------------<|]
|* * * * * * * * * * * * * * * * * * * * * * * * * * *| 
|* * * * * * * [SpellUp! Script] * * * * * * * * * * |
|* * * * * * * * By: Cybermaster * * * * * * * * * * *| 
|* * * Tested on: The Forgotten Server 0.3.6pl1 * * *|
|* * * * * * * * * * * * * * * * * * * * * * * * * * *| 
|>---------------------------------------------------]]

local s = { --SETUP
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(cid, skill, oldlevel, newlevel)
if skill ~= SKILL__LEVEL or not s.repeatAfterDeath and getCreatureStorage(cid, s.Storage) >= newlevel then
return true 
end

local t = {}
for i = 0, getPlayerInstantSpellCount(cid) - 1 do
local spell = getPlayerInstantSpellInfo(cid, i)
if(spell.level ~= 0) and spell.level == newlevel then
if(spell.manapercent > 0) then
spell.mana = spell.manapercent .. '%'
end
table.insert(t, spell)
end
end

table.sort(t, function(a, b) return a.level < b.level end)
local text, prevLevel = '', -1
for i, spell in ipairs(t) 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'
end

if text == '' then
return true
end

doCreatureSetStorage(cid, s.Storage, newlevel)
if s.messageType == 'popUp' then
doShowTextDialog(cid, 2175, text)
elseif s.messageType == 'channel' then
doPlayerSendTextMessage(cid, s.channelClass, text)
end
return true
end
--[[---------------------------------------------------------------------------------------------------<|
| * * * * * * * * * * * * * * * * * * * * * E N D * * * * * * * * * * * * * * * * * * * * * * * * * * | 
|>=====================================================================================================]]

This is the code. I changed docreaturesetstorage etc to the 1.1 functions but the script still won't work and there's no errors in the console. I've tried comparing it to TFS 1.1 spellbook.lua since the script is based on spellbook but I didn't manage to figure anything out.

Can someone please fix this script so it works with TFS 1.1? I've tried my best but with no success :(
 
line 47 seems to be an issue, short hand notation works like this (condition) ? val1 : val2 where ? is and & : is or
To my knowledge you can't nest shorthand notation and you have it compounded with no specific order of precedence.

Was just a quick look I could be wrong.
 
I'll give you mine for chat channels, and you modify it for your needs, you will just need to replace certain lines, I've already tested this for 1.x
I don't really feel up to fixing yours, I'm just tired atm :(
Code:
local CHANNEL_CHARACTER = 4
local tier =
    {
        [0] = "[ Apprentice ]",
        [1] = "[ Journeyman ]",
        [2] = "[ Adept ]",
        [3] = "[ Expert ]",
        [4] = "[ Master ]",
        [5] = "[ Grandmaster ]"
    }

local function listSpells(player)
    local count = getPlayerInstantSpellCount(player)
    local text = ""
    local t = {}
    for i = 0, count - 1 do
        local spell = getPlayerInstantSpellInfo(player, i)
        if spell.level ~= 0 then
            if spell.manapercent > 0 then
                spell.mana = spell.manapercent .. "%"
            end
            t[#t+1] = spell
        end
    end
    table.sort(t, function(a, b) return a.level < b.level end)
    local prevLevel = -1
    for i, spell in ipairs(t) do
        local line = ""
        if prevLevel ~= spell.level then
            if i ~= 1 then
                line = "\n"
            end
            line = line .. "\nSpells for Level " .. spell.level .. "\n"
            prevLevel = spell.level
            player:sendChannelMessage(cid, line, TALKTYPE_CHANNEL_O, CHANNEL_CHARACTER)
        end
        if player:getStorageValue(SPELL_WORDS[spell.words]) > 0 then
            local index = player:getStorageValue(SPELL_WORDS[spell.words])
            text =  "  " .. spell.words .. " " .. tier[index] .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
        else
            text = "  " .. spell.words .. " " .. tier[0] .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
        end
        player:sendChannelMessage(cid, text, TALKTYPE_CHANNEL_Y, CHANNEL_CHARACTER)
    end
  
end

function onJoin(player)
    addEvent(listSpells, 100, player)
    return true
end

function onSpeak(player, type, message)
    player:sendCancelMessage("You may not speak in this chat.")
    return false
end
 
Thanks but I do not need a spellbook. The script in my main post, is an onAdvance script - it tells you which spells you learned when you reach the level required for the spell.
 
Thanks but I do not need a spellbook. The script in my main post, is an onAdvance script - it tells you which spells you learned when you reach the level required for the spell.
The reason I gave you my code was as a reference, for you to review it and see how it could be applied to yours, maybe not everything but some aspects.

Edit: I see you didn't edit or write it at all
 
Back
Top