You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes when you pick up a weapon that gives free or regenerating ammo on pickup the weapon icon shows as red to indicate the weapon is out of ammo.
This happens with the Hornet gun. To reproduce:
Start a multiplayer game (e.g. on map crossfire)
Pick up a Hornet gun
Empty it completely
Drop it before it regenerates ammo (console command drop weapon_hornetgun)
Pick the weapon up again
The HUD will show the weapon as red for a moment before changing it to the normal HUD color
This happens because the ammo HUD isn't told about ammo immediately. The server only updates the client's ammo HUD when it's processing inputs received from the client, which happens at a certain time relative to the server processing weapon pickup to allow out-of-sync state to occur.
As a result there is a small window between the server sending the weapon pickup message and the ammo update message.
To fix this the ammo HUD needs to be updated before the weapon pickup is sent.
The fix i'm about to describe builds on the fix for #3137.
WRITE_BYTE( max( min( m_rgAmmo[i], 254 ), 0 ) ); // clamp the value to one byte
MESSAGE_END();
}
}
}
To look like this:
voidCBasePlayer::SendAmmoUpdate()
{
for (int i = 0; i < MAX_AMMO_SLOTS; i++)
{
InternalSendSingleAmmoUpdate(i);
}
}
voidCBasePlayer::SendSingleAmmoUpdate(int ammoIndex)
{
if (ammoIndex < 0 || ammoIndex >= MAX_AMMO_SLOTS)
{
return;
}
InternalSendSingleAmmoUpdate(ammoIndex);
}
voidCBasePlayer::InternalSendSingleAmmoUpdate(int ammoIndex)
{
if (m_rgAmmo[ammoIndex] != m_rgAmmoLast[ammoIndex])
{
m_rgAmmoLast[ammoIndex] = m_rgAmmo[ammoIndex];
ASSERT(m_rgAmmo[ammoIndex] >= 0);
ASSERT(m_rgAmmo[ammoIndex] < 255);
// send "Ammo" update messageMESSAGE_BEGIN(MSG_ONE, gmsgAmmoX, NULL, pev);
WRITE_BYTE(ammoIndex);
WRITE_BYTE(max(min(m_rgAmmo[ammoIndex], 254), 0)); // clamp the value to one byteMESSAGE_END();
}
}
Referencing the code from #3137, modify CBasePlayerWeapon::AddToPlayer to look like this:
boolCBasePlayerWeapon::AddToPlayer(CBasePlayer* pPlayer)
{
int bResult = CBasePlayerItem::AddToPlayer(pPlayer);
pPlayer->pev->weapons |= (1<<m_iId);
if (!m_iPrimaryAmmoType)
{
m_iPrimaryAmmoType = pPlayer->GetAmmoIndex(pszAmmo1());
m_iSecondaryAmmoType = pPlayer->GetAmmoIndex(pszAmmo2());
}
if (!bResult)
{
returnFALSE;
}
if (!AddWeapon())
{
returnFALSE;
}
//Immediately update the ammo HUD so weapon pickup isn't sometimes red because the HUD doesn't know about regenerating/free ammo yet.if (-1 != m_iPrimaryAmmoType)
{
m_pPlayer->SendSingleAmmoUpdate(CBasePlayer::GetAmmoIndex(pszAmmo1()));
}
if (-1 != m_iSecondaryAmmoType)
{
m_pPlayer->SendSingleAmmoUpdate(CBasePlayer::GetAmmoIndex(pszAmmo2()));
}
//Don't show weapon pickup if we're spawning or if it's an exhaustible weapon (will show ammo pickup instead).if (!m_pPlayer->m_bIsSpawning && (iFlags() & ITEM_FLAG_EXHAUSTIBLE) == 0)
{
MESSAGE_BEGIN(MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev);
WRITE_BYTE(m_iId);
MESSAGE_END();
}
returnTRUE;
}
The changes made to SendAmmoUpdate allows the weapons code to send an update for a single ammo type. The changes made to AddToPlayer updates the ammo HUD before updating the pickup history HUD.
The text was updated successfully, but these errors were encountered:
Sometimes when you pick up a weapon that gives free or regenerating ammo on pickup the weapon icon shows as red to indicate the weapon is out of ammo.
This happens with the Hornet gun. To reproduce:
crossfire
)drop weapon_hornetgun
)This happens because the ammo HUD isn't told about ammo immediately. The server only updates the client's ammo HUD when it's processing inputs received from the client, which happens at a certain time relative to the server processing weapon pickup to allow out-of-sync state to occur.
As a result there is a small window between the server sending the weapon pickup message and the ammo update message.
To fix this the ammo HUD needs to be updated before the weapon pickup is sent.
The fix i'm about to describe builds on the fix for #3137.
After this line:
halflife/dlls/player.h
Line 279 in c7240b9
Add:
Modify this function:
halflife/dlls/player.cpp
Lines 3918 to 3936 in c7240b9
To look like this:
Referencing the code from #3137, modify
CBasePlayerWeapon::AddToPlayer
to look like this:The changes made to
SendAmmoUpdate
allows the weapons code to send an update for a single ammo type. The changes made toAddToPlayer
updates the ammo HUD before updating the pickup history HUD.The text was updated successfully, but these errors were encountered: