• 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!

spells command with reb spells tfs 1.5

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
47
Hi, can someone add me to this command to show spells with rebirth?
I want something like, if spell need rebirth then is on last positon and before spell name, be text "Rebirth X"
In spells for rebirth 0, show only "Level: X"
I was tryed but without success, cuz i don't know how to get rebirth from spells.xml
Neded rebirth is in spells.xml like level, "rebirth = 0"

Code:
local spellsCommand = TalkAction("!spells")

function spellsCommand.onSay(player, words, param)
    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 .. "====================\n\n"
            line = line .. "Level: " .. spell.level .. "\n"
            prevLevel = spell.level
        end
        text = text .. line .. "  [-] " .. spell.words .. "\n"
        line = line .. "====================\n"
    end

    player:showTextDialog(1692, text)
    return true
end

spellsCommand:register()
 
Last edited:
So, i was try something but it not working (showing still only level spells)
Why this if not working?

Code:
local spellsCommand = TalkAction("!spells")

function spellsCommand.onSay(player, words, param)
    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
    local voc_id = player:getVocation():getBase():getId()
    for i, spell in ipairs(spells) do
        local line = ""
        if prevLevel ~= spell.level then
            if i ~= 1 then
                line = "\n"
            end
            line = line .. "====================\n\n"
            line = line .. "Level: " .. spell.level .. "\n"
            prevLevel = spell.level
        end
        text = text .. line .. "  [-] " .. spell.words .. "\n"
        line = line .. "====================\n"
        if voc_id == 1 or voc_id == 5 then
            line = line .. "Reborn: 1\n"
            line = line .. "> sorc\n"
            line = line .. "====================\n"
        elseif voc_id == 2 or voc_id == 6 then
            line = line .. "Reborn: 1\n"
            line = line .. "> drut\n"
            line = line .. "====================\n"
        elseif voc_id == 3 or voc_id == 7 then
            line = line .. "Reborn: 1\n"
            line = line .. "> pall\n"
            line = line .. "====================\n"
        elseif voc_id == 4 or voc_id == 8 then
            line = line .. "Reborn: 1\n"
            line = line .. "> kina\n"
            line = line .. "====================\n"
        end
    end
    print(voc_id)
    player:showTextDialog(1692, text)
    return true
end

spellsCommand:register()
 
have you tried something like that?

LUA:
local spellsCommand = TalkAction("!spells")

function spellsCommand.onSay(player, words, param)
    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 .. "====================\n\n"
            line = line .. "Level: " .. spell.level .. "\n"
            prevLevel = spell.level
        end
        text = text .. line .. "  [-] " .. spell.words .. " [-] " .. spell.rebirth .. "\n"
        line = line .. "====================\n"
    end

    player:showTextDialog(1692, text)
    return true
end

spellsCommand:register()
 
have you tried something like that?

LUA:
local spellsCommand = TalkAction("!spells")

function spellsCommand.onSay(player, words, param)
    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 .. "====================\n\n"
            line = line .. "Level: " .. spell.level .. "\n"
            prevLevel = spell.level
        end
        text = text .. line .. "  [-] " .. spell.words .. " [-] " .. spell.rebirth .. "\n"
        line = line .. "====================\n"
    end

    player:showTextDialog(1692, text)
    return true
end

spellsCommand:register()


Yep, tried it, but it can't work cuz spell.rebirth have nill value, because i don't know how to get what a rebirth need spell from spells.xml
 
Yep, tried it, but it can't work cuz spell.rebirth have nill value, because i don't know how to get what a rebirth need spell from spells.xml
rebirth="1" or rebirth="10"

I think this mean how many rebirths the player needs to use this spell, 1 = 1 and 10 = 10
 
rebirth="1" or rebirth="10"

I think this mean how many rebirths the player needs to use this spell, 1 = 1 and 10 = 10

