XML:
<talkaction words="!spellsall" script="magias.lua"/>
Lua:
function onSay(cid, words, param, channel)
local t = {}
for i = 0, getPlayerInstantSpellCount(cid) - 1 do
local spell = getPlayerInstantSpellInfo(cid, i)
if(spell.mlevel ~= 1) 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.mlevel < b.mlevel end)
local text, prevLevel = "", -1
for i, spell in ipairs(t) do
local line = ""
if(prevLevel ~= spell.mlevel) then
if(i ~= 1) then
line = "\n"
end
line = line .. "Spells for Magic Level " .. spell.mlevel .. "\n"
prevLevel = spell.mlevel
end
-- text = text .. line .. " " .. spell.words .. " - " .. spell.name .. " Mana: " .. spell.mana .. "\n"
text = text .. line .. " " .. spell.words .. " : " .. spell.mana .. "\n"
end
doShowTextDialog(cid, 2175, text)
return true
end
Post automatically merged:
error on console: Error during getDataInt(acesstime).
Lua:
function onSay(cid, words, param, channel)
local maxSpellsToShow = 8100 -- Define o número máximo de feitiços a serem mostrados
local t = {}
-- Loop através dos feitiços do jogador
for i = 0, getPlayerInstantSpellCount(cid) - 1 do
if #t >= maxSpellsToShow then
break -- Sai do loop se o limite máximo de feitiços for atingido
end
local spell = getPlayerInstantSpellInfo(cid, i)
-- Verifica se o feitiço não está no nível mínimo
if(spell.mlevel ~= 1) then
if(spell.manapercent > 0) then
spell.mana = spell.manapercent .. "%"
end
table.insert(t, spell)
end
end
-- Ordena os feitiços pelo nível de magia
table.sort(t, function(a, b) return a.mlevel < b.mlevel end)
-- Constrói a mensagem a ser exibida
local text = ""
local prevLevel = -1
for i, spell in ipairs(t) do
local line = ""
if(prevLevel ~= spell.mlevel) then
if(i ~= 1) then
line = "\n"
end
line = line .. "Spells for Magic Level " .. spell.mlevel .. "\n"
prevLevel = spell.mlevel
end
text = text .. line .. " " .. spell.words .. " : " .. spell.mana .. "\n"
end
-- Verifica o comprimento do texto
if #text > 8100 then
local chunks = {}
local current_chunk = ""
for line in text:gmatch("[^\r\n]+") do
if #current_chunk + #line > 8100 then
table.insert(chunks, current_chunk)
current_chunk = ""
end
current_chunk = current_chunk .. line .. "\n"
end
table.insert(chunks, current_chunk)
for _, chunk in ipairs(chunks) do
doShowTextDialog(cid, 2175, chunk)
end
else
-- Mostra a mensagem ao jogador
doShowTextDialog(cid, 2175, text)
end
return true
end
Last edited: