Raised This Month: $32 Target: $400
 8% 

[INC] Weapon Slots Stocks 1.0a


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
soccdoodcss
Veteran Member
Join Date: Nov 2006
Location: Wisconsin
Old 12-30-2007 , 14:54   [INC] Weapon Slots Stocks 1.0a
Reply With Quote #1

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.

PHP Code:
Stockweap_slot[weap// returns what slot the specified weapon belongs to
num_slot(idslot// returns number of weapons in that slot
set_slot(idslot// forces the player to take out a weapon in the specified slot 
Notes:
1) the "weap" parameters should be in the CSW_ format.
Attached Files
File Type: inc weap_slots.inc (1.4 KB, 500 views)
__________________
"Now safe beneath their wisdom and their feet.
Here I will teach you truly how to sleep."

Last edited by soccdoodcss; 01-02-2008 at 12:07. Reason: 1.0a
soccdoodcss is offline
Send a message via AIM to soccdoodcss
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 12-30-2007 , 17:12   Re: Weapon Slots Stocks
Reply With Quote #2

I prefer mine:
Code:
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)
Code:
#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)

Last edited by Emp`; 12-30-2007 at 17:23.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
soccdoodcss
Veteran Member
Join Date: Nov 2006
Location: Wisconsin
Old 12-30-2007 , 17:44   Re: Weapon Slots Stocks
Reply With Quote #3

Wow, I like it Emp`. I'll have to take a closer look. :]
__________________
"Now safe beneath their wisdom and their feet.
Here I will teach you truly how to sleep."
soccdoodcss is offline
Send a message via AIM to soccdoodcss
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 12-30-2007 , 18:02   Re: Weapon Slots Stocks
Reply With Quote #4

oh, and also:
Code:
#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)
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
soccdoodcss
Veteran Member
Join Date: Nov 2006
Location: Wisconsin
Old 12-30-2007 , 18:32   Re: Weapon Slots Stocks
Reply With Quote #5

Thanks for the advice. Fixed mine up.
__________________
"Now safe beneath their wisdom and their feet.
Here I will teach you truly how to sleep."
soccdoodcss is offline
Send a message via AIM to soccdoodcss
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 20:29.


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