• 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++ Remove OTSYS_TIME in code

primate

Member
Joined
Apr 14, 2009
Messages
68
Solutions
1
Reaction score
5
Location
Colombia, Medellín.
How can I make these lines not use "OTSYS_TIME()", For the following code and be able to use "potions[] = {26031, 26030};" and runes at the same time.

C++:
    int32_t potions[] = {26031, 26030};
    int16_t potionID = item->getID();
    if(std::find(std::begin(potions), std::end(potions), potionID) == std::end(potions))

C++:
bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos,
                        uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature/* = nullptr*/)
{
    int32_t potions[] = {26031, 26030};
    int16_t potionID = item->getID();
    if(std::find(std::begin(potions), std::end(potions), potionID) == std::end(potions)) {
        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;
}

Thanks for your time.
 
Hello Primate,

you can just remove the player->setNextAction(OTSYS_TIME() from the statement. Still you'll need to use EX_ACTIONS_DELAY_INTERVAL, which is set on your config.lua file.

C++:
    if(std::find(std::begin(potions), std::end(potions), potionID) == std::end(potions)) {
        g_config.getNumber(ConfigManager::EX_ACTIONS_DELAY_INTERVAL));
    }

Best Wishes,
Okke
 
Hello Primate,

you can just remove the player->setNextAction(OTSYS_TIME() from the statement. Still you'll need to use EX_ACTIONS_DELAY_INTERVAL, which is set on your config.lua file.

C++:
    if(std::find(std::begin(potions), std::end(potions), potionID) == std::end(potions)) {
        g_config.getNumber(ConfigManager::EX_ACTIONS_DELAY_INTERVAL));
    }

Best Wishes,
Okke
I had to remove ")" to let me compile "(ConfigManager :: EX_ACTIONS_DELAY_INTERVAL);", When making this change "timeBetweenExActions" it doesn't work at all.
 
I had to remove ")" to let me compile "(ConfigManager :: EX_ACTIONS_DELAY_INTERVAL);", When making this change "timeBetweenExActions" it doesn't work at all.
Oh I'm sorry, doing this from mobile doesn't really help me at all.

So try this for now and let me know the results:

C++:
bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos,
                        uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature/* = nullptr*/)
{
    int32_t potions[] = {26031, 26030};
    int16_t potionID = item->getID();
    if(std::find(std::begin(potions), std::end(potions), potionID) == std::end(potions)) {
        player->setNextAction(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;
}

Best Wishes,
Okke
 
Oh I'm sorry, doing this from mobile doesn't really help me at all.

So try this for now and let me know the results:

C++:
bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos,
                        uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature/* = nullptr*/)
{
    int32_t potions[] = {26031, 26030};
    int16_t potionID = item->getID();
    if(std::find(std::begin(potions), std::end(potions), potionID) == std::end(potions)) {
        player->setNextAction(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;
}

Best Wishes,
Okke
I was using it earlier this way, But whenever I remove "OTSYS_TIME ()", "timeBetweenExActions" stops working.
 
It was expected. If you remove OTSYS_TIME() it won't know the delay to set the next action for the player.

There is a hack to achieve what you're willing to, and it's to set it to: player->setNextAction(OTSYS_TIME()) itself and then add an extra timer for attacking spells / runes and healing spells / runes / potions.

I don't have enough time to write this down for you as I'm flat out at work, if no one comes and do it I will when I have free time :)

Best Wishes,
Okke
 
What am I missing here? Do you ever clarify why you do not want to use the function OTSYS_TIME?

How can I make these lines not use "OTSYS_TIME()"
If this is your end goal, you are free to remove the function call, but it will obviously not work as you have already figured out.

What is your actual goal with this and why is OTSYS_TIME a problem?
 
What am I missing here? Do you ever clarify why you do not want to use the function OTSYS_TIME?


If this is your end goal, you are free to remove the function call, but it will obviously not work as you have already figured out.

What is your actual goal with this and why is OTSYS_TIME a problem?

he wants to
be able to use "potions[] = {26031, 26030};" and runes at the same time.
 
Alright, so you are not setting a timeout if a potion is used.
However, the problem you are facing is that the server still checks for a timeout when using runes and potions.
I assume that you are able to spam potions without cooldown with the changes you have provided (not sure if that is intended).

You have to adjust this check (otland/forgottenserver (https://github.com/otland/forgottenserver/blob/7b0f8e28e64b98c157e99b0b5a6e0df299ee9db9/src/game.cpp#L2078-L2084)) as well.
If you want potion to have no cooldown at all, you can do a similar adjustment as the one you did in actions.cpp.
If however you intend potions to have a cooldown as well, I would recommend moving the "cooldown" check to the Action class and setting a different cooldown variable depending on whether the player uses a rune or a potion.

Edit:
This is relevant too: otland/forgottenserver (https://github.com/otland/forgottenserver/blob/7b0f8e28e64b98c157e99b0b5a6e0df299ee9db9/src/game.cpp#L2233-L2239)
 
Back
Top