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

Help with hotkeys wrong message

Manigold

Active Member
Joined
Nov 2, 2017
Messages
197
Solutions
8
Reaction score
47
I'm having a problem when i use fluids on hotkeys (manafluid,lifefluid etc).
i always receive the count of vials , not the fluids inside vials ,i want to show the count of manafluids or other fluids inside the vials .

(manafluid id 2006,7)

ex:
36445


here's the showUseHotkeyMessage part on the actions.cpp


C++:
bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item* item, bool isHotkey)
{
    player->setNextAction(OTSYS_TIME() + g_config.getNumber(ConfigManager::ACTIONS_DELAY_INTERVAL));
    //player->stopWalk();

    if (isHotkey) {
        showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1));
    }

    ReturnValue ret = internalUseItem(player, pos, index, item, isHotkey);
    if (ret != RETURNVALUE_NOERROR) {
        player->sendCancelMessage(ret);
        return false;
    }
    return true;
}

bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos,
                        uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature/* = nullptr*/)
{
    player->setNextAction(OTSYS_TIME() + g_config.getNumber(ConfigManager::EX_ACTIONS_DELAY_INTERVAL));
    //player->stopWalk();

    Action* action = getAction(item);
    if (!action) {
        player->sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT);
        return false;
    }

    ReturnValue ret = action->canExecuteAction(player, toPos);
    if (ret != RETURNVALUE_NOERROR) {
        player->sendCancelMessage(ret);
        return false;
    }

    if (isHotkey) {
        showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1));
    }

    if (!action->executeUse(player, item, fromPos, action->getTarget(player, creature, toPos, toStackPos), toPos, isHotkey)) {
        if (!action->hasOwnErrorHandler()) {
            player->sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT);
        }
        return false;
    }
    return true;
}

void Actions::showUseHotkeyMessage(Player* player, const Item* item, uint32_t count)
{
    std::ostringstream ss;

    const ItemType& it = Item::items[item->getID()];
    if (!it.showCount) {
        ss << "Using one of " << item->getName() << "...";
    } else if (count == 1) {
        ss << "Using the last " << item->getName() << "...";
    } else {
        ss << "Using one of " << count << ' ' << item->getPluralName() << "...";
    }
    player->sendTextMessage(MESSAGE_INFO_DESCR, ss.str());
}
 
Last edited:
Solution
Hi, in the function
C++:
bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item* item, bool isHotkey)
Search for:
C++:
showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1));
Change this line for this:
C++:
showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), item->getSubType()));
Then search for:
C++:
bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos,
                        uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature/* = nullptr*/)
Search for:
C++:
showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1));
Change this line for this:
C++:
showUseHotkeyMessage(player, item...
I'm having a problem when i use fluids on hotkeys (manafluid,lifefluid etc).
i always receive the count of vials , not the fluids inside vials ,i want to show the count of manafluids or other fluids inside the vials .

(manafluid id 2006,7)

ex:
View attachment 36445


here's the showUseHotkeyMessage part on the actions.cpp


C++:
bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item* item, bool isHotkey)
{
    player->setNextAction(OTSYS_TIME() + g_config.getNumber(ConfigManager::ACTIONS_DELAY_INTERVAL));
    //player->stopWalk();

    if (isHotkey) {
        showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1));
    }

    ReturnValue ret = internalUseItem(player, pos, index, item, isHotkey);
    if (ret != RETURNVALUE_NOERROR) {
        player->sendCancelMessage(ret);
        return false;
    }
    return true;
}

bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos,
                        uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature/* = nullptr*/)
{
    player->setNextAction(OTSYS_TIME() + g_config.getNumber(ConfigManager::EX_ACTIONS_DELAY_INTERVAL));
    //player->stopWalk();

    Action* action = getAction(item);
    if (!action) {
        player->sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT);
        return false;
    }

    ReturnValue ret = action->canExecuteAction(player, toPos);
    if (ret != RETURNVALUE_NOERROR) {
        player->sendCancelMessage(ret);
        return false;
    }

    if (isHotkey) {
        showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1));
    }

    if (!action->executeUse(player, item, fromPos, action->getTarget(player, creature, toPos, toStackPos), toPos, isHotkey)) {
        if (!action->hasOwnErrorHandler()) {
            player->sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT);
        }
        return false;
    }
    return true;
}

