/**
*
* Quake Style Switch
* by Numb
*
*
* Description:
* This plugins brings back the old feature from CS1.5 times. When you
* switch between your weapons really fast - you don't see the switch animation.
*
*
* Requires:
* FakeMeta
* HamSandWich
*
*
* Additional Info:
* + Tested in Counter-Strike 1.6 with amxmodx 1.8.2 (dev build hg21).
*
*
* Notes:
* I couldn't repeat the 'random' fast-switch glitch, cause I honestly just
* don't know how it works. So instead I made it so it would work when you
* switch fast enough (by default 750ms and that is 0.75sec)
*
*
* ChangeLog:
*
* + 1.3
* - Changed: Plugin uses less resources.
* - Fixed: Plugin wont crash the server if you use custom weapons. However their animations may not match.
*
* + 1.2
* - Fixed: Error when SWITCH_DELAY is set to 0 (when quake-style-switch is valid always).
* - Fixed: Plugin not working when picking up weapons.
*
* + 1.1
* - Fixed: Usp had wrong fast-switch (idle) animation glitches while shield was in place.
*
* + 1.0
* - First release.
*
*
* Downloads:
* Amx Mod X forums: http://forums.alliedmods.net/showthread.php?p=1193942#post1193942
*
**/
// ----------------------------------------- CONFIG START -----------------------------------------
// How fast in ms you have to switch between weapons for fast-switch to work (set to 0 for "always")
#define SWITCH_DELAY 750 // default: 750
/*
BBk
www.facebook.com/groups/deathoflegend
*/
// ------------------------------------------ CONFIG END ------------------------------------------
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN_NAME "Fegyvervaltas animacio nelkul"
#define PLUGIN_VERSION "1.3"
#define PLUGIN_AUTHOR "Numb"
#define m_pPlayer 41 // (weapon_*) owner entity
#define m_iId 43 // (weapon_*) type of weapon CSW_
#define m_bSilencerOn 74 // (weapon_*) in what state weapon is on
#define m_flDecreaseShotsFired 76 // (weapon_*) ??? right after Deploy has same value as get_gametime()
#define WPN_STATE_USP_SILEN (1<<0)
#define WPN_STATE_M4A1_SILEN (1<<2)
#define m_pActiveItem 373 // (player) active weapon
#define PDShieldState 510 // (player) some extra information about the player
#define SHIELD_STATE_EXISTS (1<<24)
#if SWITCH_DELAY > 0
new Float:g_fLastSwitched[33];
new Float:g_fSwitchDelay;
#endif
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
RegisterHam(Ham_Item_Deploy, "weapon_knife", "Ham_Item_Deploy_Post", 1); // I know, using event CurWeapon looks better,
RegisterHam(Ham_Item_Deploy, "weapon_glock18", "Ham_Item_Deploy_Post", 1); // but this one doesn't loop. Plus in CurWeapon
RegisterHam(Ham_Item_Deploy, "weapon_usp", "Ham_Item_Deploy_Post", 1); // event last send info may be not "active",
RegisterHam(Ham_Item_Deploy, "weapon_deagle", "Ham_Item_Deploy_Post", 1); // so animation won't work in that case.
RegisterHam(Ham_Item_Deploy, "weapon_p228", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_elite", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_fiveseven", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_m3", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_xm1014", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_mp5navy", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_mac10", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_tmp", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_p90", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_ump45", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_galil", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_famas", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_ak47", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_m4a1", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_sg552", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_aug", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_g3sg1", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_sg550", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_scout", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_awp", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_m249", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_hegrenade", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_flashbang", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_smokegrenade", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_c4", "Ham_Item_Deploy_Post", 1);
#if SWITCH_DELAY > 0
g_fSwitchDelay = (float(SWITCH_DELAY)*0.001); // I don't want to do this function each time someone switches weapons (saving CPU)
#endif
}
#if SWITCH_DELAY > 0
public client_connect(iPlrId)
g_fLastSwitched[iPlrId] = 0.0; // reset time of last switch
#endif
public Ham_Item_Deploy_Post(iEnt)
{
if( !pev_valid(iEnt) ) // it is possible honestly (I had errors cause of ignoring it - other plugins and/or engine...)
return HAM_IGNORED;
new iPlrId = get_pdata_cbase(iEnt, m_pPlayer, 4); // same here
if( !is_user_alive(iPlrId) )
return HAM_IGNORED;
if( iEnt!=get_pdata_cbase(iPlrId, m_pActiveItem, 5) ) // some other plugin can silently change weapons
return HAM_IGNORED;
weapon_switched(iPlrId, iEnt, get_pdata_int(iEnt, m_iId, 4)); // we are now sure that weapons are switched
return HAM_IGNORED;
}
public weapon_switched(iPlrId, iEnt, iWpnType)
{
#if SWITCH_DELAY > 0
new Float:fGameTime = get_gametime();
if( get_pdata_float(iEnt, m_flDecreaseShotsFired, 4)==fGameTime ) // did player really switched weapons _NOW_?
{
if( g_fLastSwitched[iPlrId]>fGameTime ) // check time - should this switch be quake-style-switch ?
configurate_switch(iPlrId, iWpnType, iEnt);
g_fLastSwitched[iPlrId] = (fGameTime+g_fSwitchDelay);
}
#else
if( get_pdata_float(iEnt, m_flDecreaseShotsFired, 4)==get_gametime() ) // did player really switched weapons _NOW_?
configurate_switch(iPlrId, iWpnType, iEnt);
#endif
}
configurate_switch(iPlrId, iWpnType, iEnt) // and here is the part where we change the animation
{
message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, iPlrId); // I also use msg cause of ping reasons
switch( iWpnType ) // I need this for usp and m4a1 silencer support
{
case CSW_USP: write_byte_and_set_anim(iPlrId, iEnt, true);
case CSW_M4A1: write_byte_and_set_anim(iPlrId, iEnt);
default: write_byte_and_set_anim(iPlrId); // all other weapons (don't blame me if custom weapon animations wont match)
}
write_byte(pev(iPlrId, pev_body));
message_end();
}
write_byte_and_set_anim(iPlrId, iEnt=0, bool:bIsWeaponUsp=false) // so lets find out what animation id we need
{
if( iEnt ) // player switched to usp or m4a1
{
if( bIsWeaponUsp ) // player switched to usp
{
if( iEnt && (get_pdata_int(iEnt, m_bSilencerOn, 4)&WPN_STATE_USP_SILEN || get_pdata_int(iPlrId, PDShieldState, 5)&SHIELD_STATE_EXISTS) )
{
write_byte(0);
set_pev(iPlrId, pev_weaponanim, 0); // so it silenced and there is no shield
}
else
{
write_byte(8);
set_pev(iPlrId, pev_weaponanim, 8); // there's a shield or it's not silenced
}
}
else // player switched to m4a1
{
if( iEnt && get_pdata_int(iEnt, m_bSilencerOn, 4)&WPN_STATE_M4A1_SILEN ) // so is it silenced
{
write_byte(0);
set_pev(iPlrId, pev_weaponanim, 0);
}
else // or is it...
{
write_byte(7);
set_pev(iPlrId, pev_weaponanim, 7);
}
}
}
else // just pass the idle animation and leave me alone about the "ow, but my custom pink bazooka has a wrong animation (cry)..." - I must say, I really don't care.
{
write_byte(0);
set_pev(iPlrId, pev_weaponanim, 0)
}
}