AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Checking Primary/Secondary Weapons (https://forums.alliedmods.net/showthread.php?t=85186)

Mlk27 02-07-2009 00:45

Checking Primary/Secondary Weapons
 
is there way to check if a weapon belongs to primary or secondary weapons group?

Bugsy 02-07-2009 01:35

Re: Checking Primary/Secondary Weapons
 
Quote:

Originally Posted by Mlk27 (Post 757177)
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;



jim_yang 02-07-2009 01:39

Re: Checking Primary/Secondary Weapons
 
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
 };


Dores 02-07-2009 14:11

Re: Checking Primary/Secondary Weapons
 
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.



cs1.7 04-04-2010 22:39

Re: Checking Primary/Secondary Weapons
 
wow..very nice! :D

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))) 


Arkshine 04-05-2010 05:59

Re: Checking Primary/Secondary Weapons
 
http://www.amxmodx.org/funcwiki.php?go=func&id=733

ConnorMcLeod 04-05-2010 06:38

Re: Checking Primary/Secondary Weapons
 
Ways by Dores are always wrong :mrgreen:

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



cs1.7 04-05-2010 07:01

Re: Checking Primary/Secondary Weapons
 
@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.



Bugsy 04-05-2010 09:02

Re: Checking Primary/Secondary Weapons
 
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) : );



cs1.7 04-05-2010 09:23

Re: Checking Primary/Secondary Weapons
 
wow thanks! :)

and it works now! :D


edit:


do you maybe know a better way to realize pistol autofire?


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

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