• 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++ classicAttackSpeed

peteralto

Member
Joined
Nov 1, 2020
Messages
93
Solutions
1
Reaction score
19
Would it be possible to include a check in this function, so that classicAttackSpeed only works for players with storage x = 1? The idea would be to limit this feature so that only a few people can have this advantage, without the server exploding.

TFS 1.3 downgrade
player.cpp
C++:
void Player::doAttacking(uint32_t)
{
    if (lastAttack == 0) {
        lastAttack = OTSYS_TIME() - getAttackSpeed() - 1;
    }


    if (hasCondition(CONDITION_PACIFIED)) {
        return;
    }


    if ((OTSYS_TIME() - lastAttack) >= getAttackSpeed()) {
        bool result = false;


        Item* tool = getWeapon();
        const Weapon* weapon = g_weapons->getWeapon(tool);
        uint32_t delay = getAttackSpeed();
        bool classicSpeed = g_config.getBoolean(ConfigManager::CLASSIC_ATTACK_SPEED);


        if (weapon) {
            if (!weapon->interruptSwing()) {
                result = weapon->useWeapon(this, tool, attackedCreature);
            } else if (!classicSpeed && !canDoAction()) {
                delay = getNextActionTime();
            } else {
                result = weapon->useWeapon(this, tool, attackedCreature);
            }
        } else {
            result = Weapon::useFist(this, attackedCreature);
        }


        SchedulerTask* task = createSchedulerTask(std::max<uint32_t>(SCHEDULER_MINTICKS, delay),
                                                  [id = getID()]() { g_game.checkCreatureAttack(id); });
        if (!classicSpeed) {
            setNextActionTask(task, false);
        } else {
            g_scheduler.addEvent(task);
        }


        if (result) {
            lastAttack = OTSYS_TIME();
        }
    }
}
 
Last edited:
Solution
1>C:\OT\src\player.cpp(3468,13): error C2660: 'Player::setNextActionTask': function does not take 2 arguments
1>C:\OT\src\player.cpp(1577,14): message : see declaration of 'Player::setNextActionTask'
1>C:\OT\src\player.cpp(3468,13): message : while trying to match the argument list '(SchedulerTask *, bool)'


TFS compile without problems here, make sure you are adding the changes correctly to your Code, do not copy all, just replace this part:

C++:
if (!classicSpeed) {
          setNextActionTask(task, false);
} 
else {
    g_scheduler.addEvent(task);
}

for this new one:


C++:
int32_t value;
getStorageValue(19998, value);  //change this Storage

