• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

C++ 7.6 and older tibian systems

Wirless

7.6 is the best :D
Joined
Nov 3, 2012
Messages
1,021
Solutions
1
Reaction score
216
Location
Ireland-Poland
Hello I am trying to edit source of 7.6 yur ots and I want to make it possible to learn spells from Items these items will be Item_Scroll that I have not yet added to items but will be in near future so I tought easiest way is to see how it works with npcs and try make it into actions this is what I came up with

ifdef __LearnSpellx__
int ActionScript::luaActionLearnSpell(lua_State *L){

//Learnspell(Spellname?)
int cid = (int)lua_tonumber(L, -3); //this is the creatureid of player i guess
const char* words = Item->getDescription(); //Get the name of the spell you want to learn from the item description ( it will be random).
lua_pop(L,3); //It was there at npc.cpp so we leave it

Creature* creature = player; // Mhm yes player
Item* ITEM_SCROLL = player->getItem(itemid); // Item and checking its id to make sure it is the item
Item->getDescription() = Spell we are going to learn
LearnSpell->Item->getDescription() = LearnSpell -> from Item -> Description
Player *player = creature? dynamic_cast<Player*>(creature) : NULL; // was in npc.cpp

if (player)
{
if (player->knowsSpell(words)) //words is the description^ atleast i think it is?
{
player->SendCancel("You know this spell already.");
}
else
{
player->learnSpell(words); //learn the spell
player->sendMagicEffect(player->pos, NM_ME_MAGIC_ENERGIE); //effect
player->sendCancel((std::string("To use it say: ") + std::string(words) + ".").c_str()); //send cancel in white above text chat?
}
}

return 0;

}
#endif __LearnSpellx__
and what could go wrong i mean it probably wont work i cant check but is there any other way I could do it? Its my first time trying to put more complex code in c++
 
Um.. code tags and indentation? Now its more readable
C++:
ifdef __LearnSpellx__
    int ActionScript::luaActionLearnSpell(lua_State *L){

    //Learnspell(Spellname?)
    int cid = (int)lua_tonumber(L, -3); //this is the creatureid of player i guess
    const char* words = Item->getDescription(); //Get the name of the spell you want to learn from the item description ( it will be random).
    lua_pop(L,3); //It was there at npc.cpp so we leave it

    Creature* creature = player; // Mhm yes player
    Item* ITEM_SCROLL = player->getItem(itemid); // Item and checking its id to make sure it is the item
    Item->getDescription() = Spell we are going to learn
    LearnSpell->Item->getDescription() = LearnSpell -> from Item -> Description
    Player *player = creature? dynamic_cast<Player*>(creature) : NULL; // was in npc.cpp

    if (player)
    {
        if (player->knowsSpell(words)) //words is the description^ atleast i think it is?
        {
            player->SendCancel("You know this spell already.");
        }
        else
        {
            player->learnSpell(words); //learn the spell
            player->sendMagicEffect(player->pos, NM_ME_MAGIC_ENERGIE); //effect
            player->sendCancel((std::string("To use it say: ") + std::string(words) + ".").c_str()); //send cancel in white above text chat?
        }
    }

    return 0;

    }
#endif __LearnSpellx__
 
Back
Top