I have spells for rebirth="2" and rebirth="5"
In this script for test i said Reborn; 1
Im using this rebornsystem - Feature - Reborn System | Reset level, increase power, set exclusive items, spells, houses, web and more! (https://otland.net/threads/reborn-system-reset-level-increase-power-set-exclusive-items-spells-houses-web-and-more.245808/)
 
This is assuming you are using the reborn system and everything was installed correctly

Create a public function here (spells.h)

C++:
uint32_t getRebirths() const {
    return reqRebirth;
}

Now on luascript.cpp push the new information through the instantSpell table

C++:
setField(L, "rebirth", spell.getRebirths());

Also on here, change 7 to 8
C++:
lua_createtable(L, 0, 7);
 
This is assuming you are using the reborn system and everything was installed correctly

Create a public function here (spells.h)

C++:
uint32_t getRebirths() const {
    return reqRebirth;
}

Now on luascript.cpp push the new information through the instantSpell table

C++:
setField(L, "rebirth", spell.getRebirths());

Also on here, change 7 to 8
C++:
lua_createtable(L, 0, 7);
@Roddet, how do i return getWords() only with the spell name? for example, if I want a npc to tell a player the words of a spell that he asks:
  • Hi
  • Light
  • npc says "Utevo Lux"

Searched for something like getInstantSpellByName(name) but doesnt found the function that correspond in new tfs
 
Last edited:
This is assuming you are using the reborn system and everything was installed correctly

Create a public function here (spells.h)

C++:
uint32_t getRebirths() const {
    return reqRebirth;
}

Now on luascript.cpp push the new information through the instantSpell table

C++:
setField(L, "rebirth", spell.getRebirths());

Also on here, change 7 to 8
C++:
lua_createtable(L, 0, 7);

Yea, spell.rebirth working now, but there is next problem, how to sort spells for rebirth bottom than spell for level? Cuz now i have all spells together if spell need level 8 and reb 2, is showing with spell for only level 8

Im tried like that but i got "spells.lua:31: attempt to concatenate local 'line' (a boolean value)"
Code:
local spellsCommand = TalkAction("!spells")

function spellsCommand.onSay(player, words, param)
    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 .. "====================\n\n"
            line = line .. "Level: " .. spell.level .. "\n"
            prevLevel = spell.level
        end
        text = text .. line .. "  [-] " .. spell.words .. " [-]\n"
        line = line .. "====================\n"
        line = line .. "Reborn: ".. spell.rebirth >= 1 .."\n"
        line = line .. "  [-] " .. spell.words .. " [-]\n"
        line = line .. "====================\n"
    end

    player:showTextDialog(1692, text)
    return true
end

spellsCommand:register()
 
Yea, spell.rebirth working now, but there is next problem, how to sort spells for rebirth bottom than spell for level? Cuz now i have all spells together if spell need level 8 and reb 2, is showing with spell for only level 8

Im tried like that but i got "spells.lua:31: attempt to concatenate local 'line' (a boolean value)"
Code:
local spellsCommand = TalkAction("!spells")

function spellsCommand.onSay(player, words, param)
    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 .. "====================\n\n"
            line = line .. "Level: " .. spell.level .. "\n"
            prevLevel = spell.level
        end
        text = text .. line .. "  [-] " .. spell.words .. " [-]\n"
        line = line .. "====================\n"
        line = line .. "Reborn: ".. spell.rebirth >= 1 .."\n"
        line = line .. "  [-] " .. spell.words .. " [-]\n"
        line = line .. "====================\n"
    end

    player:showTextDialog(1692, text)
    return true
end

spellsCommand:register()
change where is level to rebirth in the script and see if fits what you want
 
change where is level to rebirth in the script and see if fits what you want

Hmm, it work and not, because now it sorting by rebirth, but spells for rebirth 0 are together, look on screen:

1655664696171.png
Code:
local spellsCommand = TalkAction("!spells")

function spellsCommand.onSay(player, words, param)
    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.rebirth < b.rebirth end)

    local prevLevel = -1
    for i, spell in ipairs(spells) do
        local line = ""
        if prevLevel ~= spell.rebirth then
            if i ~= 1 then
                line = "\n"
            end
            line = line .. "====================\n\n"
            line = line .. "Reborn: " .. spell.rebirth .. "\n"
            prevLevel = spell.rebirth
        end
        text = text .. line .. "  [-] " .. spell.words .. " [-]\n"
        line = line .. "====================\n"
    end

    player:showTextDialog(1692, text)
    return true
end

spellsCommand:register()
 
@Roddet, how do i return getWords() only with the spell name? for example, if I want a npc to tell a player the words of a spell that he asks:
  • Hi
  • Light
  • npc says "Utevo Lux"

Searched for something like getInstantSpellByName(name) but doesnt found the function that correspond in new tfs

Same way
LUA:
function Player.getInstantSpellsName(self)
    local spells = {}
    for _, spell in ipairs(self:getInstantSpells()) do
        spells[spell.name] = spell.words
    end
    return spells
end

LUA:
local spells = player:getInstantSpellsName()
print(spells['Light']) -- prints utevo lux
 
Same way
LUA:
function Player.getInstantSpellsName(self)
    local spells = {}
    for _, spell in ipairs(self:getInstantSpells()) do
        spells[spell.name] = spell.words
    end
    return spells
end

LUA:
local spells = player:getInstantSpellsName()
print(spells['Light']) -- prints utevo lux
it worked like a glove, and I also learned more from it, thanks!
 
Back
Top