Advertisement
OvidiuS

UTIL_DropWeapons

Feb 1st, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.05 KB | None | 0 0
  1.     int UTIL_DropWeapons( edict_t *pPlayer, int bitWeaponType )
  2.     {
  3.             char aWeapons[ 32 ],pszWeaponName[ 32 ];
  4.      
  5.             int cCount, pWeapon, pWeapon2, iWeaponIndex, iWeaponIndex2;
  6.      
  7.             bool fDropAmmo = true;
  8.      
  9.             edict_t *pEntity;
  10.             edict_t *pEntity2;
  11.      
  12.             get_user_weapons( pPlayer, aWeapons, &cCount );
  13.            
  14.             for( pWeapon = 0; pWeapon < cCount; pWeapon++ )
  15.             {
  16.                     iWeaponIndex = aWeapons[ pWeapon ];
  17.                    
  18.                     if( ( bitWeaponType & DROP_PRIMARY ) && ( ( 1 << iWeaponIndex ) & PRIMARY_WEAPONS_BITSUM )
  19.                     || ( bitWeaponType & DROP_SECONDARY ) && ( ( 1 << iWeaponIndex ) & SECONDARY_WEAPONS_BITSUM ) )
  20.                     {
  21.                             edict_t* pWeapon = get_pdata_cbase( pPlayer, m_pActiveItem, 5 );
  22.      
  23.                             static char strText[4096];
  24.                             sprintf_s( strText, sizeof(strText)-1,"%s", (int)pPlayer->v.health , WEAPONENTNAMES[ GetWeaponType( pWeapon ) ] );
  25.      
  26.                             pEntity = find_ent_by_owner( -1, pszWeaponName, pPlayer );
  27.                            
  28.                             if( !pEntity )
  29.                                     continue;
  30.                            
  31.                             for( pWeapon2 = 0; pWeapon2 < cCount; pWeapon2++ )
  32.                             {
  33.                                     iWeaponIndex2 = aWeapons[ pWeapon2 ];
  34.                                    
  35.                                     if( ( bitWeaponType & DROP_PRIMARY ) && ( ( 1 << iWeaponIndex2 ) & PRIMARY_WEAPONS_BITSUM )
  36.                                     || ( bitWeaponType & DROP_SECONDARY ) && ( ( 1 << iWeaponIndex2 ) & SECONDARY_WEAPONS_BITSUM ) )
  37.                                     {
  38.                                             pEntity2 = get_pdata_cbase( pPlayer, m_pActiveItem, 5 );
  39.                                    
  40.                                    
  41.                                             if( !pEntity2 )
  42.                                                     continue;
  43.      
  44.                                             int iAmmoIndex;
  45.                                             int iAmmoIndex2;
  46.      
  47.      
  48.                                             #ifdef _WIN32
  49.                                                     iAmmoIndex = reinterpret_cast<int (__fastcall *)(void *, int)>((*((void***)((char*)pEntity->pvPrivateData)))[VirtFuncAmmoIndex])(pEntity->pvPrivateData, 0);
  50.                                                     iAmmoIndex2 = reinterpret_cast<int (__fastcall *)(void *, int)>((*((void***)((char*)pEntity2->pvPrivateData)))[VirtFuncAmmoIndex])(pEntity2->pvPrivateData, 0);
  51.                                             #elif defined __linux__
  52.                                                     iAmmoIndex = reinterpret_cast<int (*)(void *)>((*((void***)(((char*)pWeapon->pvPrivateData)))[VirtFuncAmmoIndex])(pWeapon->pvPrivateData);
  53.                                                     iAmmoIndex2 = reinterpret_cast<int (__fastcall *)(void *, int)>((*((void***)((char*)pEntity2->pvPrivateData)))[VirtFuncAmmoIndex])(pEntity2->pvPrivateData, 0);
  54.                                             #endif
  55.      
  56.                                            
  57.                                             if( iAmmoIndex == iAmmoIndex2 )
  58.                                                     fDropAmmo = true;
  59.                                     }
  60.                             }
  61.                            
  62.                             if( fDropAmmo )
  63.                             {
  64.      
  65.                                     pEntity->EV_INT_ammo = cs_get_user_backpackammo( pPlayer, iWeaponIndex );
  66.      
  67.      
  68.                                     cs_set_user_backpackammo( pPlayer, iWeaponIndex, 0 );
  69.                             }
  70.                            
  71.                             //CLIENT_COMMAND( pPlayer, "drop %s\n", pszWeaponName );
  72.                     }      
  73.             }
  74.             return 1;
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement