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

Linux [C++] How to make possibility involved witusing item on house door? Instead of "you are not invited"

okurde

New Member
Joined
Jan 28, 2009
Messages
134
Reaction score
1
Hello,
I have problem - when I use any item on house door then I see message: "you are not invited".
RET_PLAYERISNOTINVITED is responsible for this message and it occurs there:

actions.cpp
Code:
ReturnValue Actions::canUse(const Player* player, const Position& pos)
{
    (...)
    Tile* tile = g_game.getTile(pos);
    if(tile)
    {
        HouseTile* houseTile = tile->getHouseTile();
        if(houseTile && houseTile->getHouse() && !houseTile->getHouse()->isInvited(player))
            return RET_PLAYERISNOTINVITED;
    }
    return RET_NOERROR;
}

game.cpp
Code:
bool Game::playerRequestTrade(uint32_t playerId, const Position& pos, int16_t stackpos,
    uint32_t tradePlayerId, uint16_t spriteId)
{
    (...)
    HouseTile* houseTile = dynamic_cast<HouseTile*>(tradeItem->getParent());
    if(houseTile && houseTile->getHouse() && !houseTile->getHouse()->isInvited(player))
    {
        player->sendCancelMessage(RET_PLAYERISNOTINVITED);
        return false;
    }
}


game.cpp
Code:
Position Game::getClosestFreeTile(Creature* creature, Position pos, bool extended/* = false*/, bool ignoreHouse/* = true*/)
(...)
std::random_shuffle(relList.begin() + 1, relList.end());
    if(Player* player = creature->getPlayer())
    {
        for(PairVector::iterator it = relList.begin(); it != relList.end(); ++it)
        {
            Tile* tile = map->getTile(Position((pos.x + it->first), (pos.y + it->second), pos.z));
            if(!tile || !tile->ground)
                continue;

            ReturnValue ret = tile->__queryAdd(0, player, 1, FLAG_IGNOREBLOCKITEM);
            if(ret == RET_NOTENOUGHROOM || (ret == RET_NOTPOSSIBLE && !player->hasCustomFlag(
                PlayerCustomFlag_CanMoveAnywhere)) || (ret == RET_PLAYERISNOTINVITED && !ignoreHouse))
                continue;

            return tile->getPosition();
        }
    }


housetile.cpp
Code:
ReturnValue HouseTile::__queryAdd(int32_t index, const Thing* thing, uint32_t count, uint32_t flags, Creature* actor/* = NULL*/) const
{
    if(const Creature* creature = thing->getCreature())
    {
        if(const Player* player = creature->getPlayer())
        {
            if(!house->isInvited(player) && !player->hasCustomFlag(PlayerCustomFlag_CanMoveAnywhere))
                return RET_PLAYERISNOTINVITED;
        }
        else
            return RET_NOTPOSSIBLE;
    }
    else if(thing->getItem())
    {
        const uint32_t itemLimit = g_config.getNumber(ConfigManager::HOUSE_TILE_LIMIT);
        if(itemLimit && getItemCount() > itemLimit)
            return RET_TILEISFULL;

        if(actor && g_config.getBool(ConfigManager::HOUSE_PROTECTION))
        {
            if(const Player* player = actor->getPlayer())
            {
                if(!house->isInvited(player) && !player->hasCustomFlag(PlayerCustomFlag_CanThrowAnywhere))
                    return RET_PLAYERISNOTINVITED;
            }
        }
    }

    return Tile::__queryAdd(index, thing, count, flags, actor);
}


housetile.cpp
Code:
ReturnValue HouseTile::__queryRemove(const Thing* thing, uint32_t count, uint32_t flags, Creature* actor/* = NULL*/) const
{
    if(thing->getItem() && actor && g_config.getBool(ConfigManager::HOUSE_PROTECTION))
    {
        if(const Player* player = actor->getPlayer())
        {
            if(!house->isInvited(player) && !player->hasCustomFlag(PlayerCustomFlag_CanThrowAnywhere))
                return RET_PLAYERISNOTINVITED;
        }
    }

    return Tile::__queryRemove(thing, count, flags, actor);
}


