• 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] getInstantSpellCount and getExhaustion

PRLOts

Member
Joined
Jun 24, 2017
Messages
116
Solutions
4
Reaction score
15
Dear Otland !

I found a problem with my talkaction !spells and with my spellbook.lua in actions. I was trying to solve this like here or here but its still not working.

So, when I clink on spellbook in game I see error:

spellbook1.png

Here Is my compact.lua

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
    local spell = Spell(spellId)
    if not spell or not player:canCast(spell) then
        return false
    end
    return spell
end

And here spellbook.lua from actions:

Lua:
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
    local spell
    for i = 1, #spells do
        spell = spells[i]
        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.itemid, text)
    return true
end

When I try to write !spells I see error:

spellbook2.png

And here is my spells.lua in talkactions:

Lua:
function onSay(player, words, param)
    if player:getExhaustion(1000) <= 0 then
        player:setExhaustion(1000, 2)
        local text = ""
        local spells = {}
        for _, spell in ipairs(player: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(SPELL_BOOK, text)
        else
    player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You\'re exhausted for: '..player:getExhaustion(1000)..' seconds.')
    end
end

Question: Anyone knows how to solve issue with spellbook and command !spells or could share well working those 2 thing on TFS 1.2 ? Thanks for replys, best regards! :)
 
Solution
just delete the functions you put in the compat.lua like i told you to
you're overwriting them and trying to call a nil method
if you were to put something in compat.lua you would make a macro for method using the function, not the other way around because the method doesn't exist in 1.2
Lua:
function Player.getInstantSpellCount(self) return getPlayerInstantSpellCount(self:getId()) end
getPlayerInstantSpellCount already exists but you're overwriting it in the compat.lua and telling the new getPlayerInstantSpellCount to use player:getInstantSpellCount() which doesn't exist.
you can find the spellbook in tfs original datapack in actions/other/spellbook.lua
Lua:
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
not too hard to throw the code into an onSay function for !spells either
 
you can find the spellbook in tfs original datapack in actions/other/spellbook.lua
Lua:
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
not too hard to throw the code into an onSay function for !spells either

Damn, I tried a lot of scripts mate :D Still

stillll.png

:(

And the compact:

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
    local spell = Spell(spellId)
    if not spell or not player:canCast(spell) then
        return false
    end
    return spell
end
 
It's saying that you don't have the function Player:getInstantSpellCount() on your TFS 1.2.
This is strange, because this is there.
It's saying also that you don't have the function Player:getExhaustion(storage).
 
It's saying that you don't have the function Player:getInstantSpellCount() on your TFS 1.2.
This is strange, because this is there.
It's saying also that you don't have the function Player:getExhaustion(storage).
those aren't in the default tfs lib
player:getInstantSpellCount() uses getPlayerInstantSpellCount if you implement it yourself, it's a macro
player:set/get/check exhaustion are custom functions by Printer
 
if you're using default tfs 1.2 then it should work
remove the function you added to compat (not compact)

Sry my bad ofc this is compat.lua not compact.lua

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
    local spell = Spell(spellId)
    if not spell or not player:canCast(spell) then
        return false
    end
    return spell
end

those aren't in the default tfs lib
player:getInstantSpellCount() uses getPlayerInstantSpellCount if you implement it yourself, it's a macro
player:set/get/check exhaustion are custom functions by Printer

Are there any tutorials or some easy way to implement this function?
 
Dear Otland !

I found a problem with my talkaction !spells and with my spellbook.lua in actions. I was trying to solve this like here or here but its still not working.

So, when I clink on spellbook in game I see error:

View attachment 30466

Here Is my compact.lua

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
    local spell = Spell(spellId)
    if not spell or not player:canCast(spell) then
        return false
    end
    return spell
end

And here spellbook.lua from actions:

Lua:
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
    local spell
    for i = 1, #spells do
        spell = spells[i]
        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.itemid, text)
    return true
end

