• 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++ passes inside item

alcapone

Member
Joined
Jan 13, 2021
Messages
246
Reaction score
19
C++:
ReturnValue Tile::queryAdd(int32_t, const Thing& thing, uint32_t, uint32_t tileFlags, Creature*) const
{
    if (const Creature* creature = thing.getCreature()) {
        if (hasBitSet(FLAG_NOLIMIT, tileFlags)) {
            return RETURNVALUE_NOERROR;
        }

        if (hasBitSet(FLAG_PATHFINDING, tileFlags) && hasFlag(TILESTATE_FLOORCHANGE | TILESTATE_TELEPORT)) {
            return RETURNVALUE_NOTPOSSIBLE;
        }

        if (creature->isMoveLocked() || ground == nullptr) {
            return RETURNVALUE_NOTPOSSIBLE;
        }

        if (const Monster* monster = creature->getMonster()) {
            if (hasFlag(TILESTATE_PROTECTIONZONE | TILESTATE_FLOORCHANGE | TILESTATE_TELEPORT) &&
                        (!monster->isPet() || (monster->isPet() && monster->getMaster() && monster->getMaster()->getAttackedCreature()))) {
                return RETURNVALUE_NOTPOSSIBLE;
            }

            if (monster->isSummon()) {
                if (ground->getID() >= ITEM_WALKABLE_SEA_START && ground->getID() <= ITEM_WALKABLE_SEA_END) {
                    return RETURNVALUE_NOTPOSSIBLE;
                }
            }

            const CreatureVector* creatures = getCreatures();
            if (monster->canPushCreatures() && !monster->isSummon()) {
                if (creatures) {
                    for (Creature* tileCreature : *creatures) {
                        if (tileCreature->getPlayer() && tileCreature->getPlayer()->isInGhostMode()) {
                            continue;
                        }

                        const Monster* creatureMonster = tileCreature->getMonster();
                        if (!creatureMonster || !tileCreature->isPushable() ||
                                (creatureMonster->isSummon() && creatureMonster->getMaster()->getPlayer())) {
                            return RETURNVALUE_NOTPOSSIBLE;
                        }
                    }
                }
            } else if (creatures && !creatures->empty()) {
                for (const Creature* tileCreature : *creatures) {
                    if (!tileCreature->isInGhostMode()) {
                        return RETURNVALUE_NOTENOUGHROOM;
                    }
                }
            }

            if (hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID)) {
                return RETURNVALUE_NOTPOSSIBLE;
            }

            if (hasBitSet(FLAG_PATHFINDING, tileFlags) && hasFlag(TILESTATE_IMMOVABLENOFIELDBLOCKPATH)) {
                return RETURNVALUE_NOTPOSSIBLE;
            }

            if (hasFlag(TILESTATE_BLOCKSOLID) || (hasBitSet(FLAG_PATHFINDING, tileFlags) && hasFlag(TILESTATE_NOFIELDBLOCKPATH))) {
                if (!(monster->canPushItems() || hasBitSet(FLAG_IGNOREBLOCKITEM, tileFlags))) {
                    return RETURNVALUE_NOTPOSSIBLE;
                }
            }

            MagicField* field = getFieldItem();
            if (field && !field->isBlocking() && field->getDamage() != 0) {
                CombatType_t combatType = field->getCombatType();

                //There is 3 options for a monster to enter a magic field
                //1) Monster is immune
                if (!monster->isImmune(combatType)) {
                    //1) Monster is able to walk over field type
                    //2) Being attacked while random stepping will make it ignore field damages
                    if (hasBitSet(FLAG_IGNOREFIELDDAMAGE, tileFlags)) {
                        if (!(monster->canWalkOnFieldType(combatType) || monster->isIgnoringFieldDamage())) {


                        return RETURNVALUE_NOTPOSSIBLE;
                        }
                    } else {
                        return RETURNVALUE_NOTPOSSIBLE;
                    }
                }
            }

            return RETURNVALUE_NOERROR;
        }

        const CreatureVector* creatures = getCreatures();
        if (const Player* player = creature->getPlayer()) {
            if (creatures && !creatures->empty() && !hasBitSet(FLAG_IGNOREBLOCKCREATURE, tileFlags) && !player->isAccessPlayer()) {
                for (const Creature* tileCreature : *creatures) {
                    if (!player->canWalkthrough(tileCreature)) {
                        return RETURNVALUE_NOTPOSSIBLE;
                    }
                }
            }

            if (player->getParent() == nullptr && hasFlag(TILESTATE_NOLOGOUT)) {
                //player is trying to login to a "no logout" tile
                return RETURNVALUE_NOTPOSSIBLE;
            }

            const Tile* playerTile = player->getTile();
            if (playerTile && player->isPzLocked()) {
                if (!playerTile->hasFlag(TILESTATE_PVPZONE)) {
                    //player is trying to enter a pvp zone while being pz-locked
                    if (hasFlag(TILESTATE_PVPZONE)) {
                        return RETURNVALUE_PLAYERISPZLOCKEDENTERPVPZONE;
                    }
                } else if (!hasFlag(TILESTATE_PVPZONE)) {
                    // player is trying to leave a pvp zone while being pz-locked
                    return RETURNVALUE_PLAYERISPZLOCKEDLEAVEPVPZONE;
                }

                if ((!playerTile->hasFlag(TILESTATE_NOPVPZONE) && hasFlag(TILESTATE_NOPVPZONE)) ||
                    (!playerTile->hasFlag(TILESTATE_PROTECTIONZONE) && hasFlag(TILESTATE_PROTECTIONZONE))) {
                    // player is trying to enter a non-pvp/protection zone while being pz-locked
                    return RETURNVALUE_PLAYERISPZLOCKED;
                }
            }
        } else if (creatures && !creatures->empty() && !hasBitSet(FLAG_IGNOREBLOCKCREATURE, tileFlags)) {
            for (const Creature* tileCreature : *creatures) {
                if (!tileCreature->isInGhostMode()) {
                    return RETURNVALUE_NOTENOUGHROOM;
                }
            }
        }

        if (!hasBitSet(FLAG_IGNOREBLOCKITEM, tileFlags)) {
            //If the FLAG_IGNOREBLOCKITEM bit isn't set we dont have to iterate every single item
            if (hasFlag(TILESTATE_BLOCKSOLID)) {
                // NO PVP magic wall or wild growth field check
                if (creature && creature->getPlayer()) {
                    if (const auto fieldList = getItemList()) {
                        for (Item* findfield : *fieldList) {
                            if (findfield && (findfield->getID() == ITEM_MAGICWALL || findfield->getID() == ITEM_WILDGROWTH)) {
                                 // if (!creature->isInGhostMode()) {
                                    // g_game.internalRemoveItem(findfield, 1);
                                // }
                                return RETURNVALUE_NOERROR;
                            }
                        }
                    }
                }
                return RETURNVALUE_NOTENOUGHROOM;
            }
        } else {
            //FLAG_IGNOREBLOCKITEM is set
            if (ground) {
                const ItemType& iiType = Item::items[ground->getID()];
                if (iiType.blockSolid && (!iiType.moveable || ground->hasAttribute(ITEM_ATTRIBUTE_UNIQUEID))) {
                    return RETURNVALUE_NOTPOSSIBLE;
                }
            }

            if (const auto items = getItemList()) {
                for (const Item* item : *items) {
                    const ItemType& iiType = Item::items[item->getID()];
                    if (iiType.blockSolid && (!iiType.moveable || item->hasAttribute(ITEM_ATTRIBUTE_UNIQUEID))) {
                        return RETURNVALUE_NOTPOSSIBLE;
                    }
                }
            }
        }
    } else if (const Item* item = thing.getItem()) {
        const TileItemVector* items = getItemList();
        if (items && items->size() >= 0x3E8) {
            return RETURNVALUE_NOTPOSSIBLE;
        }

        if (hasBitSet(FLAG_NOLIMIT, tileFlags)) {
            return RETURNVALUE_NOERROR;
        }

        bool itemIsHangable = item->isHangable();
        if (ground == nullptr && !itemIsHangable) {
            return RETURNVALUE_NOTPOSSIBLE;
        }

        const CreatureVector* creatures = getCreatures();
        if (creatures && !creatures->empty() && item->isBlocking() && !hasBitSet(FLAG_IGNOREBLOCKCREATURE, tileFlags)) {
            for (const Creature* tileCreature : *creatures) {
                if (!tileCreature->isInGhostMode()) {
                    return RETURNVALUE_NOTENOUGHROOM;
                }
            }
        }

        if (itemIsHangable && hasFlag(TILESTATE_SUPPORTS_HANGABLE)) {
            if (items) {
                for (const Item* tileItem : *items) {
                    if (tileItem->isHangable()) {
                        return RETURNVALUE_NEEDEXCHANGE;
                    }
                }
            }
        } else {
            if (ground) {
                const ItemType& iiType = Item::items[ground->getID()];
                if (iiType.blockSolid) {
                    if (!iiType.allowPickupable || item->isMagicField() || item->isBlocking()) {
                        if (!item->isPickupable()) {
                            return RETURNVALUE_NOTENOUGHROOM;
                        }

                        if (!iiType.hasHeight || iiType.pickupable || iiType.isBed()) {
                            return RETURNVALUE_NOTENOUGHROOM;
                        }
                    }
                }
            }

            if (items) {
                for (const Item* tileItem : *items) {
                    const ItemType& iiType = Item::items[tileItem->getID()];
                    if (!iiType.blockSolid) {
                        continue;
                    }

                    if (iiType.allowPickupable && !item->isMagicField() && !item->isBlocking()) {
                        continue;
                    }

                    if (!item->isPickupable()) {
                        return RETURNVALUE_NOTENOUGHROOM;
                    }

                    if (!iiType.hasHeight || iiType.pickupable || iiType.isBed()) {
                        return RETURNVALUE_NOTENOUGHROOM;
                    }
                }
            }
        }
    }
    return RETURNVALUE_NOERROR;
}