map.cpp
Code:
bool Map::placeCreature(const Position& centerPos, Creature* creature, bool extendedPos /*= false*/, bool forced /*= false*/)
{
    bool foundTile = false, placeInPz = false;
    Tile* tile = getTile(centerPos);
    if(tile && !extendedPos)
    {
        placeInPz = tile->hasFlag(TILESTATE_PROTECTIONZONE);
        uint32_t flags = FLAG_IGNOREBLOCKITEM;
        if(creature->isAccountManager())
            flags |= FLAG_IGNOREBLOCKCREATURE;

        ReturnValue ret = tile->__queryAdd(0, creature, 1, flags);
        if(forced || ret == RET_NOERROR || ret == RET_PLAYERISNOTINVITED)
            foundTile = true;
    }
(...)


Does anyone have any idea what should be changed? Code in actions.cpp?
BG
 
Hello,
I have problem - when I use any item on house door then I see message: "you are not invited".
RET_PLAYERISNOTINVITED is responsible for this message and it occurs there:

actions.cpp
Code:
ReturnValue Actions::canUse(const Player* player, const Position& pos)
{
    (...)
    Tile* tile = g_game.getTile(pos);
    if(tile)
    {
        HouseTile* houseTile = tile->getHouseTile();
        if(houseTile && houseTile->getHouse() && !houseTile->getHouse()->isInvited(player))
            return RET_PLAYERISNOTINVITED;
    }
    return RET_NOERROR;
}

game.cpp
Code:
bool Game::playerRequestTrade(uint32_t playerId, const Position& pos, int16_t stackpos,
    uint32_t tradePlayerId, uint16_t spriteId)
{
    (...)
    HouseTile* houseTile = dynamic_cast<HouseTile*>(tradeItem->getParent());
    if(houseTile && houseTile->getHouse() && !houseTile->getHouse()->isInvited(player))
    {
        player->sendCancelMessage(RET_PLAYERISNOTINVITED);
        return false;
    }
}


game.cpp
Code:
Position Game::getClosestFreeTile(Creature* creature, Position pos, bool extended/* = false*/, bool ignoreHouse/* = true*/)
(...)
std::random_shuffle(relList.begin() + 1, relList.end());
    if(Player* player = creature->getPlayer())
    {
        for(PairVector::iterator it = relList.begin(); it != relList.end(); ++it)
        {
            Tile* tile = map->getTile(Position((pos.x + it->first), (pos.y + it->second), pos.z));
            if(!tile || !tile->ground)
                continue;

            ReturnValue ret = tile->__queryAdd(0, player, 1, FLAG_IGNOREBLOCKITEM);
            if(ret == RET_NOTENOUGHROOM || (ret == RET_NOTPOSSIBLE && !player->hasCustomFlag(
                PlayerCustomFlag_CanMoveAnywhere)) || (ret == RET_PLAYERISNOTINVITED && !ignoreHouse))
                continue;

            return tile->getPosition();
        }
    }


housetile.cpp
Code:
ReturnValue HouseTile::__queryAdd(int32_t index, const Thing* thing, uint32_t count, uint32_t flags, Creature* actor/* = NULL*/) const
{
    if(const Creature* creature = thing->getCreature())
    {
        if(const Player* player = creature->getPlayer())
        {
            if(!house->isInvited(player) && !player->hasCustomFlag(PlayerCustomFlag_CanMoveAnywhere))
                return RET_PLAYERISNOTINVITED;
        }
        else
            return RET_NOTPOSSIBLE;
    }
    else if(thing->getItem())
    {
        const uint32_t itemLimit = g_config.getNumber(ConfigManager::HOUSE_TILE_LIMIT);
        if(itemLimit && getItemCount() > itemLimit)
            return RET_TILEISFULL;

        if(actor && g_config.getBool(ConfigManager::HOUSE_PROTECTION))
        {
            if(const Player* player = actor->getPlayer())
            {
                if(!house->isInvited(player) && !player->hasCustomFlag(PlayerCustomFlag_CanThrowAnywhere))
                    return RET_PLAYERISNOTINVITED;
            }
        }
    }

    return Tile::__queryAdd(index, thing, count, flags, actor);
}


housetile.cpp
Code:
ReturnValue HouseTile::__queryRemove(const Thing* thing, uint32_t count, uint32_t flags, Creature* actor/* = NULL*/) const
{
    if(thing->getItem() && actor && g_config.getBool(ConfigManager::HOUSE_PROTECTION))
    {
        if(const Player* player = actor->getPlayer())
        {
            if(!house->isInvited(player) && !player->hasCustomFlag(PlayerCustomFlag_CanThrowAnywhere))
                return RET_PLAYERISNOTINVITED;
        }
    }

    return Tile::__queryRemove(thing, count, flags, actor);
}


map.cpp
Code:
bool Map::placeCreature(const Position& centerPos, Creature* creature, bool extendedPos /*= false*/, bool forced /*= false*/)
{
    bool foundTile = false, placeInPz = false;
    Tile* tile = getTile(centerPos);
    if(tile && !extendedPos)
    {
        placeInPz = tile->hasFlag(TILESTATE_PROTECTIONZONE);
        uint32_t flags = FLAG_IGNOREBLOCKITEM;
        if(creature->isAccountManager())
            flags |= FLAG_IGNOREBLOCKCREATURE;

        ReturnValue ret = tile->__queryAdd(0, creature, 1, flags);
        if(forced || ret == RET_NOERROR || ret == RET_PLAYERISNOTINVITED)
            foundTile = true;
    }
(...)


Does anyone have any idea what should be changed? Code in actions.cpp?
BG
So basically what you want to do is use a key instead of casting a spell/command to gain visitor/subowner/owner access rights to the house?
 
which tfs? i don't have found that code on actions.
TFS 0.3.7

So basically what you want to do is use a key instead of casting a spell/command to gain visitor/subowner/owner access rights to the house?
Not really, I want to have all "house commands" as usual and also I want to make possibility to click on non-house item as "use with" and use this item on house door. Now it is impossible becasue engine returns "You are not invited"
 
TFS 0.3.7


Not really, I want to have all "house commands" as usual and also I want to make possibility to click on non-house item as "use with" and use this item on house door. Now it is impossible becasue engine returns "You are not invited"
If you want to remove that you can just remove "return RET_PLAYERISNOTINVITED;" from Actions::canUse, or change it to RET_NOERROR.
 
Thank you.
But hmm.. how do you think - if I change it to RET_NOERROR then everything will be OK? I think that this method is made to avoid any problems but I do not have any idea why in default source code clicking "use item with" on a house tile is blocked. Does anyone have any idea?
Maybe there is possibility to return RET_NOERROR only if there is used only one item with ID that is implemented?
 
Thank you.
But hmm.. how do you think - if I change it to RET_NOERROR then everything will be OK? I think that this method is made to avoid any problems but I do not have any idea why in default source code clicking "use item with" on a house tile is blocked. Does anyone have any idea?
Maybe there is possibility to return RET_NOERROR only if there is used only one item with ID that is implemented?
I don't think there will be any problems with that, I believe it is for this:
http://tibia.wikia.com/wiki/Bed_modification_kit

But if the player from outside cant reach the bed there shouldn't be any problem I guess, can't think of anything else that uses action inside a house.
 
Yea, maybe :)
Anyway I would like to add something like this: only item with ID 2275 should be able to use on house door.
It would be something like this:
Code:
If (item.itemid == 2275)
    RET_NOERROR;
else
    RET_PLAYERISNOTINVITED;
but how can it be written in C++? ;)
 
