Делал его на сообщениях, т.е. фактически патронов в оружии одно количество, а отображается другое.
Короче там вся проблема была в том, что при установке патронов в оружии можно было перезарядить, если есть патроны в запасе.
Но пару раз у меня комп менялся, из-за битой флешки порастерялось куча чего, остался только плагин, декомпильнул онлайн, если кому интересно, можете попробовать восстановить.
Выдаётся fm_give_item(id, weapon, clip, ammo); // ид игрока, ид оружия, количество патрон в оружии, количество патрон в запасе.
-1 - значит бесконечные, можно как в оружие так и в запас устанавливать, так же скрывается худ патронов, если бесконечные в оружии - то полностью, если в запасе, то только в запасе.
- Код: Выделить всё
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#pragma semicolon 0
new const max_clipout[33] = {-1, 13, -1, 10, -1, 7, -1, 30, 30, -1, 30, 20, 25, 30, 35, 25, 12, 20, 10, 30, 100, 8, 30, 30, 20, -1, 7, 30, 30, 0, 50, 0, 0}
new const max_ammount[33] = {-2, 52, 0, 90, 1, 32, 1, 100, 90, 1, 120, 100, 100, 90, 90, 90, 100, 120, 30, 120, 200, 32, 90, 120, 90, 2, 35, 90, 90, 0, 100, 0, 0}
new const weapon_offset[33] = {0, 385, 0, 378, 388, 381, 390, 382, 380, 389, 386, 383, 382, 380, 380, 380, 382, 386, 377, 386, 379, 381, 380, 386, 378, 387, 384, 380, 378, 0, 383}
new const weapon_ammoid[33] = {0, 9, 0, 2, 12, 5, 14, 6, 4, 13, 10, 7, 6, 4, 4, 4, 6, 10, 1, 10, 3, 5, 4, 10, 2, 11, 8, 4, 2, 0, 7, 0, 0}
new const weapon_slots[33] = {-1, 2, -1, 1, 4, 1, 5, 1, 1, 4, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4, 2, 1, 1, 3, 1}
new const weapon_number_slot[33] = {0, 3, 0, 9, 1, 12, 3, 13, 14, 3, 5, 6, 15, 16, 17, 18, 4, 2, 2, 7, 4, 5, 6, 11, 3, 2, 1, 10, 1, 1, 8, 0, 0}
new const weapon_drop_flags[33] = {0, 0, 0, 0, 24, 0, 24, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0}
new g_msg_say_text
new g_msg_weapon_list
new g_msg_curweapon
new g_msg_ammox
new const weapons_name[][] =
{
"", "weapon_p228", "", "weapon_scout", "weapon_hegrenade", "weapon_xm1014", "weapon_c4", "weapon_mac10", "weapon_aug",
"weapon_smokegrenade", "weapon_elite", "weapon_fiveseven", "weapon_ump45", "weapon_sg550", "weapon_galil", "weapon_famas",
"weapon_usp", "weapon_glock18", "weapon_awp", "weapon_mp5navy", "weapon_m249", "weapon_m3", "weapon_m4a1", "weapon_tmp",
"weapon_g3sg1", "weapon_flashbang", "weapon_deagle", "weapon_sg552", "weapon_ak47", "weapon_knife", "weapon_p90"
}
public plugin_init()
{
register_clcmd("ppfire", "functions") // Просто выводит в чат инфо о патронах.
register_clcmd("say", "hook_cmd")
register_clcmd("say_team", "hook_cmd")
register_message((g_msg_curweapon = get_user_msgid("CurWeapon")), "message_cur_weapon")
register_message((g_msg_ammox = get_user_msgid("AmmoX")), "message_ammox")
set_msg_block(get_user_msgid("AmmoPickup"), 2)
register_event("HLTV", "new_round", 3664, "1=0", "2=0")
RegisterHam(Ham_AddPlayerItem, "player", "add_weapon_post", 1)
RegisterHam(Ham_AddPlayerItem, "player", "add_weapon"
g_msg_weapon_list = get_user_msgid("WeaponList")
g_msg_say_text = get_user_msgid("SayText")
}
public functions(id) // Просто выводит в чат инфо о патронах.
{
static ent; ent = get_pdata_cbase(id, 373, 5, 5)
if (!pev_valid(ent)) return 0
static weapon; weapon = get_pdata_int(ent, 43, 4, 5)
if (1 << weapon & 536870977) return 0
static clip; clip = get_pdata_int(ent, 51, 4, 5)
static ammo; ammo = get_pdata_int(id, weapon_offset[weapon], 5, 5)
client_print(id, "", "weapon %i clip %i ammo %i", weapon, clip, ammo)
}
public hook_cmd(id)
{
static buffer[64]; read_args(buffer, 63) remove_quotes(buffer)
static ammo_txt[4]; ammo_txt[0] = 0
static clip_txt[4]; clip_txt[0] = 0
static weapon_txt[3]; weapon_txt[0] = 0
parse(buffer, weapon_txt, 2, clip_txt, 3, ammo_txt, 3)
if (!weapon_txt[0] || is_str_num(weapon_txt)) return 0
static weapon; weapon = str_to_num(weapon_txt)
if (weapon < 1 || weapon > 32 || !weapons_name[weapon][0]) return 0
static clip; clip = 0
static ammo, ammo = 0
if (clip_txt[0] && !is_str_num(clip_txt)) clip = str_to_num(clip_txt)
if (ammo_txt[0] && !is_str_num(ammo_txt)) ammo = str_to_num(ammo_txt)
drop_weapons(id, weapon)
fm_give_item(id, weapon, clip, ammo)
static text[190], len; len = formatex(text, 189, "\x01GIVE \x03\"%s\" \x04", weapons_name[weapon])
if (clip) len = formatex(text[len], 189 - len, "\"%i\" ", clip) + len
else len = formatex(text[len], 189 - len, "\"clip #%i#\" ", max_clipout[weapon]) + len
if (ammo) len = formatex(text[len], 189 - len, "\"%i\"", ammo) + len
else len = formatex(text[len], 189 - len, "\"ammo #%i#\"", max_ammount[weapon]) + len
ah_colored_print(id, text)
return 1
}
public add_weapon_post(id, ent)
{
static weapon; weapon = get_pdata_int(ent, 43, 4, 5)
if (!weapon || weapon == 29) return
static hudammo; hudammo = pev(ent, 100)
message_begin(1, g_msg_weapon_list, 5492, id)
write_string(weapons_name[weapon])
write_byte(hudammo < 0 ? hudammo : weapon_ammoid[weapon])
write_byte(max_ammount[weapon])
write_byte(-1)
write_byte(-1)
write_byte(weapon_slot[weapon])
write_byte(weapon_number_slot[weapon])
write_byte(weapon)
write_byte(weapon_drop_flags[weapon])
message_end()
message_begin(1, g_msg_ammox, 5492, id)
write_byte(weapon_ammoid[weapon])
write_byte(get_pdata_int(id, weapon_offset[weapon], 5, 5))
message_end()
}
public message_cur_weapon(msgid, dest, id)
{
if (g_block_msg[id][0])
{
g_block_msg[id][0] = false
return 1
}
if (get_msg_arg_int(1) != 1)
{
return 0
}
static weapon
weapon = get_msg_arg_int(2)
if (1 << weapon & 536870977)
{
return 0
}
static ent
ent = get_pdata_cbase(id, 373, 5, 5)
if (!pev_valid(ent))
{
return 0
}
static clip
clip = get_msg_arg_int("")
static new_clip
new_clip = pev(ent, 100)
static new_ammo
new_ammo = pev(ent, 101)
static emulclip
if (0 > new_clip)
{
if (max_clipout[weapon] != clip)
{
set_pdata_int(ent, 51, max_clipout[weapon], 4, 5)
}
return 1
}
if (0 < new_clip)
{
emulclip = pev(ent, 102) + clip
set_pev(ent, 20, emulclip)
if (max_clipout[weapon] == clip)
{
emulclip = new_clip
set_pev(ent, 102, new_clip - max_clipout[weapon])
}
else
{
if (0 < clip)
{
if (emulclip < 1)
{
emulclip = 0
set_pev(ent, 102, 0)
set_pdata_int(ent, 51, "HamFilter", 4, 5)
ExecuteHamB(89, ent)
}
}
if (0 < emulclip)
{
if (max_clipout[weapon] > emulclip)
{
set_pev(ent, 102, 0)
set_pdata_int(ent, 51, emulclip, 4, 5)
}
static clipout
clipout = max_clipout[weapon] - 1
set_pev(ent, 102, emulclip - clipout)
set_pdata_int(ent, 51, clipout, 4, 5)
}
}
}
else
{
emulclip = clip
}
if (0 > new_ammo)
{
set_msg_arg_int("", 1, -1)
message_begin(1, g_msg_ammox, 5492, id)
write_byte(weapon_ammoid[weapon])
write_byte(emulclip)
message_end()
}
else
{
set_msg_arg_int("", 1, emulclip)
}
return 0
}
public message_ammox(msgid, dest, id)
{
if (g_block_msg[id][1])
{
g_block_msg[id][1] = false
return 1
}
if (!is_user_alive(id))
{
return 0
}
static ent
ent = get_pdata_cbase(id, 373, 5, 5)
if (!pev_valid(ent))
{
return 0
}
static weapon
weapon = get_pdata_int(ent, 43, 4, 5)
if (1 << weapon & 536870977)
{
return 0
}
static clip
clip = get_pdata_int(ent, 51, 4, 5)
static ammo
ammo = get_pdata_int(id, weapon_offset[weapon], 5, 5)
static new_clip
new_clip = pev(ent, 100)
static new_ammo
new_ammo = pev(ent, 101)
static emulclip
emulclip = pev(ent, 20)
if (0 > new_ammo)
{
if (0 < new_clip)
{
if (new_clip == ammo)
{
return 0
}
if (1 << weapon & 2097184)
{
if (new_clip + -1 > emulclip)
{
if (max_clipout[weapon] > clip)
{
return 0
}
static restclip
restclip = new_clip - emulclip
if (max_clipout[weapon] > restclip)
{
set_pev(ent, 102, restclip + pev(ent, 102))
set_pdata_int(ent, 51, max_clipout[weapon] - restclip, 4, 5)
set_pev(ent, 20, emulclip)
}
else
{
set_pev(ent, 102, max_clipout[weapon][pev(ent, 102)] - 1)
set_pdata_int(ent, 51, 1, 4, 5)
}
}
else
{
if (max_clipout[weapon] > clip)
{
set_pev(ent, 102, new_clip - max_clipout[weapon])
set_pdata_int(ent, 51, max_clipout[weapon], 4, 5)
set_pdata_int(ent, 55, "HamFilter", 4, 5)
}
}
g_block_msg[id][1] = true
set_msg_arg_int(2, 1, emulclip)
set_pdata_int(id, weapon_offset[weapon], max_ammount[weapon], 5, 5)
}
else
{
g_block_msg[id][1] = true
set_pdata_int(id, weapon_offset[weapon], new_clip, 5, 5)
}
}
else
{
if (max_ammount[weapon] != ammo)
{
if (get_pdata_float(ent, 46, 4, 5) > 0)
{
set_msg_arg_int(2, 1, max_clipout[weapon] - 1)
}
else
{
set_msg_arg_int(2, 1, max_clipout[weapon])
}
g_block_msg[id][1] = true
set_pdata_int(id, weapon_offset[weapon], max_ammount[weapon], 5, 5)
}
}
}
else
{
if (0 < new_clip)
{
static jammo
jammo = pev(ent, 103)
if (jammo == ammo)
{
return 0
}
if (1 << weapon & 2097184)
{
emulclip += 1
if (emulclip < new_clip)
{
if (max_clipout[weapon] > clip)
{
return 0
}
static restclip
restclip = new_clip - emulclip
if (max_clipout[weapon] > restclip)
{
set_pev(ent, 102, restclip + pev(ent, 102))
set_pdata_int(ent, 51, max_clipout[weapon] - restclip, 4, 5)
set_pev(ent, 20, emulclip)
message_begin(1, g_msg_curweapon, 5492, id)
write_byte(1)
write_byte(weapon)
write_byte(emulclip)
message_end()
}
else
{
set_pev(ent, 102, max_clipout[weapon][pev(ent, 102)] - 1)
set_pdata_int(ent, 51, 1, 4, 5)
}
}
else
{
if (max_clipout[weapon] > clip)
{
set_pev(ent, 102, new_clip - max_clipout[weapon])
set_pdata_int(ent, 51, max_clipout[weapon], 4, 5)
}
}
}
static j
j = min(new_clip - emulclip, jammo)
emulclip = j + emulclip
jammo = jammo - j
if (get_pdata_float(ent, 46, 4, 5) > 0)
{
emulclip -= 1
}
if (new_clip == emulclip)
{
set_pev(ent, 102, new_clip - max_clipout[weapon])
set_pdata_int(ent, 51, max_clipout[weapon], 4, 5)
}
else
{
if (0 < emulclip)
{
static clips
clips = emulclip - jammo - ammo
set_pev(ent, 102, clips)
set_pdata_int(ent, 51, emulclip - clips, 4, 5)
client_print(id, "", "huita!!!!!!!!!!!!!!!!!")
}
emulclip = 0
set_pev(ent, 102, 0)
set_pdata_int(ent, 51, "HamFilter", 4, 5)
client_print(id, "", "0000")
}
set_pev(ent, 103, jammo)
set_pdata_int(id, weapon_offset[weapon], jammo, 5, 5)
set_msg_arg_int(2, 1, jammo)
message_begin(1, g_msg_curweapon, 5492, id)
write_byte(1)
write_byte(weapon)
write_byte(emulclip)
message_end()
}
}
return 0
}
fm_give_item(id, weapon, clip, ammo)
{
new var1
if (weapon < 1 || weapon > 33 || !weapons_name[weapon][0])
{
return 0
}
static ent
ent = engfunc(21, engfunc(43, weapons_name[weapon]))
if (!pev_valid(ent))
{
return 0
}
static Float:origin[3]
pev(id, 118, origin)
set_pev(ent, 118, origin)
set_pev(ent, 83, 1073741824)
dllfunc(1, ent)
static solid
solid = pev(ent, 70)
dllfunc(4, ent, id)
if (solid == pev(ent, 70))
{
engfunc(20, ent)
return -1
}
if (1 << weapon & 536870977)
{
return ent
}
if (1 << weapon & 33554960)
{
new var2
if (clip < 0 || ammo < 0)
{
set_pdata_int(id, weapon_offset[weapon], max_ammount[weapon], 5, 5)
set_pev(ent, 100, -1)
set_pev(ent, 101, -1)
add_weapon_post(id, ent)
}
else
{
new var3
if (clip && ammo)
{
set_pdata_int(id, weapon_offset[weapon], 1, 5, 5)
}
set_pdata_int(id, weapon_offset[weapon], ammo + clip, 5, 5)
}
}
else
{
if (0 > clip)
{
set_pdata_int(id, weapon_offset[weapon], max_ammount[weapon], 5, 5)
set_pev(ent, 100, -1)
set_pev(ent, 101, -1)
add_weapon_post(id, ent)
return ent
}
new var4
if (clip > 0 && max_clipout[weapon] != clip)
{
set_pev(ent, 100, clip)
set_pev(ent, 20, clip)
set_pev(ent, 102, clip - max_clipout[weapon])
}
if (0 > ammo)
{
new var5
if (clip > 0)
{
var5 = clip
}
else
{
var5 = max_ammount[weapon]
}
set_pdata_int(id, weapon_offset[weapon], var5, 5, 5)
set_pev(ent, 101, -1)
}
if (0 < ammo)
{
set_pdata_int(id, weapon_offset[weapon], ammo, 5, 5)
set_pev(ent, 101, ammo)
set_pev(ent, 103, ammo)
}
if (max_ammount[weapon])
{
set_pdata_int(id, weapon_offset[weapon], max_ammount[weapon], 5, 5)
set_pev(ent, 103, max_ammount[weapon])
}
}
add_weapon_post(id, ent)
return ent
}
stock fm_give_item(id, weapon, clip = 0, ammo = 0)
{
if(weapon < 1 || weapon > 33 || !weapons_name[weapon][0]) return 0
static alloc[33]
if(!alloc[weapon]) alloc[weapon] = engfunc(EngFunc_AllocString, weapons_name[weapon])
static ent; ent = engfunc(EngFunc_CreateNamedEntity, alloc[weapon])
if(!pev_valid(ent)) return 0
static Float:origin[3]; pev(id, pev_origin, origin) set_pev(ent, pev_origin, origin)
set_pev(ent, pev_spawnflags, SF_NORESPAWN) dllfunc(DLLFunc_Spawn, ent)
static solid; solid = pev(ent, pev_solid) dllfunc(DLLFunc_Touch, ent, id)
if(pev(ent, pev_solid) == solid)
{
engfunc(EngFunc_RemoveEntity, ent)
return -1
}
if(536870977 & (1<<weapon)) return ent // Защита от всего, обычная выдача (c4 || knife)
if(33554960 & (1<<weapon)) // Если гранаты
{
if(clip < 0 || ammo < 0)
{
set_pdata_int(id, weapon_offset[weapon], max_ammount[weapon], m_linux_player) // Выдаём стандарт
set_pev(ent, pev_iuser1, -1)
set_pev(ent, pev_iuser2, -1)
return ent
}
else if(clip == 0 && ammo == 0) set_pdata_int(id, weapon_offset[weapon], 1, m_linux_player) // Выдаём 1
else set_pdata_int(id, weapon_offset[weapon], clip + ammo, m_linux_player) // Выдаём клип + аммо
}
else // Если не гранаты
{
if(clip < 0) // Если бесконечное в оружие
{
set_pdata_int(id, weapon_offset[weapon], max_ammount[weapon], m_linux_player) // Выдаём стандарт к оружию
set_pev(ent, pev_iuser1, -1)
set_pev(ent, pev_iuser2, -1)
return ent
}
else if(clip > 0 && clip != max_clipout[weapon]) // Если не стандарт, записываем количество и разницу
{
set_pev(ent, pev_iuser1, clip)
set_pev(ent, pev_euser1, clip)
set_pev(ent, pev_iuser3, clip - max_clipout[weapon])
}
if(ammo < 0) // Если патроны в запасе бесконечные
{
set_pdata_int(id, weapon_offset[weapon], clip > 0 ? clip : max_ammount[weapon], m_linux_player) // Если устанавливались в оружие, то выдать столько же, нет - стандарт.
set_pev(ent, pev_iuser2, -1)
}
else if(ammo > 0) // Если установлено в запас
{
set_pdata_int(id, weapon_offset[weapon], ammo, m_linux_player) // Выдаём игроку патроны к оружию
set_pev(ent, pev_iuser2, ammo) // Записываем количество в ячейку
set_pev(ent, pev_iuser4, ammo) // Записываем количество патронов в запасе в ячейку
}
else if(max_ammount[weapon]) // Если в запас ничего не устанавливали и стандартно в запасе есть, то выдать максимальное количество в запас.
{
set_pdata_int(id, weapon_offset[weapon], max_ammount[weapon], m_linux_player) // Если в запас не устанавливались и стандар больше 2х, выдать стандартное количество
set_pev(ent, pev_iuser4, max_ammount[weapon]) // Записываем количество патронов в запасе в ячейку
}
}
return ent
}
drop_weapons(id, dropwhat)
{
static i
static num
static weapons[32]
get_user_weapons(id, weapons, num)
i = -1
i += 1
while (i < num)
{
if (dropwhat == weapons[i])
{
if (1 << dropwhat & 33554960)
{
set_pdata_int(id, weapon_offset[dropwhat], "HamFilter", 5, 5)
}
engclient_cmd(id, "drop", weapons_name[dropwhat], 5908)
}
}
return 0
}
stock fm_strip_user_weapons(id)
{
static ent; ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "player_weaponstrip"))
if(!pev_valid(ent)) return 0
dllfunc(DLLFunc_Spawn, ent)
dllfunc(DLLFunc_Use, ent, id)
engfunc(EngFunc_RemoveEntity, ent)
return 1
}
stock colored_print(id, message[], any:...)
{
static buffer[190]; vformat(buffer, charsmax(buffer), message, 3)
if(id)
{
if(is_user_connected(id) && !is_user_bot(id))
{
message_begin(MSG_ONE, g_msg_index[3], _, id)
write_byte(id)
write_string(buffer)
message_end()
}
}
else
{
static i; i = 0
while(++i < g_maxplayers)
{
if(!is_user_connected(i)) continue
if(is_user_bot(i)) continue
message_begin(MSG_ONE, g_msg_index[3], _, i)
write_byte(i)
write_string(buffer)
message_end()
}
}
}