if (findfield && (findfield->getID() == ITEM_MAGICWALL || findfield->getID() == ITEM_WILDGROWTH)) {

I'm trying to make the player pass inside the magic wall (it is an item that is blocked in the otb)
 
Do you speak Spanish?

I'll try to help you with translete google, I don't know much about c++ either, so if I'm wrong, I apologize.

on line 216:
Code:
const ItemType& iiType = Item::items[tileItem->getID()];

print to the game console tileItem->getID() so you can get the id of the item, since I'm not sure the id is the same as it is in items.xml, so better this line tileItem->getID() It will print on the console so you can identify the id of the magic wall and so you are 100% sure of its ID.

in line 216 and 219 replace it with:
Code:
const ItemType& iiType = Item::items[tileItem->getID()];
if (!iiType.blockSolid && tileItem->getID() == ITEMIDWALL ) {
     continue;
}

replace ITEMIDWALL with the id of the magic wall.

I can't fully assure you that it works, currently I don't have visual basic to test.
 
Do you speak Spanish?

I'll try to help you with translete google, I don't know much about c++ either, so if I'm wrong, I apologize.

on line 216:
Code:
const ItemType& iiType = Item::items[tileItem->getID()];

print to the game console tileItem->getID() so you can get the id of the item, since I'm not sure the id is the same as it is in items.xml, so better this line tileItem->getID() It will print on the console so you can identify the id of the magic wall and so you are 100% sure of its ID.

in line 216 and 219 replace it with:
Code:
const ItemType& iiType = Item::items[tileItem->getID()];
if (!iiType.blockSolid && tileItem->getID() == ITEMIDWALL ) {
     continue;
}

replace ITEMIDWALL with the id of the magic wall.

I can't fully assure you that it works, currently I don't have visual basic to test.
compiled without errors but the character does not pass over the item
 
I was researching all day on this topic, but I didn't find a solution, the closest thing to what you need is in this topic:


can move players towards the items, the detail is that all players can go through anything.
 
Back
Top