From 4eb83c07664594e561ac365c088d15140d6d077b Mon Sep 17 00:00:00 2001 From: smallmodel <15067410+smallmodel@users.noreply.github.com> Date: Wed, 27 Dec 2023 16:28:49 +0100 Subject: [PATCH] Fixed weapon attachments not being detached --- code/fgame/player_combat.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/code/fgame/player_combat.cpp b/code/fgame/player_combat.cpp index 313dd449..8c7ec81b 100644 --- a/code/fgame/player_combat.cpp +++ b/code/fgame/player_combat.cpp @@ -163,7 +163,7 @@ void Player::EventCorrectWeaponAttachments(Event *ev) iTagLeft = gi.Tag_NumForName(edict->tiki, "tag_weapon_left"); iNumChildren = numchildren; - for (int i = 0; i < iNumChildren; i++) { + for (int i = 0; i < MAX_MODEL_CHILDREN && iNumChildren; i++) { iChild = children[i]; if (iChild == ENTITYNUM_NONE) { @@ -176,18 +176,17 @@ void Player::EventCorrectWeaponAttachments(Event *ev) } if (pChild->edict->s.tag_num == iTagLeft || pChild->edict->s.tag_num == iTagRight) { - if (pChild->IsSubclassOfWeapon()) { - if (pChild->edict->s.tag_num == iTagLeft) { - iUseAngles = edict->s.attach_use_angles; - vOffset = edict->s.attach_offset; - - // reattach to the right tag - detach(); - attach(entnum, iTagRight, iUseAngles, vOffset); - } - } else { + if (!pChild->IsSubclassOfWeapon()) { // Remove entities like ammoclip pChild->PostEvent(EV_Remove, 0); + iNumChildren--; + } else if (pChild->edict->s.tag_num == iTagLeft) { + iUseAngles = edict->s.attach_use_angles; + vOffset = edict->s.attach_offset; + + // reattach to the right tag + pChild->detach(); + pChild->attach(entnum, iTagRight, iUseAngles, vOffset); } } }