• 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 -=[TFS]=- [TALK] v0.4 v8.60 SpellBook who reads complete spells, no matter how much magic he has

samuel157

/root
Joined
Mar 19, 2010
Messages
447
Solutions
3
Reaction score
49
Location
São Paulo, Brazil
GitHub
Samuel10M
I need a spellbook script because mine when I click debug because it has too much magic in my ot same with player character

My SpellBook

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local count = getPlayerInstantSpellCount(cid)
    local text = ""
    local t = {}
    for i = 0, count - 1 do
        local spell = getPlayerInstantSpellInfo(cid, i)
        if spell.level ~= 0 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 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 .. "Spells for Level " .. spell.level .. "\n"
            prevLevel = spell.level
        end
        text = text .. line .. "  " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
    end
    doShowTextDialog(cid, item.itemid, text)
    return TRUE
end
 
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local t = {}
    for i = 0, getPlayerInstantSpellCount(cid) - 1 do
        local spell = getPlayerInstantSpellInfo(cid, i)
        if(spell.level ~= 0) 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 .. "Spells for Level " .. spell.level .. "\n"
            prevLevel = spell.level
        end

        text = text .. line .. "  " .. spell.words .. " - " .. spell.name .. " : " .. spell.mana .. "\n"
    end

    doShowTextDialog(cid, item.itemid, text)
    return true
end
Post automatically merged:

Tell me if you get any error
Me fale se apareceu algum erro pra vc
 
no function

Lua:
-- Caminho para a pasta spells
local spellsFolder = "data/spells/spells.xml"

function onSay(cid, words, param, channel)
    local spells = {} -- Para armazenar os nomes das magias

    -- Iterar sobre os arquivos na pasta spells
    for fileName in io.popen("ls " .. spellsFolder):lines() do
        -- Verificar se o arquivo é um arquivo XML
        if fileName:match("%.xml$") then
            local filePath = spellsFolder .. fileName
            
            -- Tentar abrir e processar o arquivo XML
            local f, err = io.open(filePath, "r")
            if f then
                -- Ler o conteúdo do arquivo
                local content = f:read("*all")
                f:close()

                -- Procurar todos os nomes de feitiços no XML e adicioná-los à lista
                for spellName in content:gmatch('<spell%s+name="(.-)"') do
                    table.insert(spells, spellName)
                end
            else
                print("Erro ao abrir o arquivo", filePath, ":", err)
            end
        end
    end

    -- Construir mensagem a ser exibida
    local texto = "Magias disponíveis:\n"
    for _, spellName in ipairs(spells) do
        texto = texto .. spellName .. "\n"
    end

    -- Mostrar a mensagem ao jogador
    doShowTextDialog(cid, 2175, texto)

    return true
end

Screenshot_1.png
 
he has Max character limit of spells so it will always crash his client. Either have to make use of modal window and display pages with Next or arrow or just use website for spellbook.
 
Back
Top