Last edited:
Yea, maybe :)
Anyway I would like to add something like this: only item with ID 2275 should be able to use on house door.
It would be something like this:
Code:
If (item.itemid == 2275)
    RET_NOERROR;
else
    RET_PLAYERISNOTINVITED;
but how can it be written in C++? ;)
You can't, not in this function.
ReturnValue Actions::canUse(const Player* player, const Position& pos) there is no itemId there.

You would have to edit the function and add an item parameter
 
Ok I changed source code and now when house owner leaves items in house door tile then all other players can use it :/ There must be any solution
 
Well, I am trying.

There are 2 methods in actions.cpp - canUse and canUseEx
Code:
ReturnValue Actions::canUse(const Player* player, const Position& pos)
{
    const Position& playerPos = player->getPosition();
    if(pos.x == 0xFFFF)
        return RET_NOERROR;

    if(playerPos.z > pos.z)
        return RET_FIRSTGOUPSTAIRS;

    if(playerPos.z < pos.z)
        return RET_FIRSTGODOWNSTAIRS;

    if(!Position::areInRange<1,1,0>(playerPos, pos))
        return RET_TOOFARAWAY;

    Tile* tile = g_game.getTile(pos);
    if(tile)
    {
        HouseTile* houseTile = tile->getHouseTile();
        if(houseTile && houseTile->getHouse() && !houseTile->getHouse()->isInvited(player))
            return RET_PLAYERISNOTINVITED;
    }
    return RET_NOERROR;
}

Code:
ReturnValue Actions::canUseEx(const Player* player, const Position& pos, const Item* item)
{
    Action* action = NULL;

    if((action = getAction(item, ACTION_UNIQUEID)))
        return action->canExecuteAction(player, pos);

    if((action = getAction(item, ACTION_ACTIONID)))
        return action->canExecuteAction(player, pos);

    if((action = getAction(item, ACTION_ITEMID)))
        return action->canExecuteAction(player, pos);

    if((action = getAction(item, ACTION_RUNEID)))
        return action->canExecuteAction(player, pos);

    if(defaultAction)
        return defaultAction->canExecuteAction(player, pos);

    return RET_NOERROR;
}


To method canUseEx I added:
Code:
    Tile* tile = g_game.getTile(pos);
    if(tile)
    {
        HouseTile* houseTile = tile->getHouseTile();
        const ItemType& it = Item::items[item->getID()];
        if(houseTile && houseTile->getHouse() && !houseTile->getHouse()->isInvited(player))
        {
            if (it.id == 2281)
                return defaultAction->canExecuteAction(player, pos);
            else
                return RET_PLAYERISNOTINVITED;
        }
    }

and it works if line return RET_PLAYERISNOTINVITED; in first method is commented, but this line can not be commented becasue when house owner leaves items in house door tile then everyone will be able to use it.

I click on item and then I use it on house door so I have no idea why canUse method is executed instead of canUseEx...
Does anyone know how can it be solved?
 
Anyone with better C++ knowledge?

Code:
    Tile* tile = g_game.getTile(pos);
    if(tile)
    {
        HouseTile* houseTile = tile->getHouseTile();
        const ItemType& it = Item::items[item->getID()];
        if(houseTile && houseTile->getHouse() && !houseTile->getHouse()->isInvited(player))
        {
            if (it.id == 2281) {
                return RET_NOERROR;
            }
        }
    }
   
    if(defaultAction)
        return defaultAction->canExecuteAction(player, pos);
 
Back
Top