When I try to write !spells I see error:

View attachment 30467

And here is my spells.lua in talkactions:

Lua:
function onSay(player, words, param)
    if player:getExhaustion(1000) <= 0 then
        player:setExhaustion(1000, 2)
        local text = ""
        local spells = {}
        for _, spell in ipairs(player: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(SPELL_BOOK, text)
        else
    player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You\'re exhausted for: '..player:getExhaustion(1000)..' seconds.')
    end
end

Question: Anyone knows how to solve issue with spellbook and command !spells or could share well working those 2 thing on TFS 1.2 ? Thanks for replys, best regards! :)

spellbook.lua:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local text = ""
    local spells = {}
    for _, spell in ipairs(player: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

spells.lua:
Lua:
function onSay(player, words, param, channel)
    local text = ""
    local spells = {}
    for _, spell in ipairs(player: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(2175, text)
    return false
end

If you want to use your old spells.lua add this to the end of your global.lua(these are printers functions):
Lua:
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end
    return storage - os.time()
end

function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end
 
Last edited:
spellbook.lua:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local text = ""
    local spells = {}
    for _, spell in ipairs(player: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

spells.lua:
Lua:
function onSay(player, words, param, channel)
    local text = ""
    local spells = {}
    for _, spell in ipairs(player: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(2175, text)
    return false
end

If you want to use your old spells.lua add this to the end of your global.lua(these are printers functions):
Lua:
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end
    return storage - os.time()
end

function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end

Damn sry for long reply I was in work.. So it's still not working i tried to add this

Lua:
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end
function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end
    return storage - os.time()
end
function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end

into my global.lua and use all scripts for spellbook.lua in actions that I found and it seems that I have no function getPlayerInstantSpellCount, check bro:

chhhh.png


I think I need to add this function but anyone knows how ? ;s
 
just delete the functions you put in the compat.lua like i told you to
you're overwriting them and trying to call a nil method
if you were to put something in compat.lua you would make a macro for method using the function, not the other way around because the method doesn't exist in 1.2
Lua:
function Player.getInstantSpellCount(self) return getPlayerInstantSpellCount(self:getId()) end
getPlayerInstantSpellCount already exists but you're overwriting it in the compat.lua and telling the new getPlayerInstantSpellCount to use player:getInstantSpellCount() which doesn't exist.
 
Solution
just delete the functions you put in the compat.lua like i told you to
you're overwriting them and trying to call a nil method
if you were to put something in compat.lua you would make a macro for method using the function, not the other way around because the method doesn't exist in 1.2
Lua:
function Player.getInstantSpellCount(self) return getPlayerInstantSpellCount(self:getId()) end
getPlayerInstantSpellCount already exists but you're overwriting it in the compat.lua and telling the new getPlayerInstantSpellCount to use player:getInstantSpellCount() which doesn't exist.

Fuck my life, you are genius. Let God gives you hundred virgins :D

hmhmhmhmhm.png
 
Yes, @Static_ is right.
Both functions getPlayerInstantSpellCount and getPlayerInstantSpellInfo already exists on your luascript environment.
You need to remove both of them on your compat.lua.
Just remove both functions on compat.lua and try again.
 
Yes, @Static_ is right.
Both functions getPlayerInstantSpellCount and getPlayerInstantSpellInfo already exists on your luascript environment.
You need to remove both of them on your compat.lua.
Just remove both functions on compat.lua and try again.

Yee guys you're pro in that :D Tell me how you get that experience in OTS :O
 
Damn sry for long reply I was in work.. So it's still not working i tried to add this

Lua:
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end
function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end
    return storage - os.time()
end
function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end

into my global.lua and use all scripts for spellbook.lua in actions that I found and it seems that I have no function getPlayerInstantSpellCount, check bro:

View attachment 30480


I think I need to add this function but anyone knows how ? ;s

There are no getPlayerInstantSpellCount() inside my versions, but glad you figured it out...
 
Back
Top