本文整理汇总了C++中CTFPlayer::GiveNamedItem方法的典型用法代码示例。如果您正苦于以下问题:C++ CTFPlayer::GiveNamedItem方法的具体用法?C++ CTFPlayer::GiveNamedItem怎么用?C++ CTFPlayer::GiveNamedItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CTFPlayer
的用法示例。
在下文中一共展示了CTFPlayer::GiveNamedItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EquipPlayer
void CTFPlayerEquip::EquipPlayer(CBaseEntity *pEntity)
{
CTFPlayer *pTFPlayer = ToTFPlayer(pEntity);
if (!pTFPlayer)
return;
for (int i = 0; i < TF_PLAYER_WEAPON_COUNT; i++)
{
if (m_bStripWeapons)
{
CTFWeaponBase *pWeapon = pTFPlayer->Weapon_GetWeaponByType(i);
if (pWeapon)
{
pTFPlayer->Weapon_Detach(pWeapon);
pTFPlayer->SwitchToNextBestWeapon(NULL);
UTIL_Remove(pWeapon);
}
}
if (m_iWeaponNumber[i])
{
if (!m_bStripWeapons)
{
CTFWeaponBase *pWeapon = pTFPlayer->Weapon_GetWeaponByType(GetTFWeaponInfo(m_iWeaponNumber[i])->m_iWeaponType);
if (pWeapon)
{
pTFPlayer->Weapon_Detach(pWeapon);
pTFPlayer->SwitchToNextBestWeapon(NULL);
UTIL_Remove(pWeapon);
}
}
pTFPlayer->GiveNamedItem(GetTFWeaponInfo(m_iWeaponNumber[i])->szClassName);
}
}
}
示例2: MyTouch
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFDroppedWeapon::MyTouch( CBasePlayer *pPlayer )
{
bool bSuccess = false;
CTFPlayer *pTFPlayer = dynamic_cast<CTFPlayer *>( pPlayer );
if ( ValidTouch( pTFPlayer ) && pTFPlayer->IsPlayerClass( TF_CLASS_MERCENARY ) )
{
// Don't remove weapon while a player is standing over it.
SetThink( NULL );
#ifndef DM_WEAPON_BUCKET
int iSlot = m_Item.GetStaticData()->GetLoadoutSlot( TF_CLASS_MERCENARY );
CTFWeaponBase *pWeapon = (CTFWeaponBase *)pTFPlayer->GetEntityForLoadoutSlot( iSlot );
const char *pszWeaponName = m_Item.GetEntityName();
int iAmmoType = m_pWeaponInfo->iAmmoType;
if ( pWeapon )
{
if ( pWeapon->GetItemID() == m_Item.GetItemDefIndex() )
{
// Give however many ammo we have
if ( pTFPlayer->GiveAmmo( m_iAmmo, iAmmoType, true, TF_AMMO_SOURCE_AMMOPACK ) )
bSuccess = true;
}
else if ( !(pTFPlayer->m_nButtons & IN_ATTACK) && ( pTFPlayer->m_nButtons & IN_USE ) ) // Check Use button
{
// Drop a usable weapon
pTFPlayer->DropWeapon( pWeapon );
if ( pWeapon == pTFPlayer->GetActiveTFWeapon() )
{
pWeapon->Holster();
}
pTFPlayer->Weapon_Detach( pWeapon );
UTIL_Remove( pWeapon );
pWeapon = NULL;
}
else
{
pTFPlayer->m_Shared.SetDesiredWeaponIndex( m_Item.GetItemDefIndex() );
}
}
#else
CTFWeaponBase *pWeapon = pTFPlayer->Weapon_OwnsThisID( m_nWeaponID );
if ( pWeapon )
{
if ( pTFPlayer->GiveAmmo( 999, GetTFWeaponInfo( m_nWeaponID )->iAmmoType ) );
bSuccess = true;
}
#endif
if ( !pWeapon )
{
CTFWeaponBase *pNewWeapon = (CTFWeaponBase *)pTFPlayer->GiveNamedItem( pszWeaponName, 0, &m_Item );
if ( pNewWeapon )
{
pPlayer->SetAmmoCount( m_iAmmo, iAmmoType );
pNewWeapon->DefaultTouch( pPlayer );
if ( pPlayer == GetOwnerEntity() )
{
// If this is the same guy who dropped it restore old clip size to avoid exploiting swapping
// weapons for faster reload.
pNewWeapon->m_iClip1 = m_iClip;
}
pTFPlayer->m_Shared.SetDesiredWeaponIndex( -1 );
bSuccess = true;
}
}
if ( bSuccess )
{
CSingleUserRecipientFilter user( pPlayer );
user.MakeReliable();
UserMessageBegin( user, "ItemPickup" );
WRITE_STRING( GetClassname() );
MessageEnd();
pPlayer->EmitSound( "BaseCombatCharacter.AmmoPickup" );
}
}
return bSuccess;
}
示例3: MyTouch
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CWeaponSpawner::MyTouch( CBasePlayer *pPlayer )
{
bool bSuccess = false;
CTFPlayer *pTFPlayer = ToTFPlayer( pPlayer );
if ( ValidTouch( pTFPlayer ) && pTFPlayer->IsPlayerClass( TF_CLASS_MERCENARY ) )
{
#ifndef DM_WEAPON_BUCKET
int iSlot = m_Item.GetStaticData()->GetLoadoutSlot( TF_CLASS_MERCENARY );
CTFWeaponBase *pWeapon = (CTFWeaponBase *)pTFPlayer->GetEntityForLoadoutSlot( iSlot );
if ( pWeapon )
{
if ( pTFPlayer->ItemsMatch( pWeapon->GetItem(), &m_Item, pWeapon ) )
{
if ( pTFPlayer->GiveAmmo( pWeapon->GetInitialAmmo(), pWeapon->GetPrimaryAmmoType(), true, TF_AMMO_SOURCE_AMMOPACK ) )
bSuccess = true;
}
else if ( !( pTFPlayer->m_nButtons & IN_ATTACK ) &&
( pTFPlayer->m_nButtons & IN_USE ||
( TFGameRules()->IsDeathmatch() && pWeapon->GetWeaponID() == TF_WEAPON_PISTOL ) ) ) // Check Use button, always replace pistol.
{
// Drop a usable weapon
pTFPlayer->DropWeapon( pWeapon );
pWeapon->UnEquip( pTFPlayer );
pWeapon = NULL;
}
else
{
pTFPlayer->m_Shared.SetDesiredWeaponIndex( m_nItemID );
}
}
#else
CTFWeaponBase *pWeapon = pTFPlayer->Weapon_OwnsThisID( m_nWeaponID );
const char *pszWeaponName = WeaponIdToClassname( m_nWeaponID );
if ( pWeapon )
{
if ( pPlayer->GiveAmmo(999, m_pWeaponInfo->iAmmoType) )
bSuccess = true;
}
#endif
if ( !pWeapon )
{
const char *pszWeaponName = m_Item.GetEntityName();
CTFWeaponBase *pNewWeapon = (CTFWeaponBase *)pTFPlayer->GiveNamedItem( pszWeaponName, 0, &m_Item );
if ( pNewWeapon )
{
pPlayer->SetAmmoCount( pNewWeapon->GetInitialAmmo(), pNewWeapon->GetPrimaryAmmoType() );
pNewWeapon->GiveTo( pPlayer );
pTFPlayer->m_Shared.SetDesiredWeaponIndex( -1 );
bSuccess = true;
}
}
if ( bSuccess )
{
CSingleUserRecipientFilter user( pPlayer );
user.MakeReliable();
UserMessageBegin( user, "ItemPickup" );
WRITE_STRING( GetClassname() );
MessageEnd();
pPlayer->EmitSound( "BaseCombatCharacter.AmmoPickup" );
}
}
return bSuccess;
}