#include <amxmodx>
#include <hamsandwich>
#include <reapi>
#define WEAPON_CMD "give_m4a1" // Команда по которой будет выдано оружие
#define WEAPON_ID WEAPON_M4A1 // ID оружия
#define WEAPON_NAME "weapon_m4a1" // Название оружия
#define ACCESS_FLAG ADMIN_LEVEL_H // Флаг которому доступно оружие. Закоментировать чтобы было доступно всем
#define WEAPON_DAMAGE 1.2 // Множитель урона. Закоментировать если не нужно
#define WEAPON_CLIP 35 // Количество патронов в обойме. Закоментировать если количество по умолчанию
#define WEAPON_AMMO 120 // Количество патронов в запасе
#define WEAPON_SPEED 300.0 // Скорость бега. Закоментировать если количество по умолчанию
// #define WEAPON_GRAVITY 0.8 // Гравитация (1.0 == sv_gravity). Закоментировать если количество по умолчанию.
#define MODELS // Включить модели оружия. Закоментировать чтобы отключить
#if defined MODELS
#define MODEL_V "models/gold/v_m4a1.mdl" // Модель V оружия.
#define MODEL_P "models/gold/p_m4a1.mdl" // Модель P оружия.
#define MODEL_W "models/gold/w_m4a1.mdl" // Модель W оружия.
#endif
// #define WEAPON_CAN_TOUCH_ONLY_OWNER // Поднять сможет только владелец. Закоментировать если не нужно
#define WEAPON_UID 1
#define GetWeponID(%1) WeaponIdType:get_member(%1, m_iId)
#define IsCustomWeapon(%1) bool:(get_entvar(%1, var_impulse) == WEAPON_UID)
#if defined MODELS
public plugin_precache() {
precache_model(MODEL_V);
precache_model(MODEL_P);
#if defined MODEL_W
precache_model(MODEL_W);
#endif
}
#endif
public plugin_init() {
register_clcmd(WEAPON_CMD, "CmdGive");
#if defined MODELS || defined WEAPON_GRAVITY
RegisterHam(Ham_Item_Deploy, WEAPON_NAME, "Item_Deploy_Post", true);
#endif
#if defined WEAPON_GRAVITY
RegisterHam(Ham_Item_Holster, WEAPON_NAME, "Item_Holster_Post", true);
#endif
#if defined MODEL_W
RegisterHookChain(RG_CWeaponBox_SetModel, "CWeaponBox_SetModel_Pre", false);
#endif
#if defined WEAPON_CLIP
RegisterHam(Ham_Weapon_Reload, WEAPON_NAME, "Weapon_Reload_Pre", false);
#endif
#if defined WEAPON_SPEED
RegisterHam(Ham_CS_Item_GetMaxSpeed, WEAPON_NAME, "CS_Item_GetMaxSpeed_Pre", false);
#endif
#if defined WEAPON_CAN_TOUCH_ONLY_OWNER
RegisterHam(Ham_Touch, "weaponbox", "Weaponbox_Touch_Pre", false);
#endif
}
public CmdGive(id) {
#if defined ACCESS_FLAG
if (~get_user_flags(id) & ACCESS_FLAG) {
return PLUGIN_HANDLED;
}
#endif
new weapon = rg_give_custom_item(id, WEAPON_NAME, GT_REPLACE, WEAPON_UID);
if (is_nullent(weapon)) {
return PLUGIN_HANDLED;
}
#if defined WEAPON_CLIP
rg_set_iteminfo(weapon, ItemInfo_iMaxClip, WEAPON_CLIP);
rg_set_user_ammo(id, WEAPON_ID, WEAPON_CLIP);
#endif
#if defined WEAPON_AMMO
rg_set_user_bpammo(id, WEAPON_ID, WEAPON_AMMO);
#endif
#if defined WEAPON_DAMAGE
set_member(weapon, m_Weapon_flBaseDamage, Float:get_member(weapon, m_Weapon_flBaseDamage) * WEAPON_DAMAGE);
#if WEAPON_ID == WEAPON_M4A1
set_member(weapon, m_M4A1_flBaseDamageSil, Float:get_member(weapon, m_M4A1_flBaseDamageSil) * WEAPON_DAMAGE);
#elseif WEAPON_ID == WEAPON_USP
set_member(weapon, m_USP_flBaseDamageSil, Float:get_member(weapon, m_USP_flBaseDamageSil) * WEAPON_DAMAGE);
#elseif WEAPON_ID == WEAPON_FAMAS
set_member(weapon, m_Famas_flBaseDamageBurst, Float:get_member(weapon, m_Famas_flBaseDamageBurst) * WEAPON_DAMAGE);
#endif
#endif
return PLUGIN_HANDLED;
}
#if defined MODELS || defined WEAPON_GRAVITY
public Item_Deploy_Post(weapon) {
if (!IsCustomWeapon(weapon)) {
return HAM_IGNORED;
}
new id = get_member(weapon, m_pPlayer);
#if defined MODELS
set_entvar(id, var_viewmodel, MODEL_V);
set_entvar(id, var_weaponmodel, MODEL_P);
#endif
#if defined WEAPON_GRAVITY
set_entvar(id, var_gravity, WEAPON_GRAVITY);
#endif
return HAM_IGNORED;
}
#endif
#if defined WEAPON_GRAVITY
public Item_Holster_Post(weapon) {
if (IsCustomWeapon(weapon)) {
new id = get_member(weapon, m_pPlayer);
set_entvar(id, var_gravity, 1.0);
}
}
#endif
#if defined MODEL_W
public CWeaponBox_SetModel_Pre(const weaponbox, const model[]) {
new weapon = getWeaponBoxWeapon(weaponbox);
if (weapon != NULLENT && IsCustomWeapon(weapon)) {
SetHookChainArg(2, ATYPE_STRING, MODEL_W);
}
}
#endif
#if defined WEAPON_CLIP
public Weapon_Reload_Pre(weapon) {
if (!IsCustomWeapon(weapon) || get_member(weapon, m_Weapon_iClip) < WEAPON_CLIP) {
return HAM_IGNORED;
}
new id = get_member(weapon, m_pPlayer);
#if WEAPON_ID == WEAPON_M4A1
sendWeaponAmimation(id, get_member(weapon, m_Weapon_iWeaponState) & WPNSTATE_M4A1_SILENCED ? 0 : 7);
#elseif WEAPON_ID == WEAPON_USP
sendWeaponAmimation(id, get_member(weapon, m_Weapon_iWeaponState) & WPNSTATE_USP_SILENCED ? 0 : 8);
#else
sendWeaponAmimation(id, 0);
#endif
return HAM_SUPERCEDE;
}
#endif
#if defined WEAPON_SPEED
public CS_Item_GetMaxSpeed_Pre(const weapon) {
if (IsCustomWeapon(weapon)) {
SetHamReturnFloat(WEAPON_SPEED);
return HAM_SUPERCEDE;
}
return HAM_IGNORED;
}
#endif
#if defined WEAPON_CAN_TOUCH_ONLY_OWNER
public Weaponbox_Touch_Pre(const weaponbox, const id) {
new weapon = getWeaponBoxWeapon(weaponbox);
if (weapon == NULLENT || GetWeponID(weapon) != WEAPON_ID || !IsCustomWeapon(weapon) {
return HAM_IGNORED;
}
return get_entvar(weaponbox, var_owner) == id ? HAM_IGNORED : HAM_SUPERCEDE;
}
#endif
stock getWeaponBoxWeapon(const weaponbox) {
for (new i = 0, weapon; i < MAX_ITEM_TYPES; i++) {
weapon = get_member(weaponbox, m_WeaponBox_rgpPlayerItems, i);
if (!is_nullent(weapon)) {
return weapon;
}
}
return NULLENT;
}
stock sendWeaponAmimation(const id, const animation) {
set_entvar(id, var_weaponanim, animation);
message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = id);
write_byte(animation);
write_byte(0);
message_end();
}