AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_user_weapons (https://forums.alliedmods.net/showthread.php?t=182970)

striker07 04-15-2012 18:00

get_user_weapons
 
I need this native but im not sure how it works, could some1 explain it a bit better to me

Functionwiki - get_user_weapons

Example:
PHP Code:

new Weapons[32
new 
numWeaponsiweapon 
get_user_weapons
(idWeaponsnumWeapons
for (
i=0i<numWeaponsi++) 

   
weapon Weapons[i


What will this return? A number of how many weapons that player has? or the names of all the weapons that this player has in the form of CSW_ ?
Do i need the make an enum list of all the CSW_ weapons it could return?

claudiuhks 04-15-2012 18:11

Re: get_user_weapons
 
PHP Code:

const SOME_WEAPONS_I_WANT = ( << CSW_USP ) | ( << CSW_M4A1 );

static 
iWeapons32 ], iNumi;
iNum 0;
get_user_weaponsiPlayeriWeaponsiNum );

// iNum -> Weapons count
// iWeapons[ 0 ] -> First weapon
// iWeapons[ 1 ] -> Second weapon

for( 0iNumi++ )
  if( ( 
<< iWeapons] ) & SOME_WEAPONS_I_WANT // If this weapon we are currently parsing is contained in SOME_WEAPONS_I_WANT bitsum then:
    
/* Your code */ 

Of course, CSW_*, DODW_*, TFW_*.

striker07 04-15-2012 18:17

Re: get_user_weapons
 
I need to do something if a player has a weapon in his inventory so as soon as a player has a gun (pistol or primary weapon + knife ),
how could i do that?

claudiuhks 04-15-2012 18:19

Re: get_user_weapons
 
If a player has a weapon in his inventory, then what exactly do you want to do?

striker07 04-15-2012 18:28

Re: get_user_weapons
 
Quote:

Originally Posted by claudiuhks (Post 1689951)
If a player has a weapon in his inventory, then what exactly do you want to do?

the moment a player dies and the victim had more then one weapon (knife + any other PRIMARY weapon) then i want to ignore the rest of the following code.

Spoiler

EDIT:
To explain it a lil better:

I need to use this function in the event: DeathMsg, its for an anti freekill system i'm working on.
To check if a victim has a primary weapon, so if the victim only had a knife AND he was not a rebel then i want to ignore the rest of the code in event: DeathMsg.

or in other words:

If the victim was not a rebel but had a primary weapon when he died (even if he wasnt holding that primary weapon) then i want to ignore the rest of the code.

This is how im using it now:
PHP Code:

public Event_DeathMsg() 

    new 
iKiller read_data(1); 
    new 
iVictim read_data(2);
    
    new 
freekill_slay get_pcvar_num(jb_slay_4freekills)
    new 
max_freekills get_pcvar_num(jb_max_freekills);
    new 
szVName[32], szKName[32]; 
    
get_user_name(iVictimszVNamecharsmax(szVName)); 
    
get_user_name(iKillerszKNamecharsmax(szKName));

    
clear_bit(g_bIsAliveiVictim);
    
    if( 
cs_get_user_teamiVictim ) == CS_TEAM_T 
    {  
        if( 
IsPlayeriKiller ) && cs_get_user_teamiKiller ) == CS_TEAM_CT 
        { 
            if( 
g_bRebel[iVictim] ) 
            { 
                
fnColorPrint(0"Guard^4 %s ^1killed rebel^4 %s ^1!"szKNameszVName); 
            }
            else if( !
g_bRebel[iVictim] ) //if victim is not a rebel   &&\/
            
{
                new 
Weapons[32];
                new 
numWeaponsiweapon;
                
get_user_weapons(iVictim,WeaponsnumWeapons); 
                for (
i=0i<numWeaponsi++) 
                { 
                    
weapon Weapons[i]; 
                    if(
weapon >= )                      //if he has a primary weapon, then ignore the rest
                        
return PLUGIN_HANDLED;
                } 

                
g_iFreekill[iKiller]++
                
                if(
g_iFreekill[iKiller] == 1)
                {
                    
fnColorPrint(iKiller"^3Warning: ^1Freekilling is not allowed. ");
                    
UTIL_ScreenFade(iKiller,{ 25510061 }, 2.02.085);
                }
                if(
g_iFreekill[iKiller] == 2)
                {
                    
UTIL_ScreenFade(iKiller,{ 25510061 }, 2.52.595);
                }
                if(
g_iFreekill[iKiller] == freekill_slay)
                {
                    
fnColorPrint(iKiller"^3Last warning:^1 Every freekill you make form now will result in instant slay");
                    
UTIL_ScreenFade(iKiller,{ 2550}, 2.52.5175);
                }
                if(
g_iFreekill[iKiller] >= max_freekills)
                {
                    
//client_tutor(0, TutorRed, FriendDied, 6.0, "Freekilling is not allowed,^nType rules to see the rules.");
                    
UTIL_ScreenFade(iKiller,{ 2550}, 2.52.5255);
                    
user_kill(iKiller);
                }
            }
        } 
    }
    return 
PLUGIN_HANDLED;


I hope this explains it a lil better

claudiuhks 04-22-2012 08:43

Re: get_user_weapons
 
PHP Code:

const PRIMARY_WEAPONS = ( << CSW_AK47 ) | ( << CSW_M4A1 ) | ( << CSW_FAMAS ) | ( << CSW_GALIL ) | ( << CSW_SCOUT ) | ( << CSW_AWP ) | ( << CSW_M249 ) | ( << CSW_MP5NAVY ) | ( << CSW_P90 ) | ( << CSW_MAC10 ) | ( << CSW_TMP ) | ( << CSW_XM1014 ) | ( << CSW_M3 ) | ( << CSW_G3SG1 ) | ( << CSW_SG550 ) | ( << CSW_SG552 ) | ( << CSW_AUG ) | ( << CSW_UMP45 );

new 
boolg_bHasPrimary33 ];

