#include <amxmodx>
#include <reapi>
#include <hamsandwich>
#include <fakemeta>
#define FLAG_ACCESS ADMIN_BAN // флаг админа который может поднимать и брать оружие (// - выкл)
#if defined FLAG_ACCESS
#define ONLY_ADMIN_CAN_TOUCH // только админ может поднимать пуху (// - выкл)
#endif
#define IsCustomItem(%0) (pev(%0, pev_impulse) == WEAPON_KEY)
new const PLUGIN_NAME[] = "[ReAPI] Custom Weapon";
new const PLUGIN_VERSION[] = "0.0.1";
const WEAPON_KEY = 1337; // super code
const WEAPON_AMMO = 35; // сколько выдавать патрон
new const WEAPON_REFERENCE[] = "weapon_ak47"; // какое оружие использовать и выдавать xd
new const WEAPON_MODEL_VIEW[] = "models/cs_zapret/aes/v_ak47.mdl";
new const WEAPON_MODEL_PLAYER[] = "models/cs_zapret/aes/p_ak47.mdl";
new const WEAPON_MODEL_WORLD[] = "models/cs_zapret/aes/w_ak47.mdl";
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, "Add your favorite scripter");
register_clcmd("say /giveweapon", "GiveModelAK");
RegisterHam(Ham_Item_Deploy, WEAPON_REFERENCE, "CWeapon_Deploy_Post", .Post = true);
#if defined ONLY_ADMIN_TOUCH
RegisterHam(Ham_Touch, "weaponbox", "CWeapon_Touch_Pre", .Post = false);
#endif
RegisterHookChain(RG_CWeaponBox_SetModel, "CWeapon_SetModel_Pre", .post = false);
}
public GiveModelAK(iPlayer)
{
#if defined FLAG_ACCESS
if(!(get_user_flags(iPlayer) & FLAG_ACCESS))
{
client_print(iPlayer, print_center, "* Нет доступа *");
return;
}
#endif
if(!is_user_alive(iPlayer))
{
client_print(iPlayer, print_center, "* Только для живых *");
return;
}
rg_give_custom_item(iPlayer, WEAPON_REFERENCE, GT_REPLACE, WEAPON_KEY);
rg_set_user_bpammo(iPlayer, rg_get_weapon_info(WEAPON_REFERENCE, WI_ID), WEAPON_AMMO);
return;
}
public plugin_precache()
{
engfunc(EngFunc_PrecacheModel, WEAPON_MODEL_VIEW);
engfunc(EngFunc_PrecacheModel, WEAPON_MODEL_PLAYER);
engfunc(EngFunc_PrecacheModel, WEAPON_MODEL_WORLD);
}
public CWeapon_Deploy_Post(iItem)
{
if(!is_entity(iItem))
{
return;
}
if(!IsCustomItem(iItem))
{
return;
}
new iPlayer = get_member(iItem, m_pPlayer);
set_entvar(iPlayer, var_viewmodel, WEAPON_MODEL_VIEW);
set_entvar(iPlayer, var_weaponmodel, WEAPON_MODEL_PLAYER);
}
public CWeapon_SetModel_Pre(iEntity, szModel[])
{
static iItem;
for(new i = 0; i < MAX_ITEM_TYPES; i++)
{
iItem = get_member(iEntity, m_WeaponBox_rgpPlayerItems, i);
if(iItem > 0 && IsCustomItem(iItem))
{
SetHookChainArg(2, ATYPE_STRING, WEAPON_MODEL_WORLD);
set_entvar(iEntity, var_impulse, WEAPON_KEY);
return HC_CONTINUE;
}
}
return HC_CONTINUE;
}
#if defined ONLY_ADMIN_CAN_TOUCH
public CWeapon_Touch_Pre(iItem, iPlayer)
{
if(!is_entity(iItem) || !is_user_connected(iPlayer))
{
return HAM_IGNORED;
}
if(IsCustomItem(iItem))
{
if(!(get_user_flags(iPlayer) & FLAG_ACCESS))
{
return HAM_SUPERCEDE;
}
}
return HAM_IGNORED;
}
#endif