• 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 Function doShowTextDialog OTHire

massuco

Brazilian, sorry for my bad english XD
Joined
Feb 17, 2013
Messages
199
Solutions
8
Reaction score
22
Location
Brasil
I'm trying to make the spellbook that show spells list work on OTHire.
By default one OTHire, we have this script:
But its not working, and the distro dont show any error, just dont work.

Any ideas?

Lua:
function onUse(cid, item, frompos, item2, topos)
    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
 
I would check to see if the item is registered twice?
If it's registered a second time further up and is trying to use a different script, you may be getting a false positive.

If nothing else, you could add 'print(1)' directly under the function onUse, and even green text the rest of the script, to ensure it's actually working at all.

If it does print the 1 into console.. then start adding print(1), print(2).. et cetera down the script, and find out where it's erroring.. or if it's doing something unintended.
 
Change level to mlevel. Should be working.

Code:
function onUse(cid, item, frompos, item2, topos)
    local count = getPlayerInstantSpellCount(cid)
    local text = "House Spells\n"
    local t = {}
 
    for i = 0, count - 1 do
        local spell = getPlayerInstantSpellInfo(cid, i)
        if spell.mlevel ~= (nil) 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 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 .. " : " .. spell.mana .. "\n"
    end
 
    doShowTextDialog(cid, item.itemid, text)
    return TRUE
end
 
Back
Top