Участник
Пользователь
- Сообщения
- 323
- Реакции
- 99
- Помог
- 5 раз(а)
Подскажите, если возможно, то как исправить такую траблу:
Если после взятия кастомной пушки, с изменённым кол-вом патронов, купить дефолт пушку с бай меню то на дефолте будут кастомные патроны.
Если после взятия кастомной пушки, с изменённым кол-вом патронов, купить дефолт пушку с бай меню то на дефолте будут кастомные патроны.
Код:
/*
* Last update: 09.02.2019
*
* Original code by F@nt0M: https://dev-cs.ru/threads/1983/page-3#post-51426
*/
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <reapi>
#pragma semicolon 1
new const PLUGIN_VERSION[] = "1.0";
/****************************************************************************************
****************************************************************************************/
#define IsUserValid(%0) (1 <= %0 <= MaxClients)
#define GetCvarDesc(%0) fmt("%l", %0)
// Режим DEBUG. Раскомментировать если нужно включить команду для выдачи оружия
//#define DEBUG
// Уникальный ID (impulse) для оружия
#define WEAPON_UID 130
// ID оружия (берётся из файла cssdk_const.inc из enum WeaponIdType)
#define WEAPON_ID WEAPON_AK47
// Получить ID оружия
#define GetWeaponID(%0) WeaponIdType:get_member(%0, m_iId)
// Является ли оружие нашим кастомным
#define IsCustomWeapon(%0) bool:(get_entvar(%0, var_impulse) == WEAPON_UID)
// Нужны ли модели
#define MODELS
// Нужна ли модель "w_"
#define MODEL_W
#if defined MODELS
new const g_szModelV[] = "models/custom/gold/v_gold_ak47.mdl"; // Модель "v_"
new const g_szModelP[] = "models/custom/gold/p_gold_ak47.mdl"; // Модель "p_"
#if defined MODEL_W
new const g_szModelW[] = "models/custom/gold/w_gold_ak47.mdl"; // Модель "w_"
#endif
#endif
#if defined DEBUG
// Команда для выдачи оружия
new const g_szGiveWeaponCmd[] = "give_ak47";
#endif
// Название оружия (информация: https://dev-cs.ru/threads/772/)
new const g_szWeaponName[] = "weapon_ak47";
/****************************************************************************************
****************************************************************************************/
enum _:CVARS
{
CVAR_WEAPON_DAMAGE,
CVAR_WEAPON_CLIP,
CVAR_WEAPON_AMMO,
CVAR_TOUCH_ONLY_OWNER
};
new g_eCvar[CVARS];
new HamHook:g_iHamHookDeployPost, HamHook:g_iHamHookReloadPre, HamHook:g_iHamHookTouchPre;
new HookChain:g_iHookChainSetModelPre, HookChain:g_iHookChainAddPlayerItemPre;
new g_iFMFwdRemoveEntityPre;
new g_iActiveWeapons;
/****************************************************************************************
****************************************************************************************/
#if defined MODELS
public plugin_precache()
{
precache_model(g_szModelV);
precache_model(g_szModelP);
#if defined MODEL_W
precache_model(g_szModelW);
#endif
}
#endif
public plugin_init()
{
register_plugin("[Custom] Weapon: Gold AK-47", PLUGIN_VERSION, "w0w");
register_dictionary("custom_weapon.ini");
#if defined DEBUG
register_clcmd(g_szGiveWeaponCmd, "func_CmdGiveWeapon");
#endif
RegisterHookChain(RG_CBasePlayer_DropPlayerItem, "refwd_PlayerDropPlayerItem_Post", true);
DisableHookChain(g_iHookChainAddPlayerItemPre = RegisterHookChain(RG_CBasePlayer_AddPlayerItem, "refwd_PlayerAddPlayerItem_Pre", false));
#if defined MODELS
DisableHamForward(g_iHamHookDeployPost = RegisterHam(Ham_Item_Deploy, g_szWeaponName, "hamfwd_ItemDeploy_Post", true));
#endif
DisableHookChain(g_iHookChainSetModelPre = RegisterHookChain(RG_CWeaponBox_SetModel, "refwd_WeaponBox_SetModel_Pre", false));
DisableHamForward(g_iHamHookReloadPre = RegisterHam(Ham_Weapon_Reload, g_szWeaponName, "hamfwd_WeaponReload_Pre", false));
DisableHamForward(g_iHamHookTouchPre = RegisterHam(Ham_Touch, "weaponbox", "hamfwd_WeaponBox_Touch_Pre", false));
func_RegisterCvars();
}
public func_CmdGiveWeapon(id)
{
if(!is_user_alive(id))
return PLUGIN_HANDLED;
if(++g_iActiveWeapons == 1)
func_ManageHooks(true);
new iWeapon = rg_give_custom_item(id, g_szWeaponName, GT_REPLACE, WEAPON_UID);
if(is_nullent(iWeapon))
return PLUGIN_HANDLED;
if(g_eCvar[CVAR_WEAPON_CLIP])
{
rg_set_iteminfo(iWeapon, ItemInfo_iMaxClip, g_eCvar[CVAR_WEAPON_CLIP]);
rg_set_user_ammo(id, WEAPON_ID, g_eCvar[CVAR_WEAPON_CLIP]);
}
if(g_eCvar[CVAR_WEAPON_AMMO])
rg_set_user_bpammo(id, WEAPON_ID, g_eCvar[CVAR_WEAPON_AMMO]);
if(g_eCvar[CVAR_WEAPON_DAMAGE])
{
set_member(iWeapon, m_Weapon_flBaseDamage, Float:get_member(iWeapon, m_Weapon_flBaseDamage) * g_eCvar[CVAR_WEAPON_DAMAGE]);
#if WEAPON_ID == WEAPON_M4A1
set_member(iWeapon, m_M4A1_flBaseDamageSil, Float:get_member(iWeapon, m_M4A1_flBaseDamageSil) * g_eCvar[CVAR_WEAPON_DAMAGE]);
#elseif WEAPON_ID == WEAPON_USP
set_member(iWeapon, m_USP_flBaseDamageSil, Float:get_member(iWeapon, m_USP_flBaseDamageSil) * g_eCvar[CVAR_WEAPON_DAMAGE]);
#elseif WEAPON_ID == WEAPON_FAMAS
set_member(iWeapon, m_Famas_flBaseDamageBurst, Float:get_member(iWeapon, m_Famas_flBaseDamageBurst) * g_eCvar[CVAR_WEAPON_DAMAGE]);
#endif
}
return PLUGIN_HANDLED;
}
#if defined MODELS
public hamfwd_ItemDeploy_Post(iWeapon)
{
if(!IsCustomWeapon(iWeapon))
return HAM_IGNORED;
new id = get_member(iWeapon, m_pPlayer);
#if defined MODELS
set_entvar(id, var_viewmodel, g_szModelV);
set_entvar(id, var_weaponmodel, g_szModelP);
#endif
return HAM_IGNORED;
}
#endif
public refwd_WeaponBox_SetModel_Pre(const iWeaponBox, const szModel[])
{
new iWeapon = func_GetWeaponBoxWeapon(iWeaponBox);
if(iWeapon != NULLENT && IsCustomWeapon(iWeapon))
{
SetHookChainArg(2, ATYPE_STRING, g_szModelW);
if(!(--g_iActiveWeapons))
func_ManageHooks(false);
}
}
public hamfwd_WeaponReload_Pre(iWeapon)
{
if(!IsCustomWeapon(iWeapon) || get_member(iWeapon, m_Weapon_iClip) < g_eCvar[CVAR_WEAPON_CLIP])
return HAM_IGNORED;
new id = get_member(iWeapon, m_pPlayer);
#if WEAPON_ID == WEAPON_M4A1
func_SendWeaponAnimation(id, get_member(iWeapon, m_Weapon_iWeaponState) & WPNSTATE_M4A1_SILENCED ? 0 : 7);
#elseif WEAPON_ID == WEAPON_USP
func_SendWeaponAnimation(id, get_member(iWeapon, m_Weapon_iWeaponState) & WPNSTATE_USP_SILENCED ? 0 : 8);
#else
func_SendWeaponAnimation(id, 0);
#endif
return HAM_SUPERCEDE;
}
public hamfwd_WeaponBox_Touch_Pre(const iWeaponBox, const id)
{
new iWeapon = func_GetWeaponBoxWeapon(iWeaponBox);
if(iWeapon == NULLENT || GetWeaponID(iWeapon) != WEAPON_ID || !IsCustomWeapon(iWeapon))
return HAM_IGNORED;
if(g_eCvar[CVAR_TOUCH_ONLY_OWNER] && get_entvar(iWeaponBox, var_owner) == id)
return HAM_SUPERCEDE;
EnableHookChain(g_iHookChainAddPlayerItemPre);
return HAM_IGNORED;
}
stock func_GetWeaponBoxWeapon(const iWeaponBox)
{
for(new i, iWeapon; i < MAX_ITEM_TYPES; i++)
{
iWeapon = get_member(iWeaponBox, m_WeaponBox_rgpPlayerItems, i);
if(!is_nullent(iWeapon))
return iWeapon;
}
return NULLENT;
}
stock func_SendWeaponAnimation(const id, const iAnimation)
{
set_entvar(id, var_weaponanim, iAnimation);
message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = id);
write_byte(iAnimation);
write_byte(0);
message_end();
}
/****************************************************************************************
****************************************************************************************/
public fmfwd_RemoveEntity_Pre(const iEnt)
{
if(!is_entity(iEnt) || !IsCustomWeapon(iEnt))
return FMRES_IGNORED;
if(!(--g_iActiveWeapons))
func_ManageHooks(false);
return FMRES_IGNORED;
}
public refwd_PlayerDropPlayerItem_Post(const id, const pszItemName[])
{
new iEnt = GetHookChainReturn(ATYPE_INTEGER);
if(!is_entity(iEnt))
return HC_CONTINUE;
new iWeapon = func_GetWeaponBoxWeapon(iEnt);
if(iWeapon != NULLENT && IsCustomWeapon(iWeapon))
EnableHookChain(g_iHookChainSetModelPre);
return HC_CONTINUE;
}
public refwd_PlayerAddPlayerItem_Pre(const id, const pItem)
{
DisableHookChain(g_iHookChainAddPlayerItemPre);
if(!is_entity(pItem))
return HC_CONTINUE;
if(IsCustomWeapon(pItem) && ++g_iActiveWeapons == 1)
func_ManageHooks(true);
return HC_CONTINUE;
}
func_ManageHooks(bool:bEnable)
{
if(bEnable)
{
if(g_eCvar[CVAR_WEAPON_CLIP])
EnableHamForward(g_iHamHookReloadPre);
if(g_eCvar[CVAR_TOUCH_ONLY_OWNER])
EnableHamForward(g_iHamHookTouchPre);
EnableHamForward(g_iHamHookDeployPost);
EnableHookChain(g_iHookChainSetModelPre);
g_iFMFwdRemoveEntityPre = register_forward(FM_RemoveEntity, "fmfwd_RemoveEntity_Pre", false);
}
else
{
DisableHookChain(g_iHookChainSetModelPre);
DisableHamForward(g_iHamHookReloadPre);
DisableHamForward(g_iHamHookDeployPost);
EnableHamForward(g_iHamHookTouchPre);
unregister_forward(FM_RemoveEntity, g_iFMFwdRemoveEntityPre);
}
}
/****************************************************************************************
****************************************************************************************/
func_RegisterCvars()
{
new pCvar;
pCvar = create_cvar("custom_weapon_gold_ak47_clip", "30", FCVAR_NONE, GetCvarDesc("CUSTOM_WEAPON_CVAR_CLIP"), true, 0.0);
hook_cvar_change(pCvar, "hook_CvarChange_Clip");
pCvar = create_cvar("custom_weapon_gold_ak47_ammo", "500", FCVAR_NONE, GetCvarDesc("CUSTOM_WEAPON_CVAR_AMMO"), true, 0.0);
bind_pcvar_num(pCvar, g_eCvar[CVAR_WEAPON_AMMO]);
pCvar = create_cvar("custom_weapon_gold_ak47_damage", "2", FCVAR_NONE, GetCvarDesc("CUSTOM_WEAPON_CVAR_DAMAGE"), true, 0.0);
bind_pcvar_num(pCvar, g_eCvar[CVAR_WEAPON_DAMAGE]);
pCvar = create_cvar("custom_weapon_gold_ak47_touch_only_owner", "0", FCVAR_NONE, GetCvarDesc("CUSTOM_WEAPON_CVAR_TOUCH_ONLY_OWNER"), true, 0.0, true, 1.0);
bind_pcvar_num(pCvar, g_eCvar[CVAR_TOUCH_ONLY_OWNER]);
}
public hook_CvarChange_Clip(pCvar, const szOldValue[], const szNewValue[])
{
g_eCvar[CVAR_WEAPON_CLIP] = str_to_num(szNewValue);
if(g_iActiveWeapons && g_eCvar[CVAR_WEAPON_CLIP] == 0)
DisableHamForward(g_iHamHookReloadPre);
}
/****************************************************************************************
****************************************************************************************/
public plugin_natives()
{
register_native("custom_give_weapon_gold_ak47", "__custom_give_weapon_gold_ak47");
}
public __custom_give_weapon_gold_ak47(iPlugin, iParams)
{
enum { player = 1 };
new id = get_param(player);
if(!IsUserValid(id))
abort(AMX_ERR_NATIVE, "Player out of range (%i)", id);
func_CmdGiveWeapon(id);
}