#include <amxmodx>
#include <customweapon>
#include <hamsandwich>
#include <reapi>
#define WEAPON_ID WEAPON_KNIFE // ID оружия
#define WEAPON_NAME "weapon_knife" // Название оружия
#define WEAPON_DAMAGE 3.0 // Скорость бега. Закоментировать если количество по умолчанию
#define MODEL_V "models/t/Knife/Gold/v_dagger.mdl" // Модель V оружия.
#define MODEL_P "models/t/Knife/Gold/p_dagger.mdl" // Модель P оружия.
#define WEAPON_UID 1
#define GetWeponID(%1) WeaponIdType:get_member(%1, m_iId)
#define IsCustomWeapon(%1) bool:(get_entvar(%1, var_impulse) == WEAPON_UID)
#define IsUserValid(%0) (1 <= %0 <= MaxClients)
new bool:g_HasKnife[MAX_CLIENTS] = false
public plugin_precache() {
precache_model(MODEL_V);
precache_model(MODEL_P);
}
public plugin_init() {
RegisterHam(Ham_Item_Deploy, WEAPON_NAME, "Item_Deploy_Post", true);
RegisterHookChain(RG_CBasePlayer_Spawn, "PlayerSpawn", true);
RegisterHookChain(RG_CBasePlayer_TakeDamage, "CBasePlayer_TakeDamage", false);
}
public Check_CmdGive(id){
new iActiveItem = get_member(id, m_pActiveItem)
new WeaponIdType:iId = get_member(iActiveItem, m_iId)
if(iId != WEAPON_ID){
g_HasKnife[id] = true
CmdGive(id)
}else{
client_print_color(id, print_team_default, "Уберите нож из рук")
}
}
public CmdGive(id) {
new iActiveItem = get_member(id, m_pActiveItem)
new WeaponIdType:iId = get_member(iActiveItem, m_iId)
if(iId != WEAPON_ID && g_HasKnife[id]){
CustomWeaponKnifeSpeed(id, false)
CustomWeaponKnifeGravity(id, false)
CustomWeaponKnifeUltra(id, false)
new weapon = rg_give_custom_item(id, WEAPON_NAME, GT_REPLACE, WEAPON_UID);
if (is_nullent(weapon)) {
return PLUGIN_HANDLED;
}
}else{
client_print_color(id, print_team_default, "Уберите нож из рук")
}
return PLUGIN_HANDLED;
}
public Item_Deploy_Post(weapon) {
if (!IsCustomWeapon(weapon)) {
return HAM_IGNORED;
}
new id = get_member(weapon, m_pPlayer);
if(id > 0 && g_HasKnife[id]){
set_entvar(id, var_viewmodel, MODEL_V);
set_entvar(id, var_weaponmodel, MODEL_P);
}
return HAM_IGNORED;
}
public CBasePlayer_TakeDamage(victim, inflictor, attacker, Float:damage, damagebits){
new weapon = get_member(attacker, m_pActiveItem)
if (!is_user_connected(attacker) || victim == attacker) {
return HC_CONTINUE;
}
if(GetWeponID(attacker) == WEAPON_ID && IsCustomWeapon(weapon))
SetHookChainArg(4, ATYPE_FLOAT, damage*WEAPON_DAMAGE)
return HC_CONTINUE;
}
public PlayerSpawn(id){
if(g_HasKnife[id] == true){
rg_give_custom_item(id, WEAPON_NAME, GT_REPLACE, WEAPON_UID)
}
}
public client_disconnected(id){
g_HasKnife[id] = false;
}
public plugin_natives()
{
register_library("customweapon");
register_native("CustomWeaponKnifeGold", "__CustomWeaponKnifeGold");
}
public __CustomWeaponKnifeGold(iPlugin, iParams)
{
enum { player = 1, bType};
new id = get_param(player);
g_HasKnife[id] = bool:get_param(bType)
if(!IsUserValid(id))
abort(AMX_ERR_NATIVE, "Player out of range (%i)", id);
if(g_HasKnife[id])
CmdGive(id);
}