AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to get primary weapon (https://forums.alliedmods.net/showthread.php?t=183321)

Bilal Pro 04-20-2012 14:01

How to get primary weapon
 
Hello there,

I like to learn how to get someone's primary weapon
i used this for example:
PHP Code:

if (user_has_weapon(idCSW_M4A1))
{
    
ColorChat(idBLUE"^1You already have this ^3weapon")
    return 
PLUGIN_HANDLED


But how to get all the primary weapons with one line?

claudiuhks 04-20-2012 14:12

Re: How to get primary weapon
 
PHP Code:

static iWeapons32 ], iWeaponsCountiiWeaponsList;
iWeaponsCount iWeaponsList 0;
get_user_weaponsiPlayeriWeaponsiWeaponsCount );

for( 
0iWeaponsCounti++ )
{
  
iWeaponsList |= ( << iWeapons] );
}

if( 
iWeaponsList & ( << CSW_M4A1 ) )
{
  
/* do this */;



Bilal Pro 04-20-2012 16:24

Re: How to get primary weapon
 
Lol i mean like:
PHP Code:

user_has_weapon(idPRIMARY_WEAPON

like that something?

claudiuhks 04-20-2012 16:27

Re: How to get primary weapon
 
PHP Code:

const PRIMARY_WEAPONS = ( << CSW_AK47 ) | ( << CSW_AUG ) | ( << CSW_GALIL );

static 
iWeapons32 ], iWeaponsCountiboolbHasPrimary;
iWeaponsCount 0bHasPrimary false;
get_user_weaponsiPlayeriWeaponsiWeaponsCount );

for( 
0iWeaponsCounti++ )
{
  if( ( 
<< iWeapons] ) & PRIMARY_WEAPONS )
  {
    
bHasPrimary true;

    break;
  }
}

if( 
bHasPrimary )
{
  
/* do this */;



Bilal Pro 04-20-2012 17:31

Re: How to get primary weapon
 
thanks

Exolent[jNr] 04-24-2012 10:15

Re: How to get primary weapon
 
You can get rid of the whole loop.

Code:
if(pev(id, pev_weapons) & PRIMARY_WEAPONS) {     // has primary } else {     // does not have primary }

EpicMonkey 04-24-2012 10:32

Re: How to get primary weapon
 
Quote:

Originally Posted by Exolent[jNr] (Post 1695610)
You can get rid of the whole loop.

Code:
if(pev(id, pev_weapons) & PRIMARY_WEAPONS) {     // has primary } else {     // does not have primary }

simple and efficient :3

Bilal Pro 04-24-2012 13:48

Re: How to get primary weapon
 
what is ->
PHP Code:

pev 

?

Bilal Pro 04-24-2012 14:06

Re: How to get primary weapon
 
nvm, solved


All times are GMT -4. The time now is 07:43.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.