• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

C++ TFS 0.3.6 Delay of the first attack

rafaeru

Active Member
Joined
Mar 6, 2013
Messages
143
Solutions
10
Reaction score
30
Location
Poland
GitHub
rafaeru97
Hello, i have a problem with add delay of the first attack. I have attack speed on my server and i want this because players use script in elfbot on target and stop target very fast.

I try add lastAttack after new target but something doesn't work.

Piece of code:

void Player::doAttacking(uint32_t interval)
C++:
void Player::doAttacking(uint32_t interval)
{
    if(!lastAttack)
        lastAttack = OTSYS_TIME() - getAttackSpeed() - 1;
    else if((OTSYS_TIME() - lastAttack) < getAttackSpeed())
        return;

    if(hasCondition(CONDITION_PACIFIED) && !hasCustomFlag(PlayerCustomFlag_IgnorePacification))
    {
        lastAttack = OTSYS_TIME();
        return;
    }

    Item* tool = getWeapon();
    if(const Weapon* weapon = g_weapons->getWeapon(tool))
    {
        if(weapon->interruptSwing() && !canDoAction())
        {
            SchedulerTask* task = createSchedulerTask(getNextActionTime(), boost::bind(&Game::checkCreatureAttack, &g_game, getID()));
            setNextActionTask(task);
        }
        else if((!weapon->hasExhaustion() || !hasCondition(CONDITION_EXHAUST, EXHAUST_COMBAT)) && weapon->useWeapon(this, tool, attackedCreature))
            lastAttack = OTSYS_TIME();
    }
    else if(Weapon::useFist(this, attackedCreature))
        lastAttack = OTSYS_TIME();
}

void Player:: onAttackedCreature(Creature* target)
C++:
void Player::onAttackedCreature(Creature* target)
{
    Creature::onAttackedCreature(target);
    if(hasFlag(PlayerFlag_NotGainInFight))
        return;

    addInFightTicks();
    Player* targetPlayer = target->getPlayer();
    if(!targetPlayer)
        return;
 
    addAttacked(targetPlayer);
    if(targetPlayer == this && targetPlayer->getZone() != ZONE_PVP)
    {
        targetPlayer->sendCreatureSkull(this);
        return;
    }

    if(Combat::isInPvpZone(this, targetPlayer) || isPartner(targetPlayer) || (g_config.getBool(
        ConfigManager::ALLOW_FIGHTBACK) && targetPlayer->hasAttacked(this)))
        return;

    if(!pzLocked)
    {
        pzLocked = true;
        sendIcons();
    }

    if(getZone() != target->getZone())
        return;

    if(skull == SKULL_NONE)
    {
        if(targetPlayer->getSkull() != SKULL_NONE)
            targetPlayer->sendCreatureSkull(this);
        else if(!hasCustomFlag(PlayerCustomFlag_NotGainSkull))
        {
            setSkull(SKULL_WHITE);
            g_game.updateCreatureSkull(this);
        }
    }
}
 
Is this the code with the changes you modified?

Try using this, it's way cleaner written than yours:


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

    if((OTSYS_TIME() - lastAttack) < getAttackSpeed())
        return;

    if(hasCondition(CONDITION_PACIFIED) && !hasCustomFlag(PlayerCustomFlag_IgnorePacification))
        return;

    Item* tool = getWeapon();
    if(const Weapon* weapon = g_weapons->getWeapon(tool))
    {
        if(weapon->interruptSwing() && !canDoAction())
        {
            SchedulerTask* task = createSchedulerTask(getNextActionTime(), boost::bind(&Game::checkCreatureAttack, &g_game, getID()));
            setNextActionTask(task);
        }
        else if((!hasCondition(CONDITION_EXHAUST, 3) || !weapon->hasExhaustion()) && weapon->useWeapon(this, tool, attackedCreature))
            lastAttack = OTSYS_TIME();
    }
    else if(Weapon::useFist(this, attackedCreature))
        lastAttack = OTSYS_TIME();
}

onAttackedCreature:
C++:
void Player::onAttackedCreature(Creature* target)
{
    Creature::onAttackedCreature(target);

    if(!hasFlag(PlayerFlag_NotGainInFight))
    {
        if(target != this)
        {
            if(Player* targetPlayer = target->getPlayer())
            {
                pzLocked = true;
                if(!isPartner(targetPlayer) && !Combat::isInPvpZone(this, targetPlayer) && !targetPlayer->hasAttacked(this))
                {
                    addAttacked(targetPlayer);
                    if(targetPlayer->getSkull() == SKULL_NONE && getSkull() == SKULL_NONE && !hasCustomFlag(PlayerCustomFlag_NotGainSkull))
                    {
                        setSkull(SKULL_WHITE);
                        g_game.updateCreatureSkull(this);
                    }

                    if(getSkull() == SKULL_NONE)
                        targetPlayer->sendCreatureSkull(this);
                }
            }
        }
        addInFightTicks();
    }
}

You're probably missing the addInFightTicks();

Please let me know the results once you replaced the codes, recompiled an tested, also if you have problems compiling it (errors or warnings).

Kindest Regards,
Okke
 
Back
Top