From a3e11ab96e8ab53295009db15cfa2c5049fde541 Mon Sep 17 00:00:00 2001 From: ramses82 Date: Wed, 10 Aug 2016 01:25:42 -0500 Subject: [PATCH] Update spellbook.lua Fixed not showing spells --- data/actions/scripts/other/spellbook.lua | 31 ++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/data/actions/scripts/other/spellbook.lua b/data/actions/scripts/other/spellbook.lua index 24d1705..ece56b8 100644 --- a/data/actions/scripts/other/spellbook.lua +++ b/data/actions/scripts/other/spellbook.lua @@ -1,31 +1,32 @@ -function onUse(player, item, fromPosition, target, toPosition, isHotkey) - local count = getPlayerInstantSpellCount(player) - local text = "" +function onUse(cid, item, fromPosition, itemEx, toPosition) local t = {} - for i = 0, count - 1 do - local spell = getPlayerInstantSpellInfo(player, i) - if spell.level ~= 0 then - if spell.manapercent > 0 then + 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 - t[#t + 1] = spell + + table.insert(t, spell) end end + table.sort(t, function(a, b) return a.level < b.level end) - local prevLevel = -1 - local spell - for i = 1, #t do - spell = t[i] + local text, prevLevel = "", -1 + for i, spell in ipairs(t) do local line = "" - if prevLevel ~= spell.level then - if i ~= 1 then + 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 - player:showTextDialog(item.itemid, text) + + doShowTextDialog(cid, item.itemid, text) return true end