AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Whats the expressio for something like"except"? (https://forums.alliedmods.net/showthread.php?t=168716)

maoxianxie 10-03-2011 02:41

Whats the expressio for something like"except"?
 
If I want to let a player can only own Ak47,then how to check wether a player has other weapons ?

e12harry 10-03-2011 02:45

Re: Whats the expressio for something like"except"?
 
get_user_weapons ( index, weapons[32], &num )

http://www.amxmodx.org/funcwiki.php?go=func&id=163

maoxianxie 10-03-2011 02:52

Re: Whats the expressio for something like"except"?
 
What should I do ?Sorry, but I really dont know,thx.

e12harry 10-03-2011 04:00

Re: Whats the expressio for something like"except"?
 
It depends on what you want to achieve.
If you want to check if player has any other weapon than AK (including knife and c4):
PHP Code:

stock bool:userHasOtherWeaponsThanAk(id)
{
    new 
weapons[32];
    new 
num;
    
get_user_weapons idweaponsnum );
    if(
num >1)
        return 
true;
    if(
num == && weapons[0] != CSW_AK47)
        return 
true;
    return 
false;


This stock will return false only if player do not have any weapons or he has got only AK.


If you want to check if player has other weapon than AK (but let him have knife and C4):

PHP Code:

stock bool:userHasOtherWeapons(idweapon)
{
    new 
weapons[32];
    new 
num;
    
get_user_weapons idweaponsnum );
    new 
weapon;
    for(new 
i=0;i<num;i++){
        
weapon weapons[i];
        if(
weapon != CSW_AK47
            
&& weapon != CSW_KNIFE     //delete this line if user can not have knife
            
&& weapon != CSW_C4    //delete this line if user can not have C4
        
)
        return 
true;
    }
    return 
false;


This will return false if player has other weapons than AK, knife and C4

maoxianxie 10-03-2011 04:30

Re: Whats the expressio for something like"except"?
 
:)THX!

maoxianxie 10-03-2011 07:52

Re: Whats the expressio for something like"except"?
 
But what dose the parameter"weapon" in the second stock bool mean?(stock : bool userHasOtherWeapons(id,weapon))And how I should use it if I want to strip weapons and give Ak47,knife and c4 when user has other weapons ? Thanks for your kindness .

Bugsy 10-03-2011 08:09

Re: Whats the expressio for something like"except"?
 
Untested
PHP Code:

const AllowWeapons = ( << CSW_KNIFE ) | ( << CSW_C4 ) | ( << CSW_AK47 );
new 
iWeapons pevid pev_weapons );
new 
iOtherWeapons iWeapons & ~AllowWeapons;

if ( 
iOtherWeapons )
{
   
//user has weapon(s) not listed in AllowWeapons
}

//To drop other weapons and give allowed weapons
for ( new 31 p++ )
{
   if ( 
iOtherWeapons & ( << ) )
   {
       
//drop this
   
}
   else if ( ( 
AllowWeapons & ( << ) ) && !( iWeapons & ( << ) ) )
   {
       
//give this
   
}




All times are GMT -4. The time now is 19:33.

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