Removing of agent weapon through script

Users who are viewing this thread

Kommissar

Recruit
I'm currently trying to create a system for breaking weapons. I want it to based on damage dealt. Anyway, my issue is that I get a random crash when a weapon is removed. Sometimes it works fine, but it will usually crash after 4-5 NPCs make a strike. Here's really simple sample code:

C#:
        public override void OnRegisterBlow(Agent attacker, Agent victim, GameEntity realHitEntity, Blow b, ref AttackCollisionData collisionData, in MissionWeapon attackerWeapon)
        {
            if (attacker.Character == null || attackerWeapon.Item == null)
            {
                return;
            }

            if (attacker.HasWeapon())
            {
                EquipmentIndex v = attacker.GetWieldedItemIndex(Agent.HandIndex.MainHand);
                if (v != EquipmentIndex.None)
                {
                    attacker.RemoveEquippedWeapon(v);
                }
            }
        }

Any idea at what point it's OK to remove a weapon?
 
Back
Top Bottom