//----------------------------------------------------------------------------- // Ask: Let's update the label, shall we? //----------------------------------------------------------------------------- void CManhackScreen::OnTick() { BaseClass::OnTick(); // Get our player CBasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return; // Get the players active weapon CBaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); // If pWeapon is NULL or it doesn't use primary ammo, don't update our screen if ( !pWeapon || pWeapon->GetSecondaryAmmoType() != GetAmmoDef()->Index( "ManhacksOnline" ) ) return; // Our RPG isn't clip-based, so we need to check the player's arsenal of rockets int manhacks = pPlayer->GetAmmoCount( pWeapon->GetSecondaryAmmoType() ); if (m_pManhackOnline) { if (manhacks>0) { m_pManhackOnline->SetText("ONLINE"); m_pManhackOnline->SetFgColor(Color(0,255,0,255)); } else { m_pManhackOnline->SetText("OFFLINE"); m_pManhackOnline->SetFgColor(Color(255,0,0,255)); } } // If our Label exist if ( m_pManhackCount ) { char buf[32]; Q_snprintf( buf, sizeof( buf ), "%d", manhacks ); // Set the Labels text to the number of missiles we have left. m_pManhackCount->SetText( buf ); m_pManhackCount->SetFgColor(Color(255,255,255,255)); } if ( m_pManhackDistance ) { char buf[32]; Q_snprintf( buf, sizeof( buf ), "%d", m_iManhackDistance ); // Set the Labels text to the number of missiles we have left. int xpos, ypos; m_pManhackDistance->GetPos(xpos,ypos); int charWidth = vgui::surface()->GetCharacterWidth(m_pManhackDistance->GetFont(),'0'); xpos = 100; if (m_iManhackDistance>=10) xpos -= charWidth; if (m_iManhackDistance>=100) xpos -= charWidth; m_pManhackDistance->SetPos(xpos,ypos); m_pManhackDistance->SetText( buf ); m_pManhackDistance->SetFgColor(Color(255,255,255,255)); } }