• 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++ One second delay

liqeen

Active Member
Joined
Nov 26, 2014
Messages
151
Solutions
1
Reaction score
30
Location
Poland
Hello,
How can I add a one second delay to this life leech function? I want it to execute just once a second even if player can execute it faster.

Lua:
        if (attackerPlayer) {
            //life leech
            if (normal_random(0, 100) < attackerPlayer->getSkillLevel(SKILL_LIFE_LEECH_CHANCE)) {
                CombatParams tmpParams;
                CombatDamage tmpDamage;
                tmpDamage.origin = ORIGIN_SPELL;
                tmpDamage.primary.type = COMBAT_HEALING;
                tmpDamage.primary.value = std::round((realDamage * (0.9 + (damage.affected / 10.)) * (attackerPlayer->getSkillLevel(SKILL_LIFE_LEECH_AMOUNT) /100.)) / damage.affected);

                Combat::doCombatHealth(nullptr, attackerPlayer, tmpDamage, tmpParams);
            }
Post automatically merged:

Nvm managed to do it solo somehow xD

game.cpp
Lua:
    if (attackerPlayer) {
      //life leech
      if (attackerPlayer->isLeechExhausted()) {
        return true;
      }
            if (normal_random(0, 100) < attackerPlayer->getSkillLevel(SKILL_LIFE_LEECH_CHANCE)) {
        attackerPlayer->updateLeechExhausted();
                CombatParams tmpParams;
                CombatDamage tmpDamage;
                tmpDamage.origin = ORIGIN_SPELL;
                tmpDamage.primary.type = COMBAT_HEALING;
                tmpDamage.primary.value = std::round((realDamage * (0.9 + (damage.affected / 10.)) * (attackerPlayer->getSkillLevel(SKILL_LIFE_LEECH_AMOUNT) /100.)) / damage.affected);
                Combat::doCombatHealth(nullptr, attackerPlayer, tmpDamage, tmpParams);
            }

player.cpp


Code:
bool Player::isLeechExhausted() const {
  uint32_t exhaust_time = 1000;
  return (OTSYS_TIME() - LeechInteraction < exhaust_time);
}

player.h
Code:
int64_t LeechInteraction = 0;
bool isLeechExhausted() const;
    void updateLeechExhausted() {
      LeechInteraction = OTSYS_TIME();
    }
 
Last edited:
Back
Top