void Actions::showUseHotkeyMessage(Player* player, const Item* item, uint32_t count)
{
    std::ostringstream ss;

    const ItemType& it = Item::items[item->getID()];
    if (!it.showCount) {
        ss << "Using one of " << item->getName() << "...";
    } else if (count == 1) {
        ss << "Using the last " << item->getName() << "...";
    } else {
        ss << "Using one of " << count << ' ' << item->getPluralName() << "...";
    }
    player->sendTextMessage(MESSAGE_INFO_DESCR, ss.str());
}
Could you send engine source code?
 
idk if this will work but we can try to asked for subtype then :
change this :
Code:
void Actions::showUseHotkeyMessage(Player* player, const Item* item, uint32_t count)
{
    std::ostringstream ss;

    const ItemType& it = Item::items[item->getID()];
    if (!it.showCount) {
        ss << "Using one of " << item->getName() << "...";
    } else if (count == 1) {
        ss << "Using the last " << item->getName() << "...";
    } else {
        ss << "Using one of " << count << ' ' << item->getPluralName() << "...";
    }
    player->sendTextMessage(MESSAGE_INFO_DESCR, ss.str());
}
to
Code:
void Actions::showUseHotkeyMessage(Player* player, const Item* item, uint32_t count)
{
    std::ostringstream ss;

    const ItemType& it = Item::items[item->getID()];
    if (!it.showCount) {
        ss << "Using one of " << item->getSubType() << "...";
    } else if (count == 1) {
        ss << "Using the last " << item->getSubType() << "...";
    } else {
        ss << "Using one of " << count << ' ' << item->getSubType() << "...";
    }
    player->sendTextMessage(MESSAGE_INFO_DESCR, ss.str());
}
you can also change getSubType() to getFluidType() , i think your items.xml names them vials because this source gets the item name so if you want it to be better without changing sources check items names in items.xml
 
idk if this will work but we can try to asked for subtype then :
change this :
Code:
void Actions::showUseHotkeyMessage(Player* player, const Item* item, uint32_t count)
{
    std::ostringstream ss;

    const ItemType& it = Item::items[item->getID()];
    if (!it.showCount) {
        ss << "Using one of " << item->getName() << "...";
    } else if (count == 1) {
        ss << "Using the last " << item->getName() << "...";
    } else {
        ss << "Using one of " << count << ' ' << item->getPluralName() << "...";
    }
    player->sendTextMessage(MESSAGE_INFO_DESCR, ss.str());
}
to
Code:
void Actions::showUseHotkeyMessage(Player* player, const Item* item, uint32_t count)
{
    std::ostringstream ss;

    const ItemType& it = Item::items[item->getID()];
    if (!it.showCount) {
        ss << "Using one of " << item->getSubType() << "...";
    } else if (count == 1) {
        ss << "Using the last " << item->getSubType() << "...";
    } else {
        ss << "Using one of " << count << ' ' << item->getSubType() << "...";
    }
    player->sendTextMessage(MESSAGE_INFO_DESCR, ss.str());
}
you can also change getSubType() to getFluidType() , i think your items.xml names them vials because this source gets the item name so if you want it to be better without changing sources check items names in items.xml
thanks but didn't work =( ,i find some examples on old sources( avesta, otserver 0.6.4, etc ), maybe someone can help me make it work with tfs 1.2 sources
C++:
bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos,
    uint8_t toStackPos, Item* item, bool isHotkey, uint32_t creatureId /* = 0*/)
{
    if(OTSYS_TIME() - player->getLastAction() < g_config.getNumber(ConfigManager::MIN_ACTIONEXTIME)){
        return false;
    }

    Action* action = getAction(item);
    if(!action){
        player->sendCancelMessage(RET_CANNOTUSETHISOBJECT);
        return false;
    }

    int32_t fromStackPos = item->getParent()->__getIndexOfThing(item);
    PositionEx fromPosEx(fromPos, fromStackPos);
    PositionEx toPosEx(toPos, toStackPos);
    ReturnValue ret = RET_NOERROR;

    if(isHotkey){
        int32_t subType = -1;
        if(item->hasSubType() && !item->hasCharges()){
            subType = item->getSubType();
        }

        uint32_t itemCount = player->__getItemTypeCount(item->getID(), subType, false);
        ret = internalUseItemEx(player, fromPosEx, toPosEx, item, isHotkey, creatureId);
        showUseHotkeyMessage(player, item, itemCount);
    }
    else{
        ret = internalUseItemEx(player, fromPosEx, toPosEx, item, isHotkey, creatureId);
    }

    if(ret != RET_NOERROR){
        player->sendCancelMessage(ret);
        return false;
    }

    player->setLastAction(OTSYS_TIME());
    return true;
}

