• 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 1.X+ [C++] Crash when i unequip weapon with custom item attackspeed system

Cornwallis

Member
Joined
Jan 3, 2010
Messages
480
Reaction score
16
Hello, so I tried to make a workaround because at first it would crash everytime I used my fist, but now it only happens whenever I attack with a weapon and then unequip the weapon to hit with fist. Oddly though, if I switch between weapons with different attack speeds it acts accordingly. Here's the part that I presume is messing up:
Code:
void Player::doAttacking(uint32_t)
{
    Item* tool = getWeapon();
    const Weapon* weapon = g_weapons->getWeapon(tool);
    uint32_t atkspd = 0;
   
    if (tool) {
        if (tool->getAttackSpeed())    {
            atkspd = tool->getAttackSpeed();
        }    else {
        atkspd = 1500;
        }
    } else {
        atkspd = 1500;       
    }
   
    if (lastAttack == 0) {
        lastAttack = OTSYS_TIME() - atkspd*getAttackFactor() - 1;
    }

    if (hasCondition(CONDITION_PACIFIED)) {
        return;
    }

    if ((OTSYS_TIME() - lastAttack) >= atkspd*getAttackFactor()) {
        bool result = false;

        if (weapon) {
            result = weapon->useWeapon(this, tool, attackedCreature);
        } else {
            result = Weapon::useFist(this, attackedCreature);
        }

        if (result) {
            lastAttack = OTSYS_TIME();
        }
    }
}
 
Last edited:
bump
EDIT: It appears to not have anything to do with attackspeed actually. It appears to be when either the attacker or the target moves, and when they're at a range > 1.
 
Last edited:
Back
Top