• 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++ Walk trough summon

Sigoles

Discord: @sigoles
Joined
Nov 20, 2015
Messages
1,209
Solutions
2
Reaction score
154
How would the code for a player be able to walkthrough a summon if it is inside the protection zone?

forgottenserver/player.cpp at c4b10a905b11728522e715bd41f2493858ab0e46 · otland/forgottenserver · GitHub

I was tryed something like this:

C++:
const Tile* SummonTile = creature->getTile();
if (SummonTile->hasFlag(TILESTATE_PROTECTIONZONE) && creature->isSummon) {   
        return true;
    }

or this:
C++:
const Player* player = creature->getPlayer();
    if (!player || !creature->isSummon("Rat")) {
        return false;
    }


tfs 1.3

Or an edit to be able to move summon, <flag pushable="1" /> does not work being summon



thanks
 
Last edited by a moderator:
How would the code for a player be able to walkthrough a summon if it is inside the protection zone?

forgottenserver/player.cpp at c4b10a905b11728522e715bd41f2493858ab0e46 · otland/forgottenserver · GitHub

I was tryed something like this:

C++:
const Tile* SummonTile = creature->getTile();
if (SummonTile->hasFlag(TILESTATE_PROTECTIONZONE) && creature->isSummon) {   
        return true;
    }

tfs 1.3

Or an edit to be able to move summon, <flag pushable="1" /> does not work being summon



thanks

Do as you have been told in prev threads to find faults, use the print functions.
In C++ it's
C++:
std::cout << "State: " << SummonTile->hasFlag(TILESTATE_PROTECTIONZONE) << std::endl;

Print before and after the if statment, if you write out the if statments both should print out 1 or true, the one that prints null or false is "breaking" the statment.
 
forgottenserver/player.cpp at c4b10a905b11728522e715bd41f2493858ab0e46 · otland/forgottenserver · GitHub

change to:
Code:
const Player* player = creature->getPlayer();
if (!player && (!creature->getMonster() && !creature->getMaster())) {
    return false;
}

forgottenserver/player.cpp at c4b10a905b11728522e715bd41f2493858ab0e46 · otland/forgottenserver · GitHub

to:
Code:
const Tile* creatureTile = creature->getTile();
if (!creatureTile || !creatureTile->hasFlag(TILESTATE_PROTECTIONZONE)) {
    return false;
}

I edited this post 999999 times XD sry for this
 
Last edited:
@Thexamx @WibbenZ

Current code (did not work yet I can not move through and did not print anything).

C++:
bool Player::canWalkthrough(const Creature* creature) const
{
    if (group->access || creature->isInGhostMode()) {
        return true;
    }
  
    const Tile* creatureTile = creature->getTile();
    if (creatureTile || creatureTile->hasFlag(TILESTATE_PROTECTIONZONE)) {
        std::cout << "State: " << creatureTile->hasFlag(TILESTATE_PROTECTIONZONE) << std::endl;
        return true;
    }
  
  
  
    const Player* player = creature->getPlayer();
    if (!player) {
        return false;
    }

    const Tile* playerTile = player->getTile();
    if (!playerTile || (!playerTile->hasFlag(TILESTATE_PROTECTIONZONE) && player->getLevel() > static_cast<uint32_t>(g_config.getNumber(ConfigManager::PROTECTION_LEVEL)))) {
        return false;
    }

    const Item* playerTileGround = playerTile->getGround();
    if (!playerTileGround || !playerTileGround->hasWalkStack()) {
        return false;
    }
  
  
    Player* thisPlayer = const_cast<Player*>(this);
    if ((OTSYS_TIME() - lastWalkthroughAttempt) > 2000) {
        thisPlayer->setLastWalkthroughAttempt(OTSYS_TIME());
        return false;
    }

    if (creature->getPosition() != lastWalkthroughPosition) {
        thisPlayer->setLastWalkthroughPosition(creature->getPosition());
        return false;
    }

    thisPlayer->setLastWalkthroughPosition(creature->getPosition());
  
  
    return true;
}

I was tested with !creatureTile too
 
@Thexamx @WibbenZ

Current code (did not work yet I can not move through and did not print anything).

C++:
bool Player::canWalkthrough(const Creature* creature) const
{
    if (group->access || creature->isInGhostMode()) {
        return true;
    }
 
    const Tile* creatureTile = creature->getTile();
    if (creatureTile || creatureTile->hasFlag(TILESTATE_PROTECTIONZONE)) {
        std::cout << "State: " << creatureTile->hasFlag(TILESTATE_PROTECTIONZONE) << std::endl;
        return true;
    }
 
 
 
    const Player* player = creature->getPlayer();
    if (!player) {
        return false;
    }

    const Tile* playerTile = player->getTile();
    if (!playerTile || (!playerTile->hasFlag(TILESTATE_PROTECTIONZONE) && player->getLevel() > static_cast<uint32_t>(g_config.getNumber(ConfigManager::PROTECTION_LEVEL)))) {
        return false;
    }

    const Item* playerTileGround = playerTile->getGround();
    if (!playerTileGround || !playerTileGround->hasWalkStack()) {
        return false;
    }
 
 
    Player* thisPlayer = const_cast<Player*>(this);
    if ((OTSYS_TIME() - lastWalkthroughAttempt) > 2000) {
        thisPlayer->setLastWalkthroughAttempt(OTSYS_TIME());
        return false;
    }

    if (creature->getPosition() != lastWalkthroughPosition) {
        thisPlayer->setLastWalkthroughPosition(creature->getPosition());
        return false;
    }

    thisPlayer->setLastWalkthroughPosition(creature->getPosition());
 
 
    return true;
}

I was tested with !creatureTile too

The only way you are gonna see that print is if the code works, put it before the if statment and check both of them
 
The only way you are gonna see that print is if the code works, put it before the if statment and check both of them

The print works if I walk inside other character and out of protection zone

Stat: 0
 
Last edited by a moderator:
Ddi you even try what I posted? In "current code" I dont see my changes.

Clean TFS code and try my changes and let me know
 
Ddi you even try what I posted? In "current code" I dont see my changes.

Clean TFS code and try my changes and let me know

Yes, we cant pass with through
code actually:
C++:
bool Player::canWalkthrough(const Creature* creature) const
{
    if (group->access || creature->isInGhostMode()) {
        return true;
    }
       
    const Player* player = creature->getPlayer();
    if (!player && (!creature->getMonster() && !creature->getMaster())) {
        return false;
    }   
   
    const Tile* creatureTile = creature->getTile();
    if (!creatureTile || !creatureTile->hasFlag(TILESTATE_PROTECTIONZONE)) {
        return false;
    }
   
    const Tile* playerTile = player->getTile();
    const Item* playerTileGround = playerTile->getGround();
    if (!playerTileGround || !playerTileGround->hasWalkStack()) {
        return false;
    }
   
    
    Player* thisPlayer = const_cast<Player*>(this);
    if ((OTSYS_TIME() - lastWalkthroughAttempt) > 2000) {
        thisPlayer->setLastWalkthroughAttempt(OTSYS_TIME());
        return false;
    }

    if (creature->getPosition() != lastWalkthroughPosition) {
        thisPlayer->setLastWalkthroughPosition(creature->getPosition());
        return false;
    }

    thisPlayer->setLastWalkthroughPosition(creature->getPosition());
   
   
    return true;
}
 
Back
Top