#include <amxmodx>
#include <reapi>
new const g_szZoomModel[] = "models/reddot.mdl";
new bool:g_iZoom[MAX_CLIENTS+1], szOldModel[MAX_CLIENTS+1][64], bool:iAlive[MAX_CLIENTS+1];
public plugin_init()
{
register_plugin("Weapon Zoom Model", "0.1", "LyNcH");
register_event("CurWeapon", "CurWeapon", "be", "1=1");
RegisterHookChain(RG_CBasePlayer_PreThink, "PreThink", .post = true);
RegisterHookChain(RG_CBasePlayer_Spawn, "PlayerSpawn", .post = true);
RegisterHookChain(RG_CBasePlayer_Killed, "PlayerKilled", .post = true);
RegisterHookChain(RG_CBasePlayerWeapon_DefaultDeploy, "DefaultDeploy", .post = false);
}
public client_putinserver(id)
{
g_iZoom[id] = false;
iAlive[id] = false;
szOldModel[id][0] = EOS;
}
public plugin_precache()
{
precache_model(g_szZoomModel);
}
public CurWeapon(id)
{
if(!is_user_alive(id) || !is_user_connected(id))
{
return PLUGIN_HANDLED;
}
new iWeaponId = get_user_weapon(id);
if(iWeaponId == CSW_AK47)
{
set_entvar(id, var_viewmodel, g_iZoom[id] ? g_szZoomModel:szOldModel[id]);
}
else
{
g_iZoom[id] = false;
}
return PLUGIN_CONTINUE;
}
public DefaultDeploy(const iEntity, szViewModel[], szWeaponModel[], iAnim, szAnimExt[], skiplocal)
{
new id = get_member(iEntity, m_pPlayer);
new WeaponIdType:iWeapon = get_member(iEntity, m_iId);
if(iWeapon == WEAPON_AK47)
{
if(!g_iZoom[id])
{
formatex(szOldModel[id], charsmax(szOldModel[]), "%s", szViewModel); /* Zoomu kapatinca eski modelini vermek icin sakliyoruz */
}
}
}
public PreThink(const id)
{
if(!iAlive[id])
{
return;
}
static iButton; iButton = get_entvar(id, var_button);
static iOldButton; iOldButton = get_entvar(id, var_oldbuttons);
static iWeapon; static szClip; static szAmmo;
iWeapon = get_user_weapon(id, szClip, szAmmo);
if(iWeapon == CSW_AK47)
{
if(g_iZoom[id])
{
static activeItem; activeItem = get_member(id, m_pActiveItem);
if(szClip == 0 || get_member(activeItem, m_Weapon_fInReload))
{
g_iZoom[id] = false; /* Mermi biterse veya reload atarsa zoomu kapatiyoruz */
CurWeapon(id);
}
}
if((iButton & IN_ATTACK2) && !(iOldButton & IN_ATTACK2))
{
g_iZoom[id] = !g_iZoom[id];
CurWeapon(id);
}
}
}
public PlayerSpawn(const id)
{
if(!is_user_alive(id))
{
return;
}
iAlive[id] = true;
}
public PlayerKilled(const this, pevAttacker)
{
if(!is_user_connected(pevAttacker))
{
return;
}
iAlive[this] = false;
}