Ha! I can prove you wrong. Yes, I must say that Ham_Deploy is called when you pickup a weapon. However! However there is a big problem with this. First of all, there are case scenarios with plugins automatically forcing player to drop the weapon or switch it back, once Deploy is called (for example knife round situations, or custom restricted weapons, or vip plugins, or anything what you can think of). Therefor protection is crusual for this, so we wont have errors and/or even possibility of server crashes. Anyway, I think we all shall agree that in this post function situations this protections are needed. However when getting a weapon, and automatically switching to it - Deploy protection fails (not fails, it works, but not all pdata/pev_owner conditions are set right instantly). Therefor in order for protection against errors/crashes to remain I simply must use AddPlayerItem function. And to prove it not only by words, here is the same code what plugin uses (same protection, same everything), with only difference of printing to chat whenever function is called, and whenever it passes the protection code.
PHP Code:
/**
*
* Fast Sniper Switch (Awp Fast Switch)
* by Numb
*
*
* Description:
* This plugins brings back the old feature from CS1.5 times.
* You were able to shoot a bullet with awp or scout, switch to
* knife or any other weapon really fast, and then switch back again.
* In result you get that you can fire your next bullet faster than
* if you would have waited for original bullet 'reload'.
*
*
* Requires:
* FakeMeta
* HamSandWich
*
*
* Additional Info:
* Tested in Counter-Strike 1.6 with amxmodx 1.8.1.
*
*
* ChangeLog:
*
* + 1.1
* - Changed: Support for quake-style-switch plugin no longer needed (removed).
*
* + 1.0
* - First release.
*
*
* Downloads:
* Amx Mod X forums: http://forums.alliedmods.net/showthread.php?p=1193990#post1193990
*
**/
// ----------------------------------------- CONFIG START -----------------------------------------
// delay for awp fast switch (in cs1.5 it was 0.75 like any other weapon)
#define AWP_SWITCH_DELAY 0.75 // default: 0.75
// delay for scout fast switch (in cs1.5 it was 0.75 like any other weapon)
#define SCOUT_SWITCH_DELAY 0.75 // default: 0.75
// ------------------------------------------ CONFIG END ------------------------------------------
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN_NAME "Fast Sniper Switch"
#define PLUGIN_VERSION "1.1"
#define PLUGIN_AUTHOR "Numb"
#define PDWeaponType 43
#define WPNNextPrimAttack 46
#define WPNNextSecAttack 47
#define WPNSwitchedAt 76
#define PDNextAttack 83
#define PDActiveItem 373
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
RegisterHam(Ham_Item_Deploy, "weapon_awp", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_Item_Deploy, "weapon_scout", "Ham_Item_Deploy_Post", 1);
RegisterHam(Ham_AddPlayerItem, "player", "Ham_AddPlayerItem_Post", 1);
}
public Ham_AddPlayerItem_Post(iPlrId, iEnt)
{
client_print(0, print_chat, "Ham_AddPlayerItem");
if( !is_user_alive(iPlrId) )
return HAM_IGNORED;
if( !pev_valid(iEnt) )
return HAM_IGNORED;
if( iEnt!=get_pdata_cbase(iPlrId, PDActiveItem, 5) )
return HAM_IGNORED;
new iWpnType = get_pdata_int(iEnt, PDWeaponType, 4);
if( iWpnType!=CSW_AWP && iWpnType!=CSW_SCOUT )
return HAM_IGNORED;
client_print(0, print_chat, "Ham_AddPlayerItem after protection");
if( get_pdata_float(iEnt, WPNNextSecAttack, 4)==1.0 && get_pdata_float(iEnt, WPNSwitchedAt, 4)==get_gametime() )
{
new iAnimationId = pev(iPlrId, pev_weaponanim);
new Float:fPlrNextAttack = get_pdata_float(iPlrId, PDNextAttack, 5);
new Float:fGunNextPAttack = get_pdata_float(iEnt, WPNNextPrimAttack, 4);
if( iWpnType==CSW_AWP && iAnimationId==5 && fPlrNextAttack==1.45 && fGunNextPAttack==1.45 )
{
set_pdata_float(iEnt, WPNNextPrimAttack, AWP_SWITCH_DELAY, 4);
set_pdata_float(iEnt, WPNNextSecAttack, AWP_SWITCH_DELAY, 4);
set_pdata_float(iPlrId, PDNextAttack, AWP_SWITCH_DELAY, 5);
}
else if( iWpnType==CSW_SCOUT && iAnimationId==4 && fPlrNextAttack==1.25 && fGunNextPAttack==1.25 )
{
set_pdata_float(iEnt, WPNNextPrimAttack, SCOUT_SWITCH_DELAY, 4);
set_pdata_float(iEnt, WPNNextSecAttack, SCOUT_SWITCH_DELAY, 4);
set_pdata_float(iPlrId, PDNextAttack, SCOUT_SWITCH_DELAY, 5);
}
}
return HAM_IGNORED;
}
public Ham_Item_Deploy_Post(iEnt)
{
client_print(0, print_chat, "Ham_Deploy");
if( !pev_valid(iEnt) )
return HAM_IGNORED;
new iPlrId = pev(iEnt, pev_owner);
if( !is_user_alive(iPlrId) )
return HAM_IGNORED;
if( iEnt!=get_pdata_cbase(iPlrId, PDActiveItem, 5) )
return HAM_IGNORED;
client_print(0, print_chat, "Ham_Deploy after protection");
switch( get_pdata_int(iEnt, PDWeaponType, 4) )
{
case CSW_AWP:
{
set_pdata_float(iEnt, WPNNextPrimAttack, AWP_SWITCH_DELAY, 4);
set_pdata_float(iEnt, WPNNextSecAttack, AWP_SWITCH_DELAY, 4);
set_pdata_float(iPlrId, PDNextAttack, AWP_SWITCH_DELAY, 5);
}
case CSW_SCOUT:
{
set_pdata_float(iEnt, WPNNextPrimAttack, SCOUT_SWITCH_DELAY, 4);
set_pdata_float(iEnt, WPNNextSecAttack, SCOUT_SWITCH_DELAY, 4);
set_pdata_float(iPlrId, PDNextAttack, SCOUT_SWITCH_DELAY, 5);
}
}
return HAM_IGNORED;
}
Here are results what I get when switching weapon manually:
Code:
Ham_Deploy
Ham_Deploy after protection
And here are results what I get when I pickup or buy a weapon, or when I give it to myself by fun.inc give_item() or FM_Touch or Ham_Touch:
Code:
Ham_Deploy
Ham_AddPlayerItem
Ham_AddPlayerItem after protection
You can clearly see that code does not pass the error/crash protection point on Deploy function whenever it's called by getting a new weapon. If you don't trust me - try it out for yourself.
Well, it took sometime to prove that I overlook more possible conditions and case scenarios than expected, but I like that you guys are doing your job as plugin approvers.
Though I must say that we both shall agree that eventually it did take some time.
Just please, don't make me rewrite protection code, just to remove AddPlayerItem function - to find perfect puzzle of how hl engine executes what functions for this case scenario it took me 2-3 days to safely say that:
1. It does work.
2. It is stable.
3. There is no risk in mistakes/errors/crashes.
__________________