• 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 to summon follow

Noupz

New Member
Joined
Jul 13, 2010
Messages
126
Reaction score
1
This is part of my monster.cpp
void Monster::eek:nThink(uint32_t interval)
{
Creature::eek:nThink(interval);
if(despawn())
{
g_game.removeCreature(this, true);
setIdle(true);
return;
}

updateIdleStatus();
if(isIdle)
return;

if(teleportToMaster && doTeleportToMaster())
teleportToMaster = false;

addEventWalk();
if(isSummon())
{
if(!attackedCreature)
{
if(master && master->getAttackedCreature()) //This happens if the monster is summoned during combat
selectTarget(master->getAttackedCreature());
else if(master != followCreature) //Our master has not ordered us to attack anything, lets follow him around instead.
setFollowCreature(master);
}
else if(attackedCreature == this)
setFollowCreature(NULL);
else if(followCreature != attackedCreature) //This happens just after a master orders an attack, so lets follow it aswell.
setFollowCreature(attackedCreature);
}
else if(!targetList.empty())
{
if(!followCreature || !hasFollowPath)
searchTarget();
else if(isFleeing() && attackedCreature && !canUseAttack(getPosition(), attackedCreature))
searchTarget(TARGETSEARCH_ATTACKRANGE);
}

onThinkTarget(interval);
onThinkYell(interval);
onThinkDefense(interval);
}

i would like this part
else if(master != followCreature) //Our master has not ordered us to attack anything, lets follow him around instead.
work with a storage, like this
else if((master != followCreature) && (getStorage(9467, 1)) //Our master has not ordered us to attack anything, lets follow him around instead.

of course what i've done is wrong, but is the perfect example of what i want, someone could help me?

this is the source i use MEGA
 
If what you're trying to accomplish is a way to stop the summon from following it's master, of course, it's doing it the way you've posted.

The posted script was wrongly posted as there are emoticons shown in the code.
So if you can make your way through this, use the conditional as follows:

Simply set the storage value to 1 to stop the summon from following their master, if it's a player of course.
I did not test this, but it should work :rolleyes: I also think you might need to include player header in the source file.

Code:
else if (master != followCreature) //Our master has not ordered us to attack anything, lets follow him around instead.
    bool allowFollowMaster = true;
    if (Player* player = master->getPlayer()) {
        int32_t value;
        player->getStorageValue(9467, value);
        if (value != 1)
            allowFollowMaster = false;
    }
  
    if (allowFollowMaster)
        setFollowCreature(master);
 
i've got this erros, and yes, i did included player.h

monster.cpp:637:9: warning: unused variable ‘allowFollowMaster’ [-Wunused-variable]
bool allowFollowMaster = true;
^
monster.cpp:640:13: error: ‘class Player’ has no member named ‘getStorageValue’
player->getStorageValue(9467, value);
^
monster.cpp:642:9: error: ‘allowFollowMaster’ was not declared in this scope
allowFollowMaster = false;
^
monster.cpp:645:13: error: ‘allowFollowMaster’ was not declared in this scope
if (allowFollowMaster)
 
Code:
else if (master != followCreature) { //Our master has not ordered us to attack anything, lets follow him around instead.
    bool allowFollowMaster = true;
    if (Player* player = master->getPlayer()) {
        int32_t value;
        player->getStorageValue(9467, value);
        if (value != 1)
            allowFollowMaster = false;
    }

    if (allowFollowMaster)
        setFollowCreature(master);
}

Include player header file (player.h) in the monster source file.
As:

#include "player.h"
 
i've got this erros, and yes, i did included player.h
i sayd, i did it, but i got these erros

edit: now only this error

Code:
monster.cpp: In member function ‘virtual void Monster::onThink(uint32_t)’:
monster.cpp:640:13: error: ‘class Player’ has no member named ‘getStorageValue’
     player->getStorageValue(9467, value);

edit2:
But I was thinking of making him only activate the movement if the master walked, without storages
something lika
Code:
else if((master != followCreature) && (master->move)) //Our master has not ordered us to attack anything, lets follow him around instead.
again, i know what i've done is wrong, but is example
 
Last edited:
in 0.4 functions name is called getStorage(...) and is in the creature class, also 'value' is not an integer but a string
 
Last edited:
as i sayd, i change my mind, i will not use with storages, but, if the master walk, then, the summon will follow him

But I was thinking of making him only activate the movement if the master walked, without storages
something lika
  • else if((master != followCreature) && (master->move)) //Our master has not ordered us to attack anything, lets follow him around instead.
again, i know what i've done is wrong, but is example
 
Uhm alright, try this:

else if(master != followCreature && master->eventWalk != 0) //Our master has not ordered us to attack anything, lets follow him around instead.
 
Code:
creature.h: In member function ‘virtual void Monster::onThink(uint32_t)’:
creature.h:507:12: error: ‘uint32_t Creature::eventWalk’ is protected
   uint32_t eventWalk;
            ^
monster.cpp:636:48: error: within this context
    else if(master != followCreature && master->eventWalk != 0) //Nothing to attack, follow the master
 
This even worked, but in a wrong way, because once he comes back to follow, even though I'm standing with the god, I push him away and he comes to me
 
So let me get this straight, you want him to only follow you when you're not standing still? So if you summon a summon and run away like 4 steps away from your summon, then stops, the summon should stop as well?
 
I am at work right now, but perhaps you could add something to onThink, looking for the master has any walkDelay, of not then stopEventWalk
 
i has done it on player.cpp
Code:
void Player::onWalk(Direction& dir)
{
   Creature::onWalk(dir);
   setNextActionTask(NULL);
   setNextAction(OTSYS_TIME() + getStepDuration(dir));
   if(getSummonCount() > 0)
   {
       if(!getCreature()->getAttackedCreature())
           for(std::list<Creature*>::iterator cit = summons.begin(); cit != summons.end(); ++cit)
           {
               (*cit)->setFollowCreature(getCreature());
           }
   }
}
but when activate it, then never stops, someone could help me to continue?

i've undone the up change and tryied it on monster.cpp
Code:
           else if(master != followCreature){ //Our master has not ordered us to attack anything, lets follow him around instead.
               if(master->getWalkDelay() > 0)
                   setFollowCreature(master);
               else if(master->getWalkDelay() == 0)
                   stopEventWalk();
                   setFollowCreature(NULL);}
and of course it doesn't work like i expected

--------------------------------------------

i will give up the way of followmaster using the "walk", i will be back to use with storage, someone have any idea?
 
Last edited:
Back
Top