Участник
- Сообщения
- 2,491
- Реакции
- 2,794
- Помог
- 61 раз(а)
Код:
#include <amxmodx>
#include <hamsandwich>
#include <reapi>
#if AMXX_VERSION_NUM < 183
new MaxClients;
#endif
#define FLAG ADMIN_LEVEL_H
#define MODEL_V "models/gold/v_m4a1.mdl"
#define MODEL_P "models/gold/p_m4a1.mdl"
#define MODEL_W "models/gold/w_m4a1.mdl"
#define DAMAGE 1.5
#define CLIPSIZE 35
#define AMMOSIZE 140
#if defined DAMAGE
new Float:g_PlayerDamage[MAX_PLAYERS + 1];
#endif
public plugin_precache() {
precache_model(MODEL_V);
precache_model(MODEL_P);
precache_model(MODEL_W);
}
public plugin_init() {
#if AMXX_VERSION_NUM < 183
MaxClients = get_maxplayers();
#endif
register_clcmd("gold_m4a1", "CmdGive");
register_clcmd("say /gold_m4a1", "CmdGive");
register_clcmd("say_team /gold_m4a1", "CmdGive");
RegisterHam(Ham_Item_Deploy, "weapon_m4a1", "HookItemDeploy", 1);
RegisterHam(Ham_Item_Holster, "weapon_m4a1", "HookHolster", 1);
RegisterHookChain(RG_CWeaponBox_SetModel, "HookSetModel", 0);
#if defined DAMAGE
RegisterHookChain(RG_CBasePlayer_TakeDamage, "HookTakeDamage", 0);
#endif
}
public CmdGive(id) {
if (~get_user_flags(id) & FLAG) {
return PLUGIN_HANDLED;
}
new weapon = rg_give_item(id, "weapon_m4a1", GT_REPLACE);
if (is_nullent(weapon)) {
return PLUGIN_HANDLED;
}
set_entvar(weapon, var_impulse, 1);
#if defined CLIPSIZE
rg_set_iteminfo(weapon, ItemInfo_iMaxClip, CLIPSIZE);
rg_set_user_ammo(id, WEAPON_M4A1, CLIPSIZE);
#endif
#if defined AMMOSIZE
rg_set_user_bpammo(id, WEAPON_M4A1, AMMOSIZE);
#else
rg_set_user_bpammo(id, WEAPON_M4A1, 90);
#endif
if (get_member(id, m_pActiveItem) == weapon) {
set_entvar(id, var_viewmodel, MODEL_V);
set_entvar(id, var_weaponmodel, MODEL_P);
#if defined DAMAGE
g_PlayerDamage[id] = DAMAGE;
#endif
}
return PLUGIN_HANDLED;
}
public HookItemDeploy(weapon) {
new id = get_member(weapon, m_pPlayer);
if (id < 1 || id > MaxClients) {
return HAM_IGNORED;
}
if (get_entvar(weapon, var_impulse) == 0) {
return HAM_IGNORED;
}
set_entvar(id, var_viewmodel, MODEL_V);
set_entvar(id, var_weaponmodel, MODEL_P);
#if defined DAMAGE
g_PlayerDamage[id] = DAMAGE;
#endif
return HAM_IGNORED;
}
public HookHolster(weapon) {
new id = get_member(weapon, m_pPlayer);
if (id < 1 || id > MaxClients) {
return HAM_IGNORED;
}
#if defined DAMAGE
g_PlayerDamage[id] = 0.0;
#endif
return HAM_IGNORED;
}
public HookSetModel(const ent, const model[]) {
for (new i = 0, weapon; i < MAX_ITEM_TYPES; i++) {
weapon = get_member(ent, m_WeaponBox_rgpPlayerItems, i);
if (!is_nullent(weapon) && get_entvar(weapon, var_impulse) == 1) {
SetHookChainArg(2, ATYPE_STRING, MODEL_W);
return HC_CONTINUE;
}
}
return HC_CONTINUE;
}
#if defined DAMAGE
public HookTakeDamage(const id, inflictor, attacker, Float:damage, damageType) {
if (
attacker < 1 || attacker > MaxClients
|| id == attacker
|| attacker != inflictor
|| (damageType & DMG_BULLET) == 0
) {
return HC_CONTINUE;
}
if (g_PlayerDamage[attacker] > 0.0) {
SetHookChainArg(4, ATYPE_FLOAT, damage * g_PlayerDamage[attacker]);
}
return HC_CONTINUE;
}
#endif