Skip to content

Commit

Permalink
Let game determine starting clip size
Browse files Browse the repository at this point in the history
This replaces the previous CWX behavior of fully manually
replenishing an item's clip to maximum with a call to the game's
functionality to determine the default clip amount.

This allows CWX to gracefully handle the case of weapons that start
with 0 in the clip (the case for weapons that can be overloaded).
  • Loading branch information
nosoop committed Nov 9, 2023
1 parent 9ac98cb commit 204430d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions scripting/cwx/item_entity.sp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ bool TF2_RemoveItemByLoadoutSlot(int client, int loadoutSlot) {
}

/**
* Equips the given econ item. If the item is a weapon, the ammo and clip are reset to full
* capacity.
* Equips the given econ item. If the item is a weapon, the ammo and clip are reset to their
* correct starting capacity.
*/
void TF2_EquipPlayerEconItem(int client, int item) {
char weaponClass[64];
Expand All @@ -71,9 +71,15 @@ void TF2_EquipPlayerEconItem(int client, int item) {
EquipPlayerWeapon(client, item);
TF2_ResetWeaponAmmo(item);

int ammoType = GetEntProp(item, Prop_Send, "m_iPrimaryAmmoType");
if (ammoType != -1) {
SetEntProp(item, Prop_Send, "m_iClip1", TF2Util_GetWeaponMaxClip(item));
}
/**
* This calls CBaseCombatWeapon::GiveDefaultAmmo(), which sets up the appropriate clip
* count. This mainly handles the case when the `auto_fires_full_clip` attribute class
* is present on the item.
*
* Hope there aren't any further side effects from calling ActivateEntity; otherwise
* we'll have to add support for CBaseCombatWeapon::GiveDefaultAmmo() somewhere.
* Probably in TF2 Utils.
*/
ActivateEntity(item);
}
}

0 comments on commit 204430d

Please sign in to comment.