AMXX-BG.INFO stripweapons.inc Raw include

stripweapons.inc

Original include source with line numbers.

Back Download .inc
1 #if defined _stripweapons_included
2 #endinput
3 #endif
4 #define _stripweapons_included
5
6 #include <fakemeta>
7 #include <hamsandwich>
8
9
10
11
12 /*
13 * Strips a player's weapon based on type.
14 *
15 * @param id: Player id
16 * @param type: Weapon type (check enum below for types)
17 * @param bSwitchIfActive: Switch to other weapon before stripping
18 * if stripped weapon is currently deployed
19 * @return: 1 on success, otherwise 0
20 *
21 * Ex: StripWeapons(id, Secondary); // Strips secondary weapon with switching if deployed.
22 * StripWeapons(iPlayer, C4, false); // Strips c4 without switching if deployed.
23 */
24 enum /* Weapon types */
25 {
26 Primary = 1
27 , Secondary
28 , Knife
29 , Grenades
30 , C4
31 };
32
33
34 stock StripWeapons(id, Type, bool: bSwitchIfActive = true)
35 {
36 new iReturn;
37
38 if(is_user_alive(id))
39 {
40 new iEntity, iWeapon;
41 while((iWeapon = GetWeaponFromSlot(id, Type, iEntity)) > 0)
42 iReturn = ham_strip_user_weapon(id, iWeapon, Type, bSwitchIfActive);
43 }
44
45 return iReturn;
46 }
47
48
49 /*
50 * bugsy
51 * http://forums.alliedmods.net/showpost.php?p=1575989&postcount=2
52 *
53 * Gets a weapon entity id based on inventory slot.
54 *
55 * @param id: Player id
56 * @param iSlot: Inventory slot you want to get the weaponid from
57 * @param &iEntity: Weapon entity id
58 * @return: Weapon CSW_* index on success, otherwise 0
59 *
60 * Ex: GetWeaponFromSlot(id, 3, iEntity); // Should return CSW_KNIFE if player has one.
61 * // Knife is always in 3th slot (if not changed with plugin or something);
62 */
63 stock GetWeaponFromSlot( id , iSlot , &iEntity )
64 {
65 if ( !( 1 <= iSlot <= 5 ) )
66 return 0;
67
68 iEntity = 0;
69 const m_rgpPlayerItems_Slot0 = 367;
70 const m_iId = 43;
71 const EXTRAOFFSET_WEAPONS = 4;
72
73 iEntity = get_pdata_cbase( id , m_rgpPlayerItems_Slot0 + iSlot , EXTRAOFFSET_WEAPONS );
74
75 return ( iEntity > 0 ) ? get_pdata_int( iEntity , m_iId , EXTRAOFFSET_WEAPONS ) : 0;
76 }
77
78
79 /*
80 * ConnorMcLeod
81 * http://forums.alliedmods.net/showpost.php?p=1109747&postcount=42
82 *
83 * Strips a player's weapon based on weapon index.
84 *
85 * @param id: Player id
86 * @param iCswId: Weapon CSW_* index
87 * @param iSlot: Inventory slot (Leave 0 if not sure)
88 * @param bSwitchIfActive: Switch weapon if currently deployed
89 * @return: 1 on success, otherwise 0
90 *
91 * Ex: ham_strip_user_weapon(id, CSW_M4A1); // Strips m4a1 if user has one.
92 * ham_strip_user_weapon(id, CSW_HEGRENADE, _, false); // Strips HE grenade if user has one
93 * // without switching weapons.
94 */
95 stock ham_strip_user_weapon(id, iCswId, iSlot = 0, bool:bSwitchIfActive = true)
96 {
97 new iWeapon
98 if( !iSlot )
99 {
100 static const iWeaponsSlots[] = {
101 -1,
102 2, //CSW_P228
103 -1,
104 1, //CSW_SCOUT
105 4, //CSW_HEGRENADE
106 1, //CSW_XM1014
107 5, //CSW_C4
108 1, //CSW_MAC10
109 1, //CSW_AUG
110 4, //CSW_SMOKEGRENADE
111 2, //CSW_ELITE
112 2, //CSW_FIVESEVEN
113 1, //CSW_UMP45
114 1, //CSW_SG550
115 1, //CSW_GALIL
116 1, //CSW_FAMAS
117 2, //CSW_USP
118 2, //CSW_GLOCK18
119 1, //CSW_AWP
120 1, //CSW_MP5NAVY
121 1, //CSW_M249
122 1, //CSW_M3
123 1, //CSW_M4A1
124 1, //CSW_TMP
125 1, //CSW_G3SG1
126 4, //CSW_FLASHBANG
127 2, //CSW_DEAGLE
128 1, //CSW_SG552
129 1, //CSW_AK47
130 3, //CSW_KNIFE
131 1 //CSW_P90
132 }
133 iSlot = iWeaponsSlots[iCswId]
134 }
135
136 const XTRA_OFS_PLAYER = 5
137 const m_rgpPlayerItems_Slot0 = 367
138
139 iWeapon = get_pdata_cbase(id, m_rgpPlayerItems_Slot0 + iSlot, XTRA_OFS_PLAYER)
140
141 const XTRA_OFS_WEAPON = 4
142 const m_pNext = 42
143 const m_iId = 43
144
145 while( iWeapon > 0 )
146 {
147 if( get_pdata_int(iWeapon, m_iId, XTRA_OFS_WEAPON) == iCswId )
148 {
149 break
150 }
151 iWeapon = get_pdata_cbase(iWeapon, m_pNext, XTRA_OFS_WEAPON)
152 }
153
154 if( iWeapon > 0 )
155 {
156 const m_pActiveItem = 373
157 if( bSwitchIfActive && get_pdata_cbase(id, m_pActiveItem, XTRA_OFS_PLAYER) == iWeapon )
158 {
159 ExecuteHamB(Ham_Weapon_RetireWeapon, iWeapon)
160 }
161
162 if( ExecuteHamB(Ham_RemovePlayerItem, id, iWeapon) )
163 {
164 user_has_weapon(id, iCswId, 0)
165 ExecuteHamB(Ham_Item_Kill, iWeapon)
166 return 1
167 }
168 }
169
170 return 0
171 }
172