PDA

View Full Version : [INC] Weapon Slots Stocks 1.0a


soccdoodcss
12-30-2007, 14:54
Allows you to easily figure out what slot a weapon belongs to, how many weapons a player has in a slot, and forces a player to use a specific weapon type(by slot number).


Changelog:
1.0a: set_slot now works with bots


Thanks to Emp` for some tips and helpful code.

Stock: weap_slot[weap] // returns what slot the specified weapon belongs to
num_slot(id, slot) // returns number of weapons in that slot
set_slot(id, slot) // forces the player to take out a weapon in the specified slot
Notes:
1) the "weap" parameters should be in the CSW_ format.

Emp`
12-30-2007, 17:12
I prefer mine:

weap_primary(weap) //whether a weapon is primary or not
weap_secondary(weap)
weap_knife(weap)
weap_grenade(weap)
weap_c4(weap)

is_weapon_slot(weap, slot) //if a weapon corresponds to this slot

has_weapon_slot(id, slot, gun_num=0) //if user has a weapon for slot
// gun_num represents how many weapons in that slot -1
// if user has 3 weapons for slot 2, then
// has_weapon_slot(id, 2, 0) == true
// has_weapon_slot(id, 2, 1) == true
// has_weapon_slot(id, 2, 2) == true
// has_weapon_slot(id, 2, 3) == false

set_active_slot(id, slot) //changes players weapon to one belonging in slot

set_primary_active(id) //changes players weapon to their first primary
set_secondary_active(id)
set_knife_active(id)
set_grenade_active(id)
set_c4_active(id)




#if !defined MAX_PLAYERS
#define MAX_PLAYERS 32
#endif

#if !defined MAX_WEAPONS
#define MAX_WEAPONS 31
#endif

#if defined _csdm_included
#define MAX_SLOT 6
#else
enum
{
SLOT_PRIMARY = 1,
SLOT_SECONDARY,
SLOT_KNIFE,
SLOT_GRENADE,
SLOT_C4,
MAX_SLOT
}

//Weapon slot lookup table
stock g_WeaponSlots[MAX_WEAPONS] = {
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
};
#endif

stock PLAYER_WEAPONS[MAX_PLAYERS+1][MAX_SLOT][MAX_WEAPONS];
stock PLAYER_WEAPONNUM[MAX_PLAYERS+1][MAX_SLOT];

#define weap_primary(%1) (g_WeaponSlots[%1]==SLOT_PRIMARY)
#define weap_secondary(%1) (g_WeaponSlots[%1]==SLOT_SECONDARY)
#define weap_knife(%1) (g_WeaponSlots[%1]==SLOT_KNIFE)
#define weap_grenade(%1) (g_WeaponSlots[%1]==SLOT_GRENADE)
#define weap_c4(%1) (g_WeaponSlots[%1]==SLOT_C4)

#define is_weapon_slot(%1,%2) (g_WeaponSlots[%1]==%2)

stock has_weapon_slot(id, slot, gun_num=0)
{
update_weapon_slots(id);
return (PLAYER_WEAPONS[id][slot][gun_num]);
}

stock update_weapon_slots(id){
static weapons[MAX_WEAPONS], weapon_num, weap, x, i;
get_user_weapons(id, weapons, weapon_num);

for( i=0; i<MAX_SLOT; i++)
PLAYER_WEAPONNUM[id][i] = 0;
for( x = 0; x < weapon_num; x++ )
{
weap = weapons[x];
for( i=0; i<MAX_SLOT; i++)
if(is_weapon_slot(weap, i))
PLAYER_WEAPON[id][i][PLAYER_WEAPONNUM[id][i]++] = weap;
}
}

stock set_active_slot(id, slot)
{
if( has_weapon_slot(id, slot) )
{
new weapon[33];
get_weaponname( PLAYER_WEAPONS[id][slot][0], weapon, 32);
client_cmd(id, weapon);
}
}
#define set_primary_active(%1) set_active_slot(%1,SLOT_PRIMARY)
#define set_secondary_active(%1) set_active_slot(%1,SLOT_SECONDARY)
#define set_knife_active(%1) set_active_slot(%1,SLOT_KNIFE)
#define set_grenade_active(%1) set_active_slot(%1,SLOT_GRENADE)
#define set_c4_active(%1) set_active_slot(%1,SLOT_C4)

soccdoodcss
12-30-2007, 17:44
Wow, I like it Emp`. I'll have to take a closer look. :]

Emp`
12-30-2007, 18:02
oh, and also:#define has_primary(%1) has_weapon_slot(%1,SLOT_PRIMARY)
#define has_secondary(%1) has_weapon_slot(%1,SLOT_SECONDARY)
#define has_knife(%1) has_weapon_slot(%1,SLOT_KNIFE)
#define has_grenade(%1) has_weapon_slot(%1,SLOT_GRENADE)
#define has_c4(%1) has_weapon_slot(%1,SLOT_C4):wink:

soccdoodcss
12-30-2007, 18:32
Thanks for the advice. Fixed mine up.