本文整理汇总了C++中CClientPed::GiveWeapon方法的典型用法代码示例。如果您正苦于以下问题:C++ CClientPed::GiveWeapon方法的具体用法?C++ CClientPed::GiveWeapon怎么用?C++ CClientPed::GiveWeapon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CClientPed
的用法示例。
在下文中一共展示了CClientPed::GiveWeapon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: COMMAND_GiveWeapon
void COMMAND_GiveWeapon ( const char *szCmdLine )
{
if ( !(szCmdLine && szCmdLine[0]) )
return;
int nWeaponID = atoi(szCmdLine);
/*
* Check validity of the command line weapon id.
*/
if ( !CClientPickupManager::IsValidWeaponID ( nWeaponID ) )
return;
CClientPed * pPed = g_pClientGame->GetManager()->GetPlayerManager()->GetLocalPlayer();
if ( pPed )
{
CWeapon * pPlayerWeapon = pPed->GiveWeapon ( (eWeaponType)nWeaponID, 9999 );
if ( pPlayerWeapon )
{
pPlayerWeapon->SetAsCurrentWeapon();
}
}
}
示例2: GiveWeapon
void CWeaponRPCs::GiveWeapon ( NetBitStreamInterface& bitStream )
{
// Read out weapon id and ammo amount
ElementID ID;
SWeaponTypeSync weaponType;
if ( bitStream.ReadCompressed ( ID ) &&
bitStream.Read ( &weaponType ) )
{
SWeaponAmmoSync ammo ( weaponType.data.ucWeaponType, true, false );
if ( bitStream.Read ( &ammo ) )
{
bool bGiveWeapon = bitStream.ReadBit ();
unsigned char ucWeaponID = weaponType.data.ucWeaponType;
unsigned short usAmmo = ammo.data.usTotalAmmo;
CClientPed * pPed = m_pPedManager->Get ( ID, true );
if ( pPed )
{
// Don't change remote players weapons (affects sync)
if ( pPed->GetType () == CCLIENTPED || pPed->GetType () == CCLIENTPLAYER )
{
// Valid weapon id?
if ( ucWeaponID == 0 || CClientPickupManager::IsValidWeaponID ( ucWeaponID ) )
{
// Adjust the ammo to 9999 if it's above
if ( usAmmo > 9999 ) usAmmo = 9999;
// Give the local player the weapon
CWeapon* pPlayerWeapon = NULL;
if ( ucWeaponID != 0 )
{
pPlayerWeapon = pPed->GiveWeapon ( static_cast < eWeaponType > ( ucWeaponID ), usAmmo );
if ( pPlayerWeapon && bGiveWeapon )
pPlayerWeapon->SetAsCurrentWeapon ();
}
else
{
// This could be entered into a hack of the year competition. Its about as hacky as it gets.
// For some stupid reason, going from brassknuckles to unarmed causes the knuckles to remain
// on display but unusable. So, what we do is switch to a MELEE weapon (creating one if necessary)
// then switch back to unarmed from there, which works fine.
CWeapon* oldWeapon = pPed->GetWeapon (WEAPONSLOT_TYPE_UNARMED);
if ( oldWeapon )
{
eWeaponType unarmedWeapon = oldWeapon->GetType();
pPed->RemoveWeapon ( unarmedWeapon );
if ( bGiveWeapon || pPed->GetCurrentWeaponSlot() == WEAPONSLOT_TYPE_UNARMED )
{
oldWeapon = NULL;
if ( unarmedWeapon == WEAPONTYPE_BRASSKNUCKLE )
{
oldWeapon = pPed->GetWeapon(WEAPONSLOT_TYPE_MELEE);
if ( oldWeapon && oldWeapon->GetType() == WEAPONTYPE_UNARMED )
{
oldWeapon = pPed->GiveWeapon(WEAPONTYPE_GOLFCLUB, 100);
}
else
{
oldWeapon = NULL;
}
pPed->SetCurrentWeaponSlot ( WEAPONSLOT_TYPE_MELEE );
}
// switch to the unarmed slot
pPed->SetCurrentWeaponSlot ( WEAPONSLOT_TYPE_UNARMED );
// if we created a special MELEE weapon just for this, remove it now
if ( oldWeapon )
{
oldWeapon->Remove();
}
}
}
else
{
// Probably the ped is streamed out
pPed->GiveWeapon ( WEAPONTYPE_UNARMED, 1 );
if ( bGiveWeapon )
pPed->SetCurrentWeaponSlot ( WEAPONSLOT_TYPE_UNARMED );
}
}
}
}
}
}
}
}