Lua What makes a spell appear in the spellbook?

chupaescadatri

Active Member
Joined
Jul 5, 2014
Messages
304
Reaction score
35
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
 

ijuchia

New Member
Joined
Dec 30, 2014
Messages
17
Reaction score
0
Publish your spells.xml and your spellbook.lua is in data / actions / script
 
OP
chupaescadatri

chupaescadatri

Active Member
Joined
Jul 5, 2014
Messages
304
Reaction score
35
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>
 

Mustafa1337

Î Àm ŁĕğẹňĎ
Joined
Mar 4, 2017
Messages
313
Reaction score
80
XML:
needlearn="1"
to
XML:
needlearn="0"
I think that's what makes it doesn't appear.
 

ijuchia

New Member
Joined
Dec 30, 2014
Messages
17
Reaction score
0
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"
 
OP
chupaescadatri

chupaescadatri

Active Member
Joined
Jul 5, 2014
Messages
304
Reaction score
35
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
 

FearWar

Member
Joined
Sep 17, 2017
Messages
40
Reaction score
2
Location
Brasil
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
 

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,509
Reaction score
2,060
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.
 
OP
chupaescadatri

chupaescadatri

Active Member
Joined
Jul 5, 2014
Messages
304
Reaction score
35
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
 

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,509
Reaction score
2,060
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;
}
 
OP
chupaescadatri

chupaescadatri

Active Member
Joined
Jul 5, 2014
Messages
304
Reaction score
35
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
 

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,509
Reaction score
2,060
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
 

Xikini

I whore myself out for likes
Premium User
Joined
Nov 17, 2010
Messages
4,043
Reaction score
2,114
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.
 
OP
chupaescadatri

chupaescadatri

Active Member
Joined
Jul 5, 2014
Messages
304
Reaction score
35
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
 
Top