Raised This Month: $ Target: $400
 0% 

Checking Primary/Secondary Weapons


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mlk27
Veteran Member
Join Date: May 2008
Old 02-07-2009 , 00:45   Checking Primary/Secondary Weapons
Reply With Quote #1

is there way to check if a weapon belongs to primary or secondary weapons group?
Mlk27 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-07-2009 , 01:35   Re: Checking Primary/Secondary Weapons
Reply With Quote #2

Quote:
Originally Posted by Mlk27 View Post
is there way to check if a weapon belongs to primary or secondary weapons group?
There may be a better way but here's what I do:

PHP Code:
public WeaponGroup(iWeapID)
{
    
//primary returns 1, secondary returns 2
    
switch (iWeapID)
    {
        case 
CSW_SCOUT,CSW_XM1014,CSW_MAC10CSW_AUGCSW_UMP45,CSW_SG550,CSW_GALIL,CSW_FAMAS,CSW_AWP,CSW_MP5NAVY,CSW_M249,CSW_M3CSW_M4A1,CSW_TMP,CSW_G3SG1,CSW_SG552,CSW_AK47,CSW_P90: return 1;
        case 
CSW_P228CSW_ELITECSW_FIVESEVENCSW_USPCSW_GLOCK18CSW_DEAGLE: return 2;
    }
    
    return 
0;

__________________

Last edited by Bugsy; 02-07-2009 at 01:45.
Bugsy is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 02-07-2009 , 01:39   Re: Checking Primary/Secondary Weapons
Reply With Quote #3

paste from csdm.inc
Code:
//Weapon slot lookup table
stock g_WeaponSlots[] = {
  0,
  2, //CSW_P228
  0,
  1, //CSW_SCOUT
  4, //CSW_HEGRENADE
  1, //CSW_XM1014
  5, //CSW_C4
  1, //CSW_MAC10
  1, //CSW_AUG
  4, //CSW_SMOKEGRENADE
  2, //CSW_ELITE
  2, //CSW_FIVESEVEN
  1, //CSW_UMP45
  1, //CSW_SG550
  1, //CSW_GALIL
  1, //CSW_FAMAS
  2, //CSW_USP
  2, //CSW_GLOCK18
  1, //CSW_AWP
  1, //CSW_MP5NAVY
  1, //CSW_M249
  1, //CSW_M3
  1, //CSW_M4A1
  1, //CSW_TMP
  1, //CSW_G3SG1
  4, //CSW_FLASHBANG
  2, //CSW_DEAGLE
  1, //CSW_SG552
  1, //CSW_AK47
  3, //CSW_KNIFE
  1 //CSW_P90
 };
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 02-07-2009 , 14:11   Re: Checking Primary/Secondary Weapons
Reply With Quote #4

Try this:

PHP Code:
#include <amxmodx>

#define SECONDARY_WEAPONS_BITSUM    ((1<<CSW_DEAGLE) | (1<<CSW_ELITE) | (1<<CSW_FIVESEVEN) | (1<<CSW_GLOCK18) | (1<<CSW_USP) | (1<<CSW_P228))
#define GRENADES_BITSUM    ((1<<CSW_HEGRENADE) | (1<<CSW_SMOKEGRENADE) | (1<<CSW_FLASHBANG) | (1<<CSW_C4))

enum
{
    
IS_PRIMARY,
    
IS_SECONDARY
}

bool:CheckWeaponType(weaponIDtype IS_PRIMARY)
{
    if(!(
GRENADES_BITSUM & (1<<weaponID)))
    {
        if(
type == IS_PRIMARY ? !(SECONDARY_WEAPONS_BITSUM & (1<<weaponID)) : (SECONDARY_WEAPONS_BITSUM & (1<<weaponID)))
        {
            return 
true;
        }
    }
    
    return 
false;

Usage:
PHP Code:
if(CheckWeaponType(get_user_weapon(id), IS_SECONDARY))
{
    
// player's weapon is secondary.

__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ
Dores is offline
cs1.7
Senior Member
Join Date: Oct 2008
Old 04-04-2010 , 22:39   Re: Checking Primary/Secondary Weapons
Reply With Quote #5

wow..very nice!

which way is the best. The way by Dores?

And i also wonder if there is really no built in function somewhere to check if user has primary or secondary.


edit


i get a "tag missmatch" at this line:

PHP Code:
if(type == IS_PRIMARY ? !(SECONDARY_WEAPONS_BITSUM & (1<<weaponID)) : (SECONDARY_WEAPONS_BITSUM & (1<<weaponID))) 
__________________
_____________
/_____\
[° ||| °]
./..............\▓

Last edited by cs1.7; 04-04-2010 at 23:51.
cs1.7 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-05-2010 , 05:59   Re: Checking Primary/Secondary Weapons
Reply With Quote #6

http://www.amxmodx.org/funcwiki.php?go=func&id=733
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-05-2010 , 06:38   Re: Checking Primary/Secondary Weapons
Reply With Quote #7

Ways by Dores are always wrong

PHP Code:
#define XTRA_OFS_PLAYER    5
#define m_pActiveItem    373

Get_User_Weapon_ItemSlot(id)
{
    new 
iActiveItem get_pdata_cbase(idm_pActiveItemXTRA_OFS_PLAYER)
    if( 
iActiveItem )
    {
        return 
ExecuteHam(Ham_Item_ItemSlotiActiveItem)
    }
    return 
0

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
cs1.7
Senior Member
Join Date: Oct 2008
Old 04-05-2010 , 07:01   Re: Checking Primary/Secondary Weapons
Reply With Quote #8

@Arkshine

very nice,

but as i tested, i found out the function checks if the player posesses a primary (not if he has switched to a primary). That means it returns 1 if player has a M4 in inventory..although he is holding a deagle. It checks if player carries only primary. Very interesting function ...


@ConnorMcLeod

As i see your code checks for weapon slots. Very smart, man! Can you show an example how to use it.


__________________
_____________
/_____\
[° ||| °]
./..............\▓

Last edited by cs1.7; 04-05-2010 at 10:20.
cs1.7 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-05-2010 , 09:02   Re: Checking Primary/Secondary Weapons
Reply With Quote #9

The function returns the slot # for the weapon he is currently holding.

Examples:
1. User holding AWP (or any primary weapon), Get_User_Weapon_ItemSlot( id ) returns 1
2. User holding Glock (or any pistol), Get_User_Weapon_ItemSlot( id ) returns 2
3. User holding Knife, Get_User_Weapon_ItemSlot( id ) returns 3
4. User holding Nade, Get_User_Weapon_ItemSlot( id ) returns 4
PHP Code:
#define XTRA_OFS_PLAYER    5
#define m_pActiveItem    373

Get_User_Weapon_ItemSlot(id)
{
    new 
iActiveItem get_pdata_cbase(idm_pActiveItemXTRA_OFS_PLAYER)
    
    return ( ( 
iActiveItem ) ? ExecuteHam(Ham_Item_ItemSlotiActiveItem) : );

__________________
Bugsy is offline
cs1.7
Senior Member
Join Date: Oct 2008
Old 04-05-2010 , 09:23   Re: Checking Primary/Secondary Weapons
Reply With Quote #10

wow thanks!

and it works now!


edit:


do you maybe know a better way to realize pistol autofire?
__________________
_____________
/_____\
[° ||| °]
./..............\▓

Last edited by cs1.7; 04-05-2010 at 10:21.
cs1.7 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:37.


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