if (classicSpeed && value != 0) {
    g_scheduler.addEvent(task);
}
else {...
Would it be possible to include a check in this function, so that classicAttackSpeed only works for players with storage x = 1? The idea would be to limit this feature so that only a few people can have this advantage, without the server exploding.

Try this:
C++:
void Player::doAttacking(uint32_t)
{
    if (lastAttack == 0) {
        lastAttack = OTSYS_TIME() - getAttackSpeed() - 1;
    }


    if (hasCondition(CONDITION_PACIFIED)) {
        return;
    }


    if ((OTSYS_TIME() - lastAttack) >= getAttackSpeed()) {
        bool result = false;


        Item* tool = getWeapon();
        const Weapon* weapon = g_weapons->getWeapon(tool);
        uint32_t delay = getAttackSpeed();
        bool classicSpeed = g_config.getBoolean(ConfigManager::CLASSIC_ATTACK_SPEED);


        if (weapon) {
            if (!weapon->interruptSwing()) {
                result = weapon->useWeapon(this, tool, attackedCreature);
            }
            else if (!classicSpeed && !canDoAction()) {
                delay = getNextActionTime();
            }
            else {
                result = weapon->useWeapon(this, tool, attackedCreature);
            }
        }
        else {
            result = Weapon::useFist(this, attackedCreature);
        }


        SchedulerTask* task = createSchedulerTask(std::max<uint32_t>(SCHEDULER_MINTICKS, delay),
            [id = getID()]() { g_game.checkCreatureAttack(id); });

        int32_t value;
        getStorageValue(19998, value);  //change this Storage

        if (classicSpeed && value != 0) {
            g_scheduler.addEvent(task);
        }
        else {
            setNextActionTask(task, false);
        }


        if (result) {
            lastAttack = OTSYS_TIME();
        }
    }
}


It is necessary that classicAttackSpeed be enabled and that the Player has Storage at 1 or greater (different from 0) for it to work.

i put 19998 u can change
 
Try this:
C++:
void Player::doAttacking(uint32_t)
{
    if (lastAttack == 0) {
        lastAttack = OTSYS_TIME() - getAttackSpeed() - 1;
    }


    if (hasCondition(CONDITION_PACIFIED)) {
        return;
    }


    if ((OTSYS_TIME() - lastAttack) >= getAttackSpeed()) {
        bool result = false;


        Item* tool = getWeapon();
        const Weapon* weapon = g_weapons->getWeapon(tool);
        uint32_t delay = getAttackSpeed();
        bool classicSpeed = g_config.getBoolean(ConfigManager::CLASSIC_ATTACK_SPEED);


        if (weapon) {
            if (!weapon->interruptSwing()) {
                result = weapon->useWeapon(this, tool, attackedCreature);
            }
            else if (!classicSpeed && !canDoAction()) {
                delay = getNextActionTime();
            }
            else {
                result = weapon->useWeapon(this, tool, attackedCreature);
            }
        }
        else {
            result = Weapon::useFist(this, attackedCreature);
        }


        SchedulerTask* task = createSchedulerTask(std::max<uint32_t>(SCHEDULER_MINTICKS, delay),
            [id = getID()]() { g_game.checkCreatureAttack(id); });

        int32_t value;
        getStorageValue(19998, value);  //change this Storage

        if (classicSpeed && value != 0) {
            g_scheduler.addEvent(task);
        }
        else {
            setNextActionTask(task, false);
        }


        if (result) {
            lastAttack = OTSYS_TIME();
        }
    }
}


It is necessary that classicAttackSpeed be enabled and that the Player has Storage at 1 or greater (different from 0) for it to work.

i put 19998 u can change
1>C:\OT\src\player.cpp(3468,13): error C2660: 'Player::setNextActionTask': function does not take 2 arguments
1>C:\OT\src\player.cpp(1577,14): message : see declaration of 'Player::setNextActionTask'
1>C:\OT\src\player.cpp(3468,13): message : while trying to match the argument list '(SchedulerTask *, bool)'
 
1>C:\OT\src\player.cpp(3468,13): error C2660: 'Player::setNextActionTask': function does not take 2 arguments
1>C:\OT\src\player.cpp(1577,14): message : see declaration of 'Player::setNextActionTask'
1>C:\OT\src\player.cpp(3468,13): message : while trying to match the argument list '(SchedulerTask *, bool)'


TFS compile without problems here, make sure you are adding the changes correctly to your Code, do not copy all, just replace this part:

C++:
if (!classicSpeed) {
          setNextActionTask(task, false);
} 
else {
    g_scheduler.addEvent(task);
}

for this new one:


C++:
int32_t value;
getStorageValue(19998, value);  //change this Storage

if (classicSpeed && value != 0) {
    g_scheduler.addEvent(task);
}
else {
    setNextActionTask(task, false);
}
 
Solution
TFS compile without problems here, make sure you are adding the changes correctly to your Code, do not copy all, just replace this part:

C++:
if (!classicSpeed) {
          setNextActionTask(task, false);
}
else {
    g_scheduler.addEvent(task);
}

for this new one:


C++:
int32_t value;
getStorageValue(19998, value);  //change this Storage

if (classicSpeed && value != 0) {
    g_scheduler.addEvent(task);
}
else {
    setNextActionTask(task, false);
}
Work, thank you!
 
Back
Top