Adding Empty Reload Animations

From Valve Developer Community
Revision as of 22:37, 7 December 2023 by Nbc66 (talk | contribs) (Created page with "== Adding empty reloads == Adding empty reloads to all weapons is super easy all you have to do is make the following change inside '''''basecombatweapon_shared.cpp''''' on...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Adding empty reloads

Adding empty reloads to all weapons is super easy

all you have to do is make the following change inside basecombatweapon_shared.cpp on Line 2070

replace the following line

basecombatweapon_shared.cpp
bool CBaseCombatWeapon::Reload( void )
{
	return DefaultReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD );
}

With The Following

bool CBaseCombatWeapon::Reload( void )
{
	return DefaultReload( GetMaxClip1(), GetMaxClip2(), Clip1() == 0 ? ACT_VM_RELOAD_EMPTY : ACT_VM_RELOAD );
}

This will give you the ability to call ACT_VM_RELOAD_EMPTY animations on you weapons

Limit ACT_VM_RELOAD_EMTPY To Specific Weapons

if you do not want all of your weapons to have ACT_VM_RELOAD_EMTPY animations you can do the following

Inside of weapon_parse.h on Line 100

you will see the following line

weapon_parse.h
char					szAmmo2[MAX_WEAPON_AMMO_NAME];			// "secondary" ammo type

UNDERNEATH THAT LINE ADD THE FOLLOWING

bool					bEmptyReload;							// Empty Reload

Now go to weapon_parse.cpp

Inside of the FileWeaponInfo_t::FileWeaponInfo_t() Constructor add the following bool and set it to true

bEmptyReload = true

And inside the void FileWeaponInfo_t::Parse( KeyValues *pKeyValuesData, const char *szWeaponName ) Function

add the following to the top of the function

weapon_parse.cpp
bEmptyReload = pKeyValuesData->GetBool("emtpy_reload", true);

now go back to basecombatweapon_shared.cpp

and replace the Reload function with this

basecombatweapon_shared.cpp
bool CBaseCombatWeapon::Reload( void )
{
	if (GetWpnData().bEmptyReload == false)
	{
		return DefaultReload(GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD);
	}
	else
	{
		return DefaultReload(GetMaxClip1(), GetMaxClip2(), Clip1() == 0 ? ACT_VM_RELOAD_EMPTY : ACT_VM_RELOAD);
	}
}

now you can specify what weapon has or doesn't have the empty reload animation

example weapon.txt file

// Pistol

WeaponData
{
	// Weapon data is loaded by both the Game and Client DLLs.
	"printname"	"#HL2_Pistol"
	"viewmodel"			"models/weapons/v_pistol.mdl"
	"playermodel"		"models/weapons/w_pistol.mdl"
	"anim_prefix"		"pistol"
	"bucket"			"1"
	"bucket_position"	"0"

	"clip_size"			"18"
	"primary_ammo"		"Pistol"
	"secondary_ammo"	"None"

	"weight"			"2"
	"item_flags"			"0"
	"damage"			"8"

	// Sounds for the weapon. There is a max of 16 sounds per category (i.e. max 16 "single_shot" sounds)
	SoundData
	{

		"reload"		"Weapon_Pistol.Reload"
		"reload_npc"	"Weapon_Pistol.NPC_Reload"
		"empty"			"Weapon_Pistol.Empty"
		"single_shot"	"Weapon_Pistol.Single"
		"single_shot_npc"	"Weapon_Pistol.NPC_Single"
		"special1"		"Weapon_Pistol.Special1"
		"special2"		"Weapon_Pistol.Special2"
		"burst"			"Weapon_Pistol.Burst"
	}

	// Weapon Sprite data is loaded by the Client DLL.
	TextureData
	{
		"weapon"
		{
				"font"		"WeaponIcons"
				"character"	"d"
		}
		"weapon_s"
		{	
				"font"		"WeaponIconsSelected"
				"character"	"d"
		}
		"ammo"
		{
				"font"		"WeaponIcons"
				"character"	"p"
		}
		"crosshair"
		{
				"font"		"Crosshairs"
				"character"	"Q"
		}
		"autoaim"
		{
				"file"		"sprites/crosshairs"
				"x"			"0"
				"y"			"48"
				"width"		"24"
				"height"	"24"
		}
	}
}

add the following line to the top of the file to turn off the empty reload for the weapon

"emtpy_reload"		"0"

and that should be it

Note.pngNote:By Default all weapons have the empty reload set to true!