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

TFS 0.4 Attack Speed problem

Songo Krul

New Member
Joined
Nov 28, 2018
Messages
2
Reaction score
0
Yo
I want to do attack speed skill (for example 190 as -> 100 hit speed -> 10 hits per 1 sec), i edited creature.h creature think interval (1, 100) and my getAttackSpeed func in player.cpp
My problem is in doAttacking func. Attack speed is not stable - when i'm walking/using runes/clicking on something my AS is stopping or speeding up. i tried to remove scheduler tasks like in few tutorials but it doesn't work. Also when i'm attacking with fist (without weapon) my server crashes (idk why lol)
my player.cpp:
[C++] Attack Speed Problem - Pastebin.com
 
Solution
There are a few things that can cause issues with attackspeed. (Expecially fast attackspeed)

First, if you want attackspeed faster than 50 ms, you need to change SCHEDULER_MINTICKS.

Also I would try this for your doAttacking function.
Code:
void Player::doAttacking(uint32_t)
{
   if(!lastAttack)
       lastAttack = OTSYS_TIME() - getAttackSpeed() - 1;
   else if((OTSYS_TIME() - lastAttack) < getAttackSpeed())
   {
       int timeTillAttack = ((getAttackSpeed() - (OTSYS_TIME() - lastAttack))+1)
       SchedulerTask* task = createSchedulerTask(getAttackSpeed(),   boost::bind(&Game::checkCreatureAttack, &g_game, getID()));
       setNextActionTask(task);
       return;
   }
   
   if(hasCondition(CONDITION_PACIFIED) &&...
There are a few things that can cause issues with attackspeed. (Expecially fast attackspeed)

First, if you want attackspeed faster than 50 ms, you need to change SCHEDULER_MINTICKS.

Also I would try this for your doAttacking function.
Code:
void Player::doAttacking(uint32_t)
{
   if(!lastAttack)
       lastAttack = OTSYS_TIME() - getAttackSpeed() - 1;
   else if((OTSYS_TIME() - lastAttack) < getAttackSpeed())
   {
       int timeTillAttack = ((getAttackSpeed() - (OTSYS_TIME() - lastAttack))+1)
       SchedulerTask* task = createSchedulerTask(getAttackSpeed(),   boost::bind(&Game::checkCreatureAttack, &g_game, getID()));
       setNextActionTask(task);
       return;
   }
   
   if(hasCondition(CONDITION_PACIFIED) && !hasCustomFlag(PlayerCustomFlag_IgnorePacification))
   {
       lastAttack = OTSYS_TIME();
       return;
   }

   Item* item = getWeapon(false);
   if(const Weapon* _weapon = g_weapons->getWeapon(item))
   {
       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, item, attackedCreature))
           {
               lastAttack = OTSYS_TIME();
               SchedulerTask* task = createSchedulerTask(getAttackSpeed(),   boost::bind(&Game::checkCreatureAttack, &g_game, getID()));
               setNextActionTask(task);
           }

           updateWeapon();
       }
   }
   else if(Weapon::useFist(this, attackedCreature))
       lastAttack = OTSYS_TIME();
}

Let me know if it works.
 
Solution
Back
Top