TFS 1.X+ [C++] Crash when i unequip weapon with custom item attackspeed system

Cornwallis

Intermediate OT User
Joined
Jan 3, 2010
Messages
456
Reaction score
9
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:
OP
Cornwallis

Cornwallis

Intermediate OT User
Joined
Jan 3, 2010
Messages
456
Reaction score
9
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:
Top