Because it's called in the following moments:
1 - When you get the weapon;
2 - When you switch to another weapon;
3 - When you reload the weapon;
4 - When you use the snipers telescopic sight (scope);
5 - When you shoot the weapon;
6 - And any other case which changes the numeric values of the gun ammunition (clip, backpack ammo)...
Use Ham_Item_Deploy instead, it is called only when the player got the weapon:
PHP Code:
#include <amxmodx>
#include <hamsandwich>
// Exclude the weapons you do not want like the new const below:
// new const EXCLUDE_GUNS = (1<<0 | 1<<4 | 1<<6 | 1<<9 | 1<<25 | 1<<29)
// For a list of valid gun constants, here: https://www.amxmodx.org/api/cstrike_const
// It's at your option to use 'CSW_' or the const number directly.
// We recommend you to not use 'CSW_' directly as in certain cases tested, it's not reliable to retrieve the gun (not this case).
public plugin_init() {
register_plugin("Got_Weapon","1.0","Scripting Help")
// You can specify the weapon by writing it's name, like "weapon_ak47":
// RegisterHam(Ham_Item_Deploy,"weapon_ak47","Make_a_Print",1)
// If you want to register several weapons and exclude certain ones:
new weapon_name[20] // string buffer for storing the weapon name. The returned weapon name will be like the following: weapon_ak47
for(new i = CSW_P228; i <= CSW_P90; i++) { // Starts with the P228 (1) and ends in the P90 (30). It's up to you to change this based in the weapons you want.
if(get_weaponname(i,weapon_name,charsmax(weapon_name))) { // Gets the max characters of the weapon name and stores it in the buffer. Remove 'charsmax(weapon_name)'' and use a number specifying the lenght, if you want.
if(!EXCLUDE_GUNS & (1<<i)) // Ignores the registration of the excluded guns
RegisterHam(Ham_Item_Deploy,weapon_name,"Make_a_Print",1)
}
}
}
public Make_a_Print(ent){
//In order to get the player id, do not use ent, instead:
new id = get_pdata_cbase(ent,41)
//In order to get the weapon id, use:
new weapon = get_pdata_int(ent,43)
if(weapon == certain_weapon)
PRINT(id,"this")
}
__________________