Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HL] Some weapon reloading animations run twice #2301

Open
Matthaiks opened this issue Apr 25, 2019 · 5 comments
Open

[HL] Some weapon reloading animations run twice #2301

Matthaiks opened this issue Apr 25, 2019 · 5 comments

Comments

@Matthaiks
Copy link

Shoot and then spam the reload weapon key. The Glock, the MP5 and the Python will be reloaded twice. Python's second animation is cut, though.

This is not the same bug as #1076.

@rtxa
Copy link

rtxa commented Apr 26, 2019

I test it and I can confirm the issue, at leats in the beta version.

@SamVanheer
Copy link

SamVanheer commented Apr 26, 2019

This happens because weapon reloading was never fully implemented in the weapon prediction code on the client. As a result the client will think that the clip is not full and sets up another reload.

This is the code that changes the ammo values incorrectly:

#if 0 // FIXME, need ammo on client to make this work right
// complete the reload.
int j = min( iMaxClip() - m_iClip, m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]);
// Add them to the clip
m_iClip += j;
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= j;
#else
m_iClip += 10;
#endif

iMaxClip() returns 0 because item info is not cached like it is on the server.

I was able to fix this by changing the code to this:

#if 1 // FIXME, need ammo on client to make this work right
	// complete the reload. 
	ItemInfo ii;

	memset( &ii, 0, sizeof( ii ) );

	GetItemInfo( &ii );

	int j = V_min( ii.iMaxClip - m_iClip, m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]);

	// Add them to the clip
	m_iClip += j;
	m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] -= j;
#else	
	m_iClip += 10;
#endif

It's a bit ugly since it calls GetItemInfo every time but this will ensure it correctly adjusts the clip and spare ammo values during prediction.

A proper fix would require engine level changes to the data structures and networking system in order to network all ammo values which is impossible to do without breaking mods, so this will have to do.

Avoiding the GetItemInfo calls is possible by creating a list of all weapon classes on the client and caching the item info like the server does, but that's a lot of refactoring to do.

@Matthaiks
Copy link
Author

cl_lw is set to "1" by default. "0" fixes this bug, it seems.

@SamVanheer
Copy link

Yes, because it disables the prediction code. But it's not a fix.

@sjain882
Copy link

cl_lw is set to "1" by default. "0" fixes this bug, it seems.

That's a workaround not a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants