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

[C++] Storage = Attack (Monsters)

norrow

Member
Joined
Dec 16, 2012
Messages
129
Reaction score
7
Location
Poland
Hello,
i looking for a script:
-When player DONT have stroage id 8000, 15 monster with name "rat" cant attack him
-When dont have this stroage, cant attack this monster too...

I have this code but it does not work on 8.54 (0.3.6pl1)
Code:
Player* player = attackedCreature->getPlayer();
    std::string value;
    std::string check = "15";
    if (getName() == "Rat" && player && ( !(player->getStorage("8000",value)) || check != value ) )
    {
        setFollowCreature(NULL);
        setAttackedCreature(NULL);
        searchTarget(TARGETSEARCH_NEAREST);
      
    }
and
Code:
bool Monster::selectTarget(Creature* creature)
{
#ifdef __DEBUG__
    std::cout << "Selecting target... " << std::endl;
#endif
    if(!isTarget(creature))
        return false;

    CreatureList::iterator it = std::find(targetList.begin(), targetList.end(), creature);
    if(it == targetList.end())
    {
        //Target not found in our target list.
#ifdef __DEBUG__
        std::cout << "Target not found in targetList." << std::endl;
#endif
        return false;
    }

    Player* player = creature->getPlayer();
    std::string value;
    std::string check = "15";
    if (getName() == "Rat" && player && ( !(player->getStorage("8000",value)) || check != value ) )
        return false;

    if((isHostile() || isSummon()) && setAttackedCreature(creature) && !isSummon())
        Dispatcher::getInstance().addTask(createTask(
            boost::bind(&Game::checkCreatureAttack, &g_game, getID())));

    return setFollowCreature(creature, true);
}
Is there anyone who knows C + + and know how to fix it?
 
Compiling error
Code:
507 C:\Users\DOM\Desktop\DBV\source\0.3.6pl1.r102\monster.cpp invalid conversion from `const char*' to `uint32_t'
Log Compiling
Code:
Kompilator: Default compiler
Building Makefile: "C:\Users\DOM\Desktop\DBV\source\0.3.6pl1.r102\dev-cpp\Makefile.win"
Wykonywanie  make...
make.exe -f "C:\Users\DOM\Desktop\DBV\source\0.3.6pl1.r102\dev-cpp\Makefile.win" all
g++.exe -c ../monster.cpp -o obj//monster.o -I"include"  -D__USE_MYSQL__ -D__USE_SQLITE__ -D__ENABLE_SERVER_DIAGNOSTIC__  -fexpensive-optimizations -O1

../monster.cpp: In member function `bool Monster::selectTarget(Creature*)':
../monster.cpp:507: error: invalid conversion from `const char*' to `uint32_t'
../monster.cpp:507: error:  initializing argument 1 of `virtual bool Creature::getStorage(uint32_t, std::string&) const'

../monster.cpp: In member function `virtual void Monster::doAttacking(uint32_t)':
../monster.cpp:624: error: invalid conversion from `const char*' to `uint32_t'
../monster.cpp:624: error:  initializing argument 1 of `virtual bool Creature::getStorage(uint32_t, std::string&) const'

make.exe: *** [obj//monster.o] Error 1
 
Remove the quotation marks from "8000".

Change:
Code:
player->getStorage("8000", value)

To:

Code:
player->getStorage(8000, value)

In both cases.
 
I don't have the same server version as you. So I can't test out the code. But let's try anyway.

Go to player.cpp. You sould find the function 'bool Player::setAttackedCreature(Creature* creature)'

Add the following at the beginning of the function:
Code:
Player::setAttackedCreature(Creature* creature) {
    std::string value;
    if (creature && creature->getName() == "Rat" && !(getStorage(8000, value)))
        return false;
 
Back
Top