void CWeaponRPCs::TakeWeapon ( CClientEntity* pSource, NetBitStreamInterface& bitStream ) { // Read out weapon id and ammo amount SWeaponTypeSync weaponType; if ( bitStream.Read ( &weaponType ) ) { unsigned char ucWeaponID = weaponType.data.ucWeaponType; CClientPed * pPed = m_pPedManager->Get ( pSource->GetID (), true ); if ( pPed ) { // Is the weapon id valid? (may not be neccessary, just being safe) if ( CClientPickupManager::IsValidWeaponID ( ucWeaponID ) ) { // Have we ammo in packet? If so, we need to take the ammo, not weapon SWeaponAmmoSync ammo ( ucWeaponID, true, false ); if ( bitStream.Read ( &ammo ) ) { unsigned short usAmmo = ammo.data.usTotalAmmo; // Do we have the weapon? CWeapon* pPlayerWeapon = pPed->GetWeapon ( (eWeaponType) ucWeaponID ); if ( pPlayerWeapon == NULL ) return; unsigned char ucAmmoInClip = static_cast < unsigned char > ( pPlayerWeapon->GetAmmoInClip () ); pPlayerWeapon->SetAmmoInClip ( 0 ); unsigned long ulWeaponAmmo = pPlayerWeapon->GetAmmoTotal (); if ( usAmmo > ulWeaponAmmo ) ulWeaponAmmo = 0; else ulWeaponAmmo -= usAmmo; // Update the ammo pPlayerWeapon->SetAmmoTotal ( ulWeaponAmmo ); if ( pPlayerWeapon->GetAmmoTotal () > ucAmmoInClip ) pPlayerWeapon->SetAmmoInClip ( ucAmmoInClip ); else if ( pPlayerWeapon->GetAmmoTotal () <= ucAmmoInClip ) pPlayerWeapon->SetAmmoInClip ( pPlayerWeapon->GetAmmoTotal () ); } else { // Don't change remote players weapons (affects sync) if ( pPed->IsLocalPlayer () ) { // Remove the weapon pPed->RemoveWeapon ( static_cast < eWeaponType > ( ucWeaponID ) ); } } } } } }
void CPedWeapons::SetAmmoInClip(DWORD dwAmmoInClip) { CWeapon * pCurrentWeapon = GetCurrentWeapon(); if(m_pPedWeapons && pCurrentWeapon) { WORD wClipSize = pCurrentWeapon->GetClipSize(); if(dwAmmoInClip > wClipSize) dwAmmoInClip = wClipSize; DWORD dwCurrentAmmoInClip = pCurrentWeapon->GetAmmoInClip(); pCurrentWeapon->SetAmmoInClip(dwAmmoInClip); DWORD dwCurrentAmmo = pCurrentWeapon->GetAmmoTotal(); DWORD dwDifference = (dwAmmoInClip - dwCurrentAmmoInClip); if(dwDifference >= 25000) pCurrentWeapon->SetAmmoTotal(25000); DWORD dwNewAmmo = (dwCurrentAmmo + dwDifference); if(dwNewAmmo <= 25000) pCurrentWeapon->SetAmmoTotal(dwNewAmmo); else pCurrentWeapon->SetAmmoTotal(25000); } }
void CWeaponRPCs::TakeWeaponAmmo ( NetBitStreamInterface& bitStream ) { ElementID ID; SWeaponTypeSync weaponType; if ( bitStream.ReadCompressed ( ID ) && bitStream.Read ( &weaponType ) ) { unsigned char ucWeaponID = weaponType.data.ucWeaponType; SWeaponAmmoSync ammo ( ucWeaponID, true, false ); if ( bitStream.Read ( &ammo ) ) { unsigned short usAmmo = ammo.data.usTotalAmmo; CClientPed * pPed = m_pPedManager->Get ( ID, true ); if ( pPed ) { // Valid weapon id? if ( !CClientPickupManager::IsValidWeaponID ( ucWeaponID ) ) return; // Do we have it? CWeapon* pPlayerWeapon = pPed->GetWeapon ( (eWeaponType) ucWeaponID ); if ( pPlayerWeapon == NULL ) return; unsigned char ucAmmoInClip = static_cast < unsigned char > ( pPlayerWeapon->GetAmmoInClip () ); pPlayerWeapon->SetAmmoInClip ( 0 ); unsigned long ulWeaponAmmo = pPlayerWeapon->GetAmmoTotal (); if ( ulWeaponAmmo - usAmmo < 0 ) ulWeaponAmmo = 0; else ulWeaponAmmo -= usAmmo; // Remove the weapon ammo pPlayerWeapon->SetAmmoTotal ( ulWeaponAmmo ); if ( pPlayerWeapon->GetAmmoTotal () > ucAmmoInClip ) pPlayerWeapon->SetAmmoInClip ( ucAmmoInClip ); else if ( pPlayerWeapon->GetAmmoTotal () <= ucAmmoInClip ) pPlayerWeapon->SetAmmoInClip ( pPlayerWeapon->GetAmmoTotal () ); } } } }
void CWeaponRPCs::SetWeaponAmmo ( CClientEntity* pSource, NetBitStreamInterface& bitStream ) { SWeaponTypeSync weaponType; if ( bitStream.Read ( &weaponType ) ) { unsigned char ucWeaponID = weaponType.data.ucWeaponType; SWeaponAmmoSync ammo ( ucWeaponID, true, true ); if ( bitStream.Read ( &ammo ) ) { unsigned short usAmmo = ammo.data.usTotalAmmo; unsigned short usAmmoInClip = ammo.data.usAmmoInClip; CClientPed * pPed = m_pPedManager->Get ( pSource->GetID (), true ); if ( pPed ) { // Valid weapon id? if ( !CClientPickupManager::IsValidWeaponID ( ucWeaponID ) ) return; // Do we have it? CWeapon* pPlayerWeapon = pPed->GetWeapon ( (eWeaponType) ucWeaponID ); if ( pPlayerWeapon == NULL ) return; unsigned char ucAmmoInClip = static_cast < unsigned char > ( pPlayerWeapon->GetAmmoInClip () ); pPlayerWeapon->SetAmmoInClip ( usAmmoInClip ); pPlayerWeapon->SetAmmoTotal ( usAmmo ); if ( !usAmmoInClip ) { if ( usAmmo > ucAmmoInClip ) pPlayerWeapon->SetAmmoInClip ( ucAmmoInClip ); else if ( usAmmo <= ucAmmoInClip ) pPlayerWeapon->SetAmmoInClip ( usAmmo ); } } } } }