• 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 What makes a spell appear in the spellbook?

chupaescadatri

Banned User
Joined
Jul 5, 2014
Messages
338
Reaction score
49
I went to see my spellbook, it appears almost all the spells, but does not appear an attack magic,
What do I do to make it appear?
+ rep
 
post script .lua and line .xml magic not appear?
Publish your spells.xml and your spellbook.lua is in data / actions / script

SPELLBOOK.LUA
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    local t = {}
    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

            table.insert(t, spell)
        end
    end

    table.sort(t, function(a, b) return a.level < b.level end)
    local text, 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

spells.xml
Lua:
    <instant name="Berserk" words="exori" maglv="5" mana="115" prem="1" needweapon="1" exhaustion="1600" needlearn="1" event="script" value="attack/berserk.lua">
        <vocation id="4"/>
        <vocation id="8"/>
    </instant>
 
XML:
needlearn="1"
to
XML:
needlearn="0"
I think that's what makes it doesn't appear.
 
XML:
needlearn="1"
to
XML:
needlearn="0"
I think that's what makes it doesn't appear.
It is very likely that this is your problem,
and if you do not use premium remove this too

XML:
prem="1"
to
XML:
prem="0"

I do not want to remove needlearn that would make the character come with magic without having to buy ..
I do not want to remove that magic is not from premium account, this would cause freeaccount to have the magic if they buy 1 time at the time that is premium account

What I want is to just add the magic in the spellbook
 
I do not want to remove needlearn that would make the character come with magic without having to buy ..
I do not want to remove that magic is not from premium account, this would cause freeaccount to have the magic if they buy 1 time at the time that is premium account

What I want is to just add the magic in the spellbook

the magic only appears the moment the player "buys" it
 
Add the flag ignoreSpellCheck to normal player groups, this will set InstantSpell::canCast to return true no matter what which results in every spell being entered into the spellbook.
Add 17179869184 to your current group flags in groups.xml.
 
the magic only appears the moment the player "buys" it
no, I already bought the magic I can use it normally, but it does not appear in the spellbook
Add the flag ignoreSpellCheck to normal player groups, this will set InstantSpell::canCast to return true no matter what which results in every spell being entered into the spellbook.
Add 17179869184 to your current group flags in groups.xml.
This made appear paladin and some sorcerer and none knight spells in the knight's spellbook
 
no, I already bought the magic I can use it normally, but it does not appear in the spellbook

This made appear paladin and some sorcerer and none knight spells in the knight's spellbook
Then you're going to have to source edit.
In spells.cpp, change this:
C++:
bool InstantSpell::canCast(const Player* player) const
{
    if (player->hasFlag(PlayerFlag_CannotUseSpells)) {
        return false;
    }

    if (player->hasFlag(PlayerFlag_IgnoreSpellCheck)) {
        return true;
    }

    if (isLearnable()) {
        if (player->hasLearnedInstantSpell(getName())) {
            return true;
        }
    } else {
        if (vocSpellMap.empty() || vocSpellMap.find(player->getVocationId()) != vocSpellMap.end()) {
            return true;
        }
    }

    return false;
}
to this:
C++:
bool InstantSpell::canCast(const Player* player) const
{
    if (player->hasFlag(PlayerFlag_CannotUseSpells)) {
        return false;
    }

    if (player->hasFlag(PlayerFlag_IgnoreSpellCheck)) {
        return true;
    }

    if (vocSpellMap.empty() || vocSpellMap.find(player->getVocationId()) != vocSpellMap.end()) {
        return true;
    }

    return false;
}
 
Then you're going to have to source edit.
In spells.cpp, change this:
C++:
bool InstantSpell::canCast(const Player* player) const
{
    if (player->hasFlag(PlayerFlag_CannotUseSpells)) {
        return false;
    }

    if (player->hasFlag(PlayerFlag_IgnoreSpellCheck)) {
        return true;
    }

    if (isLearnable()) {
        if (player->hasLearnedInstantSpell(getName())) {
            return true;
        }
    } else {
        if (vocSpellMap.empty() || vocSpellMap.find(player->getVocationId()) != vocSpellMap.end()) {
            return true;
        }
    }

    return false;
}
to this:
C++:
bool InstantSpell::canCast(const Player* player) const
{
    if (player->hasFlag(PlayerFlag_CannotUseSpells)) {
        return false;
    }

    if (player->hasFlag(PlayerFlag_IgnoreSpellCheck)) {
        return true;
    }

    if (vocSpellMap.empty() || vocSpellMap.find(player->getVocationId()) != vocSpellMap.end()) {
        return true;
    }

    return false;
}

my code is:
Code:
bool InstantSpell::canCast(const Player* player) const
{
    if(player->hasFlag(PlayerFlag_CannotUseSpells))
        return false;

    if(player->hasFlag(PlayerFlag_IgnoreSpellCheck) || (!isLearnable() && (vocSpellMap.empty()
        || vocSpellMap.find(player->getVocationId()) != vocSpellMap.end())))
        return true;

    return player->hasLearnedInstantSpell(getName());
}

change to:
Code:
bool InstantSpell::canCast(const Player* player) const
{
    if(player->hasFlag(PlayerFlag_CannotUseSpells))
        return false;

    if(player->hasFlag(PlayerFlag_IgnoreSpellCheck) || (!isLearnable() && (vocSpellMap.empty()
        || vocSpellMap.find(player->getVocationId()) != vocSpellMap.end())))
        return true;

    return (player->hasFlag(PlayerFlag_IgnoreSpellCheck)));
}

but it did not work
 
my code is:
Code:
bool InstantSpell::canCast(const Player* player) const
{
    if(player->hasFlag(PlayerFlag_CannotUseSpells))
        return false;

    if(player->hasFlag(PlayerFlag_IgnoreSpellCheck) || (!isLearnable() && (vocSpellMap.empty()
        || vocSpellMap.find(player->getVocationId()) != vocSpellMap.end())))
        return true;

    return player->hasLearnedInstantSpell(getName());
}

change to:
Code:
bool InstantSpell::canCast(const Player* player) const
{
    if(player->hasFlag(PlayerFlag_CannotUseSpells))
        return false;

    if(player->hasFlag(PlayerFlag_IgnoreSpellCheck) || (!isLearnable() && (vocSpellMap.empty()
        || vocSpellMap.find(player->getVocationId()) != vocSpellMap.end())))
        return true;

    return (player->hasFlag(PlayerFlag_IgnoreSpellCheck)));
}

but it did not work
What TFS version are you using? I sent code for 1.2 or 1.3
 
Maybe it's stupid, but try adding
Lua:
level="1"
to the spells.xml line

Maybe it's just not adding the line because it doesn't think it exists, since it's checking for the spell level.. on this line
Lua:
line = line .. "Spells for Level " .. spell.level .. "\n"

Although, idk why the entire script wouldn't just error in that case.. so idk.
Worth a try anyways.
 
Maybe it's stupid, but try adding
Lua:
level="1"
to the spells.xml line

Maybe it's just not adding the line because it doesn't think it exists, since it's checking for the spell level.. on this line
Lua:
line = line .. "Spells for Level " .. spell.level .. "\n"

Although, idk why the entire script wouldn't just error in that case.. so idk.
Worth a try anyways.
did not work, and verofiquei that the druid for example shows no spell in the spellbook
 
Back
Top