PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <cstrike>
#define PLUGIN "Cod Weapons Zooms"
#define VERSION "1.3"
#define AUTHOR "CeLeS"
new const zoom[] = "models/champion_cod/zoom2.mdl"
new const m4a1[] = "models/champion_cod/v_m4a1.mdl"
new g_hasZoom[32]
new bool:norecoil[33]
new szClip, szAmmo
new cwz_norecoil, cwz_crosshair
new gmsgHideWeapon
public plugin_init( )
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_forward(FM_CmdStart, "fw_CmdStart" )
register_forward(FM_PlayerPreThink,"fw_Player_PreThink")
register_forward(FM_PlayerPreThink,"fw_PreThink")
register_forward(FM_UpdateClientData,"fw_Update",1)
register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
cwz_norecoil = register_cvar("cod_norecoil", "1")
cwz_crosshair = register_cvar("cod_crosshair_enable", "0")
gmsgHideWeapon = get_user_msgid("HideWeapon")
}
public plugin_precache( )
{
precache_model(zoom)
precache_model(m4a1)
}
public Event_CurWeapon(id)
{
if(!is_user_alive(id) || !is_user_connected(id))
return PLUGIN_CONTINUE
new szWeapID = get_user_weapon( id, szClip, szAmmo )
if(szWeapID == CSW_M4A1 && !g_hasZoom[id] == true )
{
entity_set_string(id, EV_SZ_viewmodel, m4a1)
}
return PLUGIN_CONTINUE
}
public fw_CmdStart( id, uc_handle, seed )
{
if(!is_user_alive(id) )
{
ZoomFalse(id)
return PLUGIN_HANDLED
}
new szWeapID = get_user_weapon( id, szClip, szAmmo )
if((get_uc( uc_handle, UC_Buttons ) & IN_ATTACK2 ) && !( pev( id, pev_oldbuttons ) & IN_ATTACK2 ) )
{
if(szWeapID == CSW_M4A1 && !g_hasZoom[id] == true)
{
ZoomTrue(id)
}
else if(szWeapID == CSW_M4A1 && g_hasZoom[id])
{
ZoomFalse(id)
entity_set_string(id, EV_SZ_viewmodel, m4a1)
}
}
if(g_hasZoom[id] && ( ( get_uc( uc_handle, UC_Buttons ) & IN_RELOAD ) && (pev(id, pev_button) & IN_RELOAD)) )
{
if(szWeapID == CSW_M4A1 )
{
ZoomFalse(id)
entity_set_string(id, EV_SZ_viewmodel, m4a1)
}
}
if( szWeapID != CSW_M4A1 && g_hasZoom[id] )
{
ZoomFalse(id)
}
if(szClip == 0 && g_hasZoom[id])
{
ZoomFalse(id)
}
return PLUGIN_HANDLED
}
public fw_Player_PreThink(id)
{
if(!is_user_alive(id) || get_user_weapon(id) != CSW_M4A1)
{
return FMRES_IGNORED
}
set_pev(id, pev_button, pev(id,pev_button) & ~IN_ATTACK2)
return FMRES_HANDLED
}
public fw_PreThink(id)
{
if(!is_user_alive(id) || norecoil[id] == false)
{
return FMRES_IGNORED
}
set_pev(id,pev_punchangle,{0.0,0.0,0.0})
return FMRES_HANDLED
}
public fw_Update(id, sendweapons, cd_handle)
{
if(!is_user_alive(id) || norecoil[id] == false)
{
return FMRES_IGNORED
}
set_cd(cd_handle, CD_PunchAngle, {0.0,0.0,0.0})
return FMRES_HANDLED
}
public ZoomTrue(id)
{
if(get_pcvar_num(cwz_norecoil) == 1)
{
norecoil[id] = true
}
g_hasZoom[id] = true
if(!get_pcvar_num(cwz_crosshair))
{
hide_crosshair(id)
}
entity_set_string(id, EV_SZ_viewmodel, zoom)
cs_set_user_zoom(id, CS_SET_AUGSG552_ZOOM, 0)
client_cmd(id, "spk weapons/zoom")
}
public ZoomFalse(id)
{
norecoil[id] = false
g_hasZoom[id] = false
draw_crosshair(id)
cs_set_user_zoom(id, CS_RESET_ZOOM, 0)
}
public draw_crosshair(id)
{
message_begin(MSG_ONE_UNRELIABLE, gmsgHideWeapon, _, id)
write_byte(0)
message_end()
}
public hide_crosshair(id)
{
message_begin(MSG_ONE_UNRELIABLE, gmsgHideWeapon, _, id)
write_byte(1<<6)
message_end()
}