• 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++] Something like saga system..

Yatsu

I'm nobody.
Joined
Feb 12, 2016
Messages
27
Reaction score
2
Hello I'm trying to do something like "saga system(when you have storage for ex. 8000,1 monster dosen't attack you and you can't attack him, but if you have storage 8000,2 you can attack this monster same like he does attack you)" :
monster.cpp
Code:
void Monster::doAttacking(uint32_t interval)
{
    if(!attackedCreature || (isSummon() && attackedCreature == this))
        return;

    Player* player = attackedCreature->getPlayer();
    std::string value;
    std::string check = "15";
    if (getName() == "Demon Lord" && player && !player->getStorage(8000,value) || check != value )
    {
        setFollowCreature(NULL);
        setAttackedCreature(NULL);
        searchTarget(TARGETSEARCH_NEAREST);
    
    }
and also
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() == "Demon Lord" && 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);
}
My problem is that just 50% of this script is working. Monster is ignoring the player, but player still can attack the monster..
I have no idea what is bad here, could someone help?
TFS 0.3.6
 
Last edited:
small hint:

Player::setAttackedCreature(Creature* creature)
and
void Player::doAttacking(uint32_t interval)
 
What should I change in these lines:
Code:
Player* player = creature->getPlayer();
    std::string value;
    std::string check = "15";
    if (getName() == "Demon Lord" && player && !player->getStorage(8000,value) || check != value )
        return false;
and:
Code:
 Player* player = attackedCreature->getPlayer();
    std::string value;
    std::string check = "15";
    if (getName() == "Demon Lord" && player && !player->getStorage(8000,value) || check != value )
    {
        setFollowCreature(NULL);
        setAttackedCreature(NULL);
        searchTarget(TARGETSEARCH_NEAREST);
  
    }
to make that script working on the player side too? I don't get it.
 
Last edited:
bool Player::setAttackedCreature(Creature* creature)
here you insert a condition checking if is the player that have the storage and if the creature is the Demon Lord

if the player and/or the monster is affected by any AOE spell, you can use OnStatsChange/onHealthChange to avoid it
 
@Marcelo Druida Compiled it successful, but I still can target the monster in game, my characters doesen't deal damage and after I stop targeting server crashes.
 
Last edited:
I also tried do something in lua, but It also didin't work..
No errors in console
Code:
function onAttack(cid, target)

if isMonster(cid, target) then
if getPlayerStorageValue(cid, 8000) == 14 then
return 0
else
doSendPlayerCancel(cid, "Sorry, you cannot attack this monster.")
end
end
end
 
Back
Top