#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <cstrike>
new const V_MODEL[] = "models/v_model3_21.mdl";
#define MAX_SHOOTS 3
enum _:WeaponData
{
WPN_ID, // ID оружия (CSW_*)
WPN_BODY, // Номер субмодели (body)
ANIM_DRAW, // Анимация доставания
STD_SHOTS[MAX_SHOOTS], // Стандартные анимации выстрела для отлова
CUSTOM_SHOTS[MAX_SHOOTS], // Соответствующие им кастомные анимации
ANIM_RELOAD, // Анимация перезарядки
ANIM_IDLE // Анимация покоя
}
// Если какая-то анимация не нужна, ставим -1.
new const g_WeaponSettings[][WeaponData] =
{
// ID оружия | Субмодель | Доставание | Пары выстрелов (до 3 пар: {станд}, {кастом}) | Перезарядка | Покой (Idle)
{
CSW_AK47, 0, 2, {3, 4, 5}, {3, 4, 5}, 1, 8
},
{
CSW_M249, 8, 29, {1, 2, -1}, {25, 26, -1}, 28, 24
}
};
const m_pPlayer = 41;
const m_flTimeWeaponIdle = 48;
const m_fInReload = 54;
const XTRA_OFS_WEAPON = 4;
public plugin_init()
{
register_plugin("Custom Submodel Weapons (Fixed)", "2.1", "Gemini");
new weapon_name[32];
for (new i = 0; i < sizeof(g_WeaponSettings); i++) {
get_weaponname(g_WeaponSettings[i][WPN_ID], weapon_name, charsmax(weapon_name));
RegisterHam(Ham_Item_Deploy, weapon_name, "OnItemDeploy_Post", 1);
RegisterHam(Ham_Weapon_Reload, weapon_name, "OnReload_Post", 1);
RegisterHam(Ham_Weapon_WeaponIdle, weapon_name, "OnWeaponIdle_Pre", 0);
RegisterHam(Ham_Weapon_PrimaryAttack, weapon_name, "OnPrimaryAttack_Pre", 0);
}
}
public plugin_precache()
{
precache_model(V_MODEL);
}
public OnItemDeploy_Post(ent)
{
if (!pev_valid(ent)) return;
new id = get_pdata_cbase(ent, m_pPlayer, XTRA_OFS_WEAPON);
if (!is_user_alive(id)) return;
new wpn_id = cs_get_weapon_id(ent);
new index = GetWeaponSettingIndex(wpn_id);
if (index != -1) {
set_pev(id, pev_viewmodel2, V_MODEL);
set_pev(id, pev_body, g_WeaponSettings[index][WPN_BODY]);
SendWeaponAnim(id, g_WeaponSettings[index][ANIM_DRAW], g_WeaponSettings[index][WPN_BODY]);
set_pdata_float(ent, m_flTimeWeaponIdle, 1.0, XTRA_OFS_WEAPON);
}
}
public OnReload_Post(ent)
{
if (!pev_valid(ent)) return;
if (!get_pdata_int(ent, m_fInReload, XTRA_OFS_WEAPON)) return;
new id = get_pdata_cbase(ent, m_pPlayer, XTRA_OFS_WEAPON);
if (!is_user_alive(id)) return;
new wpn_id = cs_get_weapon_id(ent);
new index = GetWeaponSettingIndex(wpn_id);
if (index != -1 && g_WeaponSettings[index][ANIM_RELOAD] != -1) {
set_pev(id, pev_body, g_WeaponSettings[index][WPN_BODY]);
SendWeaponAnim(id, g_WeaponSettings[index][ANIM_RELOAD], g_WeaponSettings[index][WPN_BODY]);
set_pdata_float(ent, m_flTimeWeaponIdle, 2.5, XTRA_OFS_WEAPON);
}
}
public OnWeaponIdle_Pre(ent)
{
if (!pev_valid(ent)) return HAM_IGNORED;
if (get_pdata_float(ent, m_flTimeWeaponIdle, XTRA_OFS_WEAPON) > 0.0) return HAM_IGNORED;
new id = get_pdata_cbase(ent, m_pPlayer, XTRA_OFS_WEAPON);
if (!is_user_alive(id)) return HAM_IGNORED;
new wpn_id = cs_get_weapon_id(ent);
new index = GetWeaponSettingIndex(wpn_id);
if (index != -1 && g_WeaponSettings[index][ANIM_IDLE] != -1) {
set_pev(id, pev_body, g_WeaponSettings[index][WPN_BODY]);
SendWeaponAnim(id, g_WeaponSettings[index][ANIM_IDLE], g_WeaponSettings[index][WPN_BODY]);
set_pdata_float(ent, m_flTimeWeaponIdle, 5.0, XTRA_OFS_WEAPON);
return HAM_SUPERCEDE;
}
return HAM_IGNORED;
}
public OnPrimaryAttack_Pre(ent)
{
if (!pev_valid(ent)) return HAM_IGNORED;
new id = get_pdata_cbase(ent, m_pPlayer, XTRA_OFS_WEAPON);
if (!is_user_alive(id)) return HAM_IGNORED;
new wpn_id = cs_get_weapon_id(ent);
new index = GetWeaponSettingIndex(wpn_id);
if (index != -1) {
if (cs_get_weapon_ammo(ent) > 0) {
set_pev(id, pev_body, g_WeaponSettings[index][WPN_BODY]);
new shoot_anim = g_WeaponSettings[index][CUSTOM_SHOTS][0];
if (shoot_anim != -1) {
SendWeaponAnim(id, shoot_anim, g_WeaponSettings[index][WPN_BODY]);
set_pdata_float(ent, m_flTimeWeaponIdle, 1.5, XTRA_OFS_WEAPON);
}
}
}
return HAM_IGNORED;
}
stock GetWeaponSettingIndex(wpn_id)
{
for (new i = 0; i < sizeof(g_WeaponSettings); i++) {
if (g_WeaponSettings[i][WPN_ID] == wpn_id) {
return i;
}
}
return -1;
}
stock SendWeaponAnim(id, anim, body)
{
set_pev(id, pev_weaponanim, anim);
set_pev(id, pev_body, body);
message_begin(MSG_ONE, SVC_WEAPONANIM, _, id);
write_byte(anim);
write_byte(body);
message_end();
}