#include <amxmodx>
#include <hamsandwich>
#include <reapi>
#define WEAPON_CMD "give_AK47" // Команда по которой будет выдано оружие
#define WEAPON_ID WEAPON_AK47 // ID оружия
#define WEAPON_NAME "weapon_ak-47" // Название оружия
#define ACCESS_FLAG ADMIN_LEVEL_H // Флаг которому доступно оружие. Закоментировать чтобы было доступно всем
#define WEAPON_DAMAGE 2.0 // Множитель урона. Закоментировать если не нужно
#define WEAPON_CLIP 35 // Количество патронов в обойме. Закоментировать если количество по умолчанию
#define WEAPON_AMMO 150 // Количество патронов в запасе
#define WEAPON_SPEED 300.0 // Скорость бега. Закоментировать если количество по умолчанию
#define WEAPON_GRAVITY 0.8 // Гравитация (1.0 == sv_gravity). Закоментировать если количество по умолчанию.
#define MODEL_V "models/Elitegun/v_ak47.mdl" // Модель оружия. Закоментировать если не нужно
#define MODEL_P "models/Elitegun/p_ak47.mdl" // Модель оружия. Закоментировать если не нужно
#define MODEL_W "models/Elitegun/w_ak47.mdl" // Модель оружия. Закоментировать если не нужно
#define WEAPON_CAN_TOUCH_ONLY_OWNER // Поднять сможет только владелец. Закоментировать если не нужно
#define WEAPON_UID 1
#define IsCustomWeapon(%1) bool:(get_entvar(%1, var_impulse) == WEAPON_UID)
#if defined WEAPON_DAMAGE
new Float:g_PlayerDamage[MAX_PLAYERS + 1];
#endif
#if defined MODEL_V || defined MODEL_P || defined MODEL_W
public plugin_precache() {
#if defined MODEL_V
precache_model(MODEL_V);
#endif
#if defined MODEL_P
precache_model(MODEL_P);
#endif
#if defined MODEL_W
precache_model(MODEL_W);
#endif
}
#endif
public plugin_init() {
register_clcmd(WEAPON_CMD, "CmdGive");
#if defined MODEL_V || defined MODEL_P || defined WEAPON_DAMAGE || defined WEAPON_GRAVITY
RegisterHam(Ham_Item_Deploy, WEAPON_NAME, "HookItemDeploy", 1);
#endif
#if defined WEAPON_DAMAGE || defined WEAPON_GRAVITY
RegisterHam(Ham_Item_Holster, WEAPON_NAME, "HookHolster", 1);
#endif
#if defined MODEL_W
RegisterHookChain(RG_CWeaponBox_SetModel, "HookSetModel", 0);
#endif
#if defined WEAPON_DAMAGE
RegisterHookChain(RG_CBasePlayer_TakeDamage, "HookTakeDamage", 0);
#endif
#if defined WEAPON_CLIP
RegisterHam(Ham_Weapon_Reload, WEAPON_NAME, "HookReloaded", 0);
#endif
#if defined WEAPON_SPEED
RegisterHookChain(RG_CBasePlayer_ResetMaxSpeed, "HookResetMaxSpeed", 1);
#endif
#if defined WEAPON_CAN_TOUCH_ONLY_OWNER
RegisterHam(Ham_Touch, "weaponbox", "HookWeaponBoxTouch", 0);
#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
return PLUGIN_HANDLED;
}
#if defined MODEL_V || defined MODEL_P || defined WEAPON_DAMAGE || defined WEAPON_GRAVITY
public HookItemDeploy(weapon) {
new id = get_member(weapon, m_pPlayer);
if (!is_user_connected(id) || !IsCustomWeapon(weapon)) {
return HAM_IGNORED;
}
#if defined MODEL_V
set_entvar(id, var_viewmodel, MODEL_V);
#endif
#if defined MODEL_V
set_entvar(id, var_weaponmodel, MODEL_P);
#endif
#if defined WEAPON_DAMAGE
g_PlayerDamage[id] = WEAPON_DAMAGE;
#endif
#if defined WEAPON_GRAVITY
set_entvar(id, var_gravity, WEAPON_GRAVITY);
#endif
return HAM_IGNORED;
}
#endif
#if defined WEAPON_DAMAGE || defined WEAPON_GRAVITY
public HookHolster(weapon) {
new id = get_member(weapon, m_pPlayer);
if (!is_user_connected(id)) {
return HAM_IGNORED;
}
#if defined WEAPON_DAMAGE
g_PlayerDamage[id] = 0.0;
#endif
#if defined WEAPON_GRAVITY
set_entvar(id, var_gravity, 1.0);
#endif
return HAM_IGNORED;
}
#endif
#if defined MODEL_W
public HookSetModel(const weaponbox, const model[]) {
new weapon = getWeaponBoxWeapon(weaponbox);
if (weaponbox != NULLENT && IsCustomWeapon(weapon)) {
SetHookChainArg(2, ATYPE_STRING, MODEL_W);
}
return HC_CONTINUE;
}
#endif
#if defined WEAPON_DAMAGE
public HookTakeDamage(const id, inflictor, attacker, Float:damage, type) {
if (
!is_user_connected(id) ||
id == attacker ||
attacker != inflictor ||
(type & (DMG_BULLET | DMG_NEVERGIB)) == 0
) {
return HC_CONTINUE;
}
if (g_PlayerDamage[attacker] > 0.0) {
SetHookChainArg(4, ATYPE_FLOAT, damage * g_PlayerDamage[attacker]);
}
return HC_CONTINUE;
}
#endif
#if defined WEAPON_CLIP
public HookReloaded(weapon) {
new id = get_member(weapon, m_pPlayer);
if (!is_user_connected(id) || !IsCustomWeapon(weapon)) {
return HAM_IGNORED;
}
if (get_member(weapon, m_Weapon_iClip) < WEAPON_CLIP) {
return HAM_IGNORED;
}
#if WEAPON_ID == WEAPON_M4A1
new animation = get_member(weapon, m_Weapon_iWeaponState) & WPNSTATE_M4A1_SILENCED ? 0 : 7;
#elseif WEAPON_ID == WEAPON_USP
new animation = get_member(weapon, m_Weapon_iWeaponState) & WPNSTATE_USP_SILENCED ? 0 : 8;
#else
new animation = 0
#endif
set_entvar(id, var_weaponanim, animation);
message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = id);
write_byte(animation);
write_byte(get_entvar(id, var_body));
message_end();
return HAM_SUPERCEDE;
}
#endif
#if defined WEAPON_SPEED
public HookResetMaxSpeed(const id)
{
new speed = floatround(Float:get_entvar(id, var_maxspeed));
if (speed == 900 || speed == 1) { // Observer mode or Freeze period
return HC_CONTINUE;
}
new weapon = get_member(id, m_pActiveItem);
if(
weapon == NULLENT ||
WeaponIdType:get_member(weapon, m_iId ) != WEAPON_ID ||
!IsCustomWeapon(weapon)
) {
return HC_CONTINUE;
}
set_entvar(id, var_maxspeed, WEAPON_SPEED);
return HC_CONTINUE;
}
#endif
#if defined WEAPON_CAN_TOUCH_ONLY_OWNER
public HookWeaponBoxTouch(const weaponbox, const id) {
new weapon = getWeaponBoxWeapon(weaponbox);
if(
weapon == NULLENT ||
WeaponIdType:get_member(weapon, m_iId ) != 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;
}