public 
client_putinserver(id)
  
g_bHasPrimaryid ] = false;

public 
Event_CurWeapon(id)
{
  
// register_event( "CurWeapon", "Event_CurWeapon", "be", "1=1" );

  
g_bHasPrimaryid ] = false;

  static 
iWeapons32 ], iNumiiNum 0;
  
get_user_weaponsidiWeaponsiNum );
  for( 
0iNumi++ )
  {
    if( ( 
<< iWeapons] ) & PRIMARY_WEAPONS )
    {
        
g_bHasPrimaryid ] = true;

        break;
    }
  }
}

public 
Event_DeathMsg() 

    new 
iKiller read_data(1); 
    new 
iVictim read_data(2);
    
    new 
freekill_slay get_pcvar_num(jb_slay_4freekills)
    new 
max_freekills get_pcvar_num(jb_max_freekills);
    new 
szVName[32], szKName[32]; 
    
get_user_name(iVictimszVNamecharsmax(szVName)); 
    
get_user_name(iKillerszKNamecharsmax(szKName));

    
clear_bit(g_bIsAliveiVictim);
    
    if( 
cs_get_user_teamiVictim ) == CS_TEAM_T 
    {  
        if( 
IsPlayeriKiller ) && cs_get_user_teamiKiller ) == CS_TEAM_CT 
        { 
            if( 
g_bRebel[iVictim] ) 
            { 
                
fnColorPrint(0"Guard^4 %s ^1killed rebel^4 %s ^1!"szKNameszVName); 
            }
            else if( !
g_bRebel[iVictim] ) 
            {
                if( 
g_bHasPrimaryiVictim ] ) return PLUGIN_HANDLED;

                
g_iFreekill[iKiller]++
                
                if(
g_iFreekill[iKiller] == 1)
                {
                    
fnColorPrint(iKiller"^3Warning: ^1Freekilling is not allowed. ");
                    
UTIL_ScreenFade(iKiller,{ 25510061 }, 2.02.085);
                }
                if(
g_iFreekill[iKiller] == 2)
                {
                    
UTIL_ScreenFade(iKiller,{ 25510061 }, 2.52.595);
                }
                if(
g_iFreekill[iKiller] == freekill_slay)
                {
                    
fnColorPrint(iKiller"^3Last warning:^1 Every freekill you make form now will result in instant slay");
                    
UTIL_ScreenFade(iKiller,{ 2550}, 2.52.5175);
                }
                if(
g_iFreekill[iKiller] >= max_freekills)
                {
                    
//client_tutor(0, TutorRed, FriendDied, 6.0, "Freekilling is not allowed,^nType rules to see the rules.");
                    
UTIL_ScreenFade(iKiller,{ 2550}, 2.52.5255);
                    
user_kill(iKiller);
                }
            }
        } 
    }
    return 
PLUGIN_HANDLED;



striker07 04-22-2012 11:55

Re: get_user_weapons
 
ah yes very nice, thanks for your help man :up:


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

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