• 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 1.2]Spellbook not working

OdynsRaven

Odin @ Aesir OT
Joined
Apr 12, 2017
Messages
5
Reaction score
0
So have a server set up and I am working through adding features. I wanted to add a !spells feature. Command would not work. I have starter packages added and I have a sorcerer level 8 (so i should have spells) with a normal spellbook. When I try to use the spellbook it says "You cannot use this object". Console shows

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/spellbook.lua:eek:nUse
data/actions/scripts/other/spellbook.lua:4: attempt to call global 'getInstantSpells' (a nil value)
stack traceback:
        [C]: in function 'getInstantSpells'
        data/actions/scripts/other/spellbook.lua:4: in function <data/actions/scripts/other/spellbook.lua:1>

I have not altered this file in anyway (only copied it to make the !spells command). I have even tried downloading the newest master release and replacing the whole spells list. Any ideas? I want to change some spells around and want to be able to either use !spells or a spellbook to see the spells.
 
Solution
Thank you, just saw the update, must have had a wrong link. Have a Ubuntu server set up for the server, going to test. Gotta learn how to stay up to date without having to change all the scripts again after updating :(

Where can I find 1.3? Ive been looking through their GitHub and cant seem to find it.


Please read the rules; Rules for the Support board
#2

You can download 1.3 here; https://github.com/otland/forgottenserver/archive/master.zip
It's what we are working on atm.

If someone needs to know how to fix this in the future, update these 2 files;
forgottenserver/compat.lua at master · otland/forgottenserver · GitHub
forgottenserver/spellbook.lua at master · otland/forgottenserver · GitHub
The TFS version is in the Thread title, as well as when I said that I downloaded the most recent TFS master release and replaced the entire directory(as well as all action directory). I have read the Rules, and because its my first post maybe it just wasn't read.

For your convenience.

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   local text = ""
   local spells = {}
   for _, spell in ipairs(getInstantSpells()) do
       if spell.level ~= 0 then
           if spell.manapercent > 0 then
               spell.mana = spell.manapercent .. "%"
           end
           spells[#spells + 1] = spell
       end
   end

   table.sort(spells, function(a, b) return a.level < b.level end)

   local prevLevel = -1
   for i, spell in ipairs(spells) 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

   player:showTextDialog(item:getId(), text)
   return true
end

This is the most recent spellbook.lua file from the release.
 
Here you go.
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local count = getPlayerInstantSpellCount(player)
    local text = ""
    local spells = {}
    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
            spells[#spells + 1] = spell
        end
    end
  
    table.sort(spells, function(a, b) return a.level < b.level end)
  
    local prevLevel = -1
    for i, spell in ipairs(spells) 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
  
    player:showTextDialog(item:getId(), text)
    return true
end
 
The TFS version is in the Thread title, as well as when I said that I downloaded the most recent TFS master release and replaced the entire directory(as well as all action directory). I have read the Rules, and because its my first post maybe it just wasn't read.

For your convenience.

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   local text = ""
   local spells = {}
   for _, spell in ipairs(getInstantSpells()) do
       if spell.level ~= 0 then
           if spell.manapercent > 0 then
               spell.mana = spell.manapercent .. "%"
           end
           spells[#spells + 1] = spell
       end
   end

   table.sort(spells, function(a, b) return a.level < b.level end)

   local prevLevel = -1
   for i, spell in ipairs(spells) 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

   player:showTextDialog(item:getId(), text)
   return true
end

This is the most recent spellbook.lua file from the release.
my mistake, anyways i guess @Carlitos Flow beat me to it
 
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/spellbook.lua:onUse
data/lib/compat/compat.lua:1010: attempt to call method 'getInstantSpellCount' (a nil value)
stack traceback:
        [C]: in function 'getInstantSpellCount'
        data/lib/compat/compat.lua:1010: in function 'getPlayerInstantSpellCount'
        data/actions/scripts/other/spellbook.lua:2: in function <data/actions/scripts/other/spellbook.lua:1>

Same thing, this is literally with just default TFS 1.2 server.

Looking at the function list and everything here Script Interface · otland/forgottenserver Wiki · GitHub. Cant find anything for spell count. Trying some workarounds now.
 
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/spellbook.lua:onUse
data/lib/compat/compat.lua:1010: attempt to call method 'getInstantSpellCount' (a nil value)
stack traceback:
        [C]: in function 'getInstantSpellCount'
        data/lib/compat/compat.lua:1010: in function 'getPlayerInstantSpellCount'
        data/actions/scripts/other/spellbook.lua:2: in function <data/actions/scripts/other/spellbook.lua:1>

Same thing, this is literally with just default TFS 1.2 server.

Looking at the function list and everything here Script Interface · otland/forgottenserver Wiki · GitHub. Cant find anything for spell count. Trying some workarounds now.
you probably do not have a default 1.2 server, the error is inside compat.lua
default 1.2 does not have getPlayerInstantSpellCount in the compat lib, yours does (somewhere around line 1010)
either way the latest 1.3 has player:getInstantSpells() instead if you'd like to switch
 
Thank you, just saw the update, must have had a wrong link. Have a Ubuntu server set up for the server, going to test. Gotta learn how to stay up to date without having to change all the scripts again after updating :(

Where can I find 1.3? Ive been looking through their GitHub and cant seem to find it.
 
Last edited by a moderator:
Thank you, just saw the update, must have had a wrong link. Have a Ubuntu server set up for the server, going to test. Gotta learn how to stay up to date without having to change all the scripts again after updating :(

Where can I find 1.3? Ive been looking through their GitHub and cant seem to find it.


Please read the rules; Rules for the Support board
#2

You can download 1.3 here; https://github.com/otland/forgottenserver/archive/master.zip
It's what we are working on atm.

If someone needs to know how to fix this in the future, update these 2 files;
forgottenserver/compat.lua at master · otland/forgottenserver · GitHub
forgottenserver/spellbook.lua at master · otland/forgottenserver · GitHub
 
Solution
Understood thank you. I do need to say that it is still not working.

Lua:
function getPlayerInstantSpellCount(cid) local p = Player(cid) return p ~= nil and p:getInstantSpellCount() end
function getPlayerInstantSpellInfo(cid, spellId)
local player = Player(cid)
if not player then
return false
end

Line 1010 getPlayerInstantSpellCount is there as well as player:getInstantSpells(). This is from the 1.3 as well as the fix provided.

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/spellbook.lua:onUse
data/actions/scripts/other/spellbook.lua:4: attempt to call method 'getInstantSpells' (a nil value)
stack traceback:
        [C]: in function 'getInstantSpells'
        data/actions/scripts/other/spellbook.lua:4: in function <data/actions/scripts/other/spellbook.lua:1>

Is what I get, this is with 1.3 and the two fixes you provided.
 
Back
Top