Not for clip ammo. You need to use Mod Specific natives. Like for cs you would use cs_set_weapon_ammo and you have to find the Weapon Entity Index for the player you want to set the ammo too. Since ammo clip is on the Weapon Entity Index Private Data.
Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <cstrike>
#define SLOT_PRIMARY 1
#define SLOT_SECONDARY 2
#define SLOT_KNIFE 3
#define SLOT_GRENADE 4
#define SLOT_C4 5
// Weapon CSW_*
new PrimarySlot[33];
new PrimaryWeapIndex[33];
new SecondarySlot[33];
new SecondaryWeapIndex[33];
//----------------------------------------------------------------------------------------------
#define sh_getMaxBPAmmo(%1) _sh_getMaxBPAmmo[%1]
stock _sh_getMaxBPAmmo[] = {
0,
52, //CSW_P228
0,
90, //CSW_SCOUT
1, //CSW_HEGRENADE
32, //CSW_XM1014
1, //CSW_C4
100,//CSW_MAC10
90, //CSW_AUG
1, //CSW_SMOKEGRENADE
120,//CSW_ELITE
100,//CSW_FIVESEVEN
100,//CSW_UMP45
90, //CSW_SG550
90, //CSW_GALIL
90, //CSW_FAMAS
100,//CSW_USP
120,//CSW_GLOCK18
30, //CSW_AWP
120,//CSW_MP5NAVY
200,//CSW_M249
32, //CSW_M3
90, //CSW_M4A1
120,//CSW_TMP
90, //CSW_G3SG1
2, //CSW_FLASHBANG
35, //CSW_DEAGLE
90, //CSW_SG552
90, //CSW_AK47
0, //CSW_KNIFE
100 //CSW_P90
}
#define sh_getMaxClipAmmo(%1) _sh_getMaxClipAmmo[%1]
stock _sh_getMaxClipAmmo[] = {
0,
13, //CSW_P228
0,
10, //CSW_SCOUT
0, //CSW_HEGRENADE
7, //CSW_XM1014
0, //CSW_C4
30,//CSW_MAC10
30, //CSW_AUG
0, //CSW_SMOKEGRENADE
15,//CSW_ELITE
20,//CSW_FIVESEVEN
25,//CSW_UMP45
30, //CSW_SG550
35, //CSW_GALIL
25, //CSW_FAMAS
12,//CSW_USP
20,//CSW_GLOCK18
10, //CSW_AWP
30,//CSW_MP5NAVY
100,//CSW_M249
8, //CSW_M3
30, //CSW_M4A1
30,//CSW_TMP
20, //CSW_G3SG1
0, //CSW_FLASHBANG
7, //CSW_DEAGLE
30, //CSW_SG552
30, //CSW_AK47
0, //CSW_KNIFE
50//CSW_P90
}
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
};
stock g_WeapNames[31][] =
{
"",
"weapon_p228",//CSW_P228
"",
"weapon_scout", //CSW_SCOUT
"", //CSW_HEGRENADE
"weapon_xm1014", //CSW_XM1014
"", //CSW_C4
"weapon_mac10", //CSW_MAC10
"weapon_aug", //CSW_AUG
"", //CSW_SMOKEGRENADE
"weapon_elite",//CSW_ELITE
"weapon_fiveseven",//CSW_FIVESEVEN
"weapon_ump45", //CSW_UMP45
"weapon_sg550", //CSW_SG550
"weapon_galil", //CSW_GALIL
"weapon_famas", //CSW_FAMAS
"weapon_usp",//CSW_USP
"weapon_glock18",//CSW_GLOCK18
"weapon_awp", //CSW_AWP
"weapon_mp5navy", //CSW_MP5NAVY
"weapon_m249", //CSW_M249
"weapon_m3", //CSW_M3
"weapon_m4a1", //CSW_M4A1
"weapon_tmp", //CSW_TMP
"weapon_g3sg1", //CSW_G3SG1
"", //CSW_FLASHBANG
"weapon_deagle",//CSW_DEAGLE
"weapon_sg552", //CSW_SG552
"weapon_ak47", //CSW_AK47
"", //CSW_KNIFE
"weapon_p90" //CSW_P90
}
public plugin_init()
{
register_event("CurWeapon", "hook_CurWeapon", "be", "1=1")
}
public hook_CurWeapon(id)
{
new wp = read_data(2);
// Check if weapon is different from the stored slot when ammo is 2.
// Weapon should reload when the ammo clip is 1.
if(read_data(3) > 3)
return;
new Slot = g_WeaponSlots[wp];
if(Slot == SLOT_PRIMARY || Slot == SLOT_SECONDARY)
{
if(PrimarySlot[id] != wp || SecondarySlot[id] != wp)
{
new index;
switch(Slot)
{
case SLOT_PRIMARY:
{
index = find_weapon_index_by_name(id, g_WeapNames[wp])
if(index)
{
PrimarySlot[id] = wp;
PrimaryWeapIndex[id] = index;
}
}
case SLOT_SECONDARY:
{
index = find_weapon_index_by_name(id, g_WeapNames[wp]) // Find Weapon Index
if(index)
{
SecondarySlot[id] = wp;
SecondaryWeapIndex[id] = index;
}
}
}
} else {
cs_set_weapon_ammo((Slot == SLOT_PRIMARY) ? PrimaryWeapIndex[id] : SecondaryWeapIndex[id], _sh_getMaxClipAmmo[wp]) // Reload Clip Ammo
}
}
}
// Using Find entity in sphere might be better here..
stock find_weapon_index_by_name(id, const WeaponName[])
{
new Index = -1
while ((Index = engfunc(EngFunc_FindEntityByString, Index, "classname", WeaponName)) != 0)
{
if(id == pev(Index, pev_owner))
{
return Index
}
}
return 0;
}