void Actions::showUseHotkeyMessage(Player* player, Item* item, uint32_t itemCount)
{
    std::stringstream ss;
    if(itemCount == 1){
        ss << "Using the last " << item->getName() << "...";
    }
    else{
        ss << "Using one of " << itemCount << " " << item->getPluralName() << "...";
    }
    
    player->sendTextMessage(MSG_INFO_DESCR, ss.str());
}

C++:
    //look for the item in action maps   
    Action* action = getAction(item);
    
                if (isHotKey) {
                    std::stringstream cinfo;
                    int count = player->getBotItemCount(item->getClientID(), itemType);
                    // Count fist.
                    if(count == 1)
                       cinfo << "Using the last ";
                    else
                       cinfo << "Using one of " << count << " ";
                        
                    // vial,spell rune?
                    if(item->isRune() && count <= 1)
                       cinfo << "spell rune";
                    else if(item->isRune() && count > 1)
                       cinfo << "spell runes";
                    else if(item->isFluidContainer() && count <= 1)
                       cinfo << "vial";
                    else if(item->isFluidContainer() && count > 1)
                       cinfo << "vials";
                    else if(count <= 1)
                       cinfo << item->getName();
                    else if(count > 1)
                       cinfo << item->getName() + "s";
                    
                    if(count > 1)
                       cinfo << "...";
                    else
                       cinfo << ".";
                    
                    // send message xD
                    player->sendTextMessage(MSG_INFO_DESCR, cinfo.str().c_str());
                }
    
    //if found execute it
    if(action){
        int32_t stack = item->getParent()->__getIndexOfThing(item);
        PositionEx posEx(pos, stack);
        if(action->executeUse(player, item, posEx, posEx, false)){
            return true;
        }
    }


C++:
bool Actions::useItemEx(Player* player, const Position& from_pos,
    const Position& to_pos, const unsigned char to_stack, Item* item, bool isHotKey /*= false*/, uint8_t itemType /* = 0*/)
{
    Action* action = getAction(item);
    
                if (isHotKey) {
                    std::stringstream cinfo;
                    int count = player->getBotItemCount(item->getClientID(), itemType);
                    // Count fist.
                    if(count == 1)
                       cinfo << "Using the last ";
                    else
                       cinfo << "Using one of " << count << " ";
                        
                    // vial,spell rune?
                    if(item->isRune() && count <= 1)
                       cinfo << "spell rune";
                    else if(item->isRune() && count > 1)
                       cinfo << "spell runes";
                    else if(item->isFluidContainer() && count <= 1)
                       cinfo << "vial";
                    else if(item->isFluidContainer() && count > 1)
                       cinfo << "vials";

                    else if(count <= 1)
                       cinfo << item->getName();
                    else if(count > 1)
                       cinfo << item->getName() + "s";

                    
                    if(count > 1)
                       cinfo << "...";
                    else
                       cinfo << ".";
                    
                    // send message :P
                    player->sendTextMessage(MSG_INFO_DESCR, cinfo.str().c_str());
                    
                }
    
    if(action){
        bool ret = action->canExecuteAction(player, to_pos);
        if(ret){
            int32_t from_stack = item->getParent()->__getIndexOfThing(item);
            PositionEx posFromEx(from_pos, from_stack);
            PositionEx posToEx(to_pos, to_stack);
            if(action->executeUse(player, item, posFromEx, posToEx, true)){
                return true;
            }
        }

    }
 
Hi, in the function
C++:
bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item* item, bool isHotkey)
Search for:
C++:
showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1));
Change this line for this:
C++:
showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), item->getSubType()));
Then search for:
C++:
bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos,
                        uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature/* = nullptr*/)
Search for:
C++:
showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1));
Change this line for this:
C++:
showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), item->getSubType()));

Mark as the best answer if it works, thank you.
 
Solution
Hi, in the function
C++:
bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item* item, bool isHotkey)
Search for:
C++:
showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1));
Change this line for this:
C++:
showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), item->getSubType()));
Then search for:
C++:
bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos,
                        uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature/* = nullptr*/)
Search for:
C++:
showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), -1));
Change this line for this:
C++:
showUseHotkeyMessage(player, item, player->getItemTypeCount(item->getID(), item->getSubType()));

Mark as the best answer if it works, thank you.
perfect thanks \o/
 
do you happen to know how to make it count the charges aswell for the hotkeymessage? say i have a bag of runes and all have different charges, so it will sum it up instead of just counting how many runes there are
 
Back
Top