Raised This Month: $51 Target: $400
 12% 

Real Weapon Drop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
666
Senior Member
Join Date: Mar 2015
Old 04-07-2019 , 14:49   Real Weapon Drop
Reply With Quote #1

I'm using this add-on works fine, I just want to add it:

1) when a player buys 1 weapon and if he has a weapon, for example if he has a m4a1 and buys an awp, the m4a1 is dropped perpendicular downwards as in the image, and so it happens with all the weapons except the c4


PHP Code:
/**
 *
 * Real Weapon Drop
 *  by Numb
 *
 *
 * Description:
 *  This plugin introduces into the game more features related to dropped weapons. Features
 *  such as:
 *  + Ability to drop weapons up and down - where you aim, in that direction weapon will be
 *   thrown.
 *  + Ability to manually drop grenades.
 *  + Drop all weapons at death. Including grenades and a special box of ammunition.
 *  + Drop all weapons on disconnect. Including grenades and a special box of ammunition.
 *  + Barrel of dropped weapons is always facing in the same direction as player was looking.
 *
 *
 * Requires:
 *  FakeMeta
 *  HamSandWich
 *
 *
 * Cvars:
 *
 *  + "rwd_aimdrop" - Counter-Strike:Source style manual weapon drop.
 *  - "1" - enabled. [default]
 *  - "0" - disabled.
 *
 *  + "rwd_grenadedrop" - ability to manually drop grenades.
 *  - "1" - enabled. [default]
 *  - "0" - disabled.
 *
 *  + "rwd_deathdrop" - drop all weapons on death.
 *  - "1" - enabled. [default]
 *  - "0" - disabled.
 *
 *  + "rwd_disconnectdrop" - drop all weapons on disconnect.
 *  - "1" - enabled. [default]
 *  - "0" - disabled.
 *
 *  + "rwd_modelanglefix[/U]" - barrel of the weapon angle fix.
 *  - "1" - enabled. [default]
 *  - "0" - disabled.
 *
 *
 * Additional info:
 *  Tested in Counter-Strike 1.6 with amxmodx 1.8.2. Various features can be enabled and
 *  disabled via cvars. This plugin also has support VIP objectives and grenade trail
 *  plugins.
 *
 *
 * Notes:
 *  Barrel of dropped weapons may be facing in wrong direction if client is using custom
 *  weapon models.
 *
 *
 * WARNINGS:
 *  In some cases pausing this plugin may lead to glitches, therefor if when needed please
 *  use cvars instead. That is if paused in certain moments by other plugins. Manual pauses
 *  won't do much harm, except dropped flashes will fill up your flashbang slot to maximum,
 *  and ammunition box will be touchable only once.
 *
 *
 * Credits:
 *  Special thanks to Arkshine ( http://forums.alliedmods.net/member.php?u=7779 ) for
 *  Counter-Strike SDK ( https://github.com/Arkshine/CSSDK/ ) and big help what he have
 *  provided by delivering very useful information! Also big thanks goes to eDark for
 *  calculation functions!
 *
 *
 * Change-Log:
 *
 *  + 2.3
 *  - Fixed: Crash at mapchange if there's too many players and other entities.
 *  - Changed: More reliability when saving number of dropped bullets and flash grenades.
 *
 *  + 2.2
 *  - Fixed: VIPs drop all their weapons on escape.
 *  - Changed: Minor performance improvement.
 *
 *  + 2.1
 *  - Changed: Minor performance improvement.
 *
 *  + 2.0
 *  - Fixed: Grenades do not bounce insane when dropped.
 *  - Fixed: VIPs can't no longer pick-up ammunition.
 *  - Fixed: VIPs also do drop their weapons if have any.
 *  - Changed: Full plugin rewrite - plugin is now much more stable.
 *
 *  + 1.4
 *  - Fixed: "grenade bounce for ever" by adding gravitation level manually. // had issues
 *
 *  + 1.3
 *  - Fixed: Explode grenade on death if it's not armed.
 *  - Added: Grenade drop.
 *
 *  + 1.2
 *  - Fixed: Due to bug in standard ArrayDeleteItem(Array:which, item) native I created my
 *   own working one.
 *
 *  + 1.1
 *  - Changed: (code) Modified array clear (less cpu usage - I think).
 *  - Changed: (code) Entity scan (less cpu usage).
 *  - Changed: (code) Unneeded data getting from array - removed (less cpu usage).
 *
 *  + 1.0
 *  - First release.
 *
 *
 * Downloads:
 *  Amx Mod X forums: http://forums.alliedmods.net/showthread.php?p=619788#post619788
 *
**/

//#define FAST_METHOD // saves AllocString value at mapstart, but isn't as reliable

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN_NAME    "Real Weapon Drop"
#define PLUGIN_VERSION    "2.3"
#define PLUGIN_AUTHOR    "Numb"

#define AMMO_MODEL "models/w_357ammobox.mdl"
#define AMMO_SOUND "items/9mmclip2.wav"

#define SetPlayerBit(%1,%2)    ( %1 |=  ( 1 << ( %2 & 31 ) ) )
#define ClearPlayerBit(%1,%2)  ( %1 &= ~( 1 << ( %2 & 31 ) ) )
#define CheckPlayerBit(%1,%2)  ( %1 &   ( 1 << ( %2 & 31 ) ) )

// "weapon_" entity
#define m_flStartThrow 30
#define m_pPlayer 41
#define m_iId 43
#define m_flTimeWeaponIdle 48

// "player" entity
#define m_bIsVIP 209
#define m_pActiveItem 373
#define m_rgAmmo_player 376
#define FLAG_VIP (1<<8)

// "weaponbox" entity
#define m_rgpPlayerItems 34
#define m_rgiszAmmo 41
#define m_rgAmmo 73
#define AMMO_FLASHBANG 11
#define AMMO_HEGRENADE 12
#define AMMO_SMOKENADE 13

new g_iBulletsDropped[33][15];
#if defined FAST_METHOD
new m_rgiszAmmoNames[15];
#endif
new g_iMaxPlayers;
new 
g_iConnected;
new 
g_iAlive;

new 
g_iMsgId_AmmoPickup;
new 
g_iMsgId_WeapPickup;

new 
g_iCvar_AimDrop;
new 
g_iCvar_GrenadeDrop;
new 
g_iCvar_DeathDrop;
new 
g_iCvar_DisconnectDrop;
new 
g_iCvar_ModelAngleFix;

new 
g_bInAutoDrop;
new 
HamHook:g_iHamHook_Think;
new 
g_iHamHook_Active;
new 
g_iDeathDrops[33][29];
new 
g_iDeathDropsNum[33];
new 
Float:g_fPlayerAngle[33];
new 
bool:g_bVipDrop;
new 
bool:g_bChangingMap;

new 
g_iAmmoNames[15][] = {
    
"",
    
"338Magnum"// awp
    
"762Nato"// ak47 scout g3sg1
    
"556NatoBox"// m249
    
"556Nato"// aug m4a1 sgg550 sgg552 galil famas
    
"buckshot"// m3 xm1014
    
"45ACP"// mac10 usp ump45
    
"57mm"// p90 fiveseven
    
"50AE"// deagle
    
"357SIG"// p228
    
"9mm"// glock elites mp5navy tmp
    
"Flashbang",
    
"HEGrenade",
    
"SmokeGrenade",
    
"C4"
};

new 
g_iAmmoEntityNames[15][] = {
    
"",
    
"ammo_338magnum"// awp
    
"ammo_762nato"// ak47 scout g3sg1
    
"ammo_556natobox"// m249
    
"ammo_556nato"// aug m4a1 sgg550 sgg552 galil famas
    
"ammo_buckshot"// m3 xm1014
    
"ammo_45acp"// mac10 usp ump45
    
"ammo_57mm"// p90 fiveseven
    
"ammo_50ae"// deagle
    
"ammo_357sig"// p228
    
"ammo_9mm"// glock elites mp5navy tmp
    
"weapon_flashbang",
    
"weapon_hegrenade",
    
"weapon_smokegenade",
    
"weapon_c4"
};

new 
g_iMaxAmmo[15] = {
    
0,
    
30,
    
90,
    
200,
    
90,
    
32,
    
100,
    
100,
    
35,
    
52,
    
120,
    
2,
    
1,
    
1,
    
1
};

public 
plugin_init()
{
    
register_plugin(PLUGIN_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR);
    
    
register_event("30""Event_MapChangeScoreboard""a");
    
    
register_forward(FM_ClientDisconnect"FM_ClientDisconnect_Pre"0);
    
register_forward(FM_SetModel,         "FM_SetModel_Pre",         0);
    
    
RegisterHam(Ham_Spawn,           "player",              "Ham_Spawn_Player_Post",  1);
    
RegisterHam(Ham_Killed,          "player",              "Ham_Killed_player_Pre",  0);
    
RegisterHam(Ham_Killed,          "player",              "Ham_Killed_player_Post"1);
    
RegisterHam(Ham_CS_Item_CanDrop"weapon_hegrenade",    "Ham_Item_CanDrop_Pre",   0);
    
RegisterHam(Ham_CS_Item_CanDrop"weapon_flashbang",    "Ham_Item_CanDrop_Pre",   0);
    
RegisterHam(Ham_CS_Item_CanDrop"weapon_smokegrenade""Ham_Item_CanDrop_Pre",   0);
    
RegisterHam(Ham_CS_Item_CanDrop"weapon_knife",        "Ham_Item_CanDrop_Pre",   0);
    
RegisterHam(Ham_Touch,           "weaponbox",           "Ham_Touch_wpnbox_Pre",   0);
    
RegisterHam(Ham_Touch,           "func_vip_safetyzone""Ham_Touch_safezone_Pre"0);
    
    
g_iHamHook_Think RegisterHam(Ham_Think"player""Ham_Think_player_Pre"0);
    
DisableHamForward(g_iHamHook_Think);
    
    
g_iCvar_AimDrop        register_cvar("rwd_aimdrop""1");
    
g_iCvar_GrenadeDrop    register_cvar("rwd_grenadedrop""1");
    
g_iCvar_DeathDrop      register_cvar("rwd_deathdrop""1");
    
g_iCvar_DisconnectDrop register_cvar("rwd_disconnectdrop""1");
    
g_iCvar_ModelAngleFix  register_cvar("rwd_modelanglefix""1");
    
    
g_iMaxPlayers clamp(get_maxplayers(), 132);
    
#if defined FAST_METHOD
    
for( new iLoop=1iLoop<15iLoop++ )
        
m_rgiszAmmoNames[iLoop] = engfunc(EngFunc_AllocStringg_iAmmoNames[iLoop]);
#endif
    
    
g_iMsgId_AmmoPickup get_user_msgid("AmmoPickup");
    
g_iMsgId_WeapPickup get_user_msgid("WeapPickup");
}

public 
plugin_precache()
{
    
precache_model(AMMO_MODEL);
    
precache_sound(AMMO_SOUND);
}

public 
plugin_unpause()
{
    
g_iConnected 0;
    
g_iAlive 0;
    
    for( new 
iPlrId=1iPlrId<=g_iMaxPlayersiPlrId++ )
    {
        if( 
is_user_alive(iPlrId) )
        {
            
SetPlayerBit(g_iConnectediPlrId);
            
SetPlayerBit(g_iAliveiPlrId);
        }
        else if( 
is_user_connected(iPlrId) )
            
SetPlayerBit(g_iConnectediPlrId);
    }
}

public 
client_connect(iPlrId)
{
    
ClearPlayerBit(g_iAliveiPlrId);
    
ClearPlayerBit(g_iConnectediPlrId);
}

public 
client_putinserver(iPlrId)
    
SetPlayerBit(g_iConnectediPlrId);

public 
Event_MapChangeScoreboard()
    
g_bChangingMap true;

public 
Message_AmmoPickup(iMsgIdiMsgTypeiPlrId// modify given ammo on hud when needed
{
    static 
s_iAmmoNum;
    
s_iAmmoNum g_iBulletsDropped[iPlrId][get_msg_arg_int(1)];
    if( 
s_iAmmoNum )
        
set_msg_arg_int(2ARG_BYTEs_iAmmoNum);
}

public 
Message_Block(iMsgIdiMsgTypeiPlrId// block ammo and weaponpickup hud update when needed
    
return PLUGIN_HANDLED;

public 
FM_ClientDisconnect_Pre(iPlrId)
{
    
ClearPlayerBit(g_iConnectediPlrId);
    
ClearPlayerBit(g_iAliveiPlrId);
    
ClearPlayerBit(g_iHamHook_ActiveiPlrId);
    
    if( 
get_pcvar_num(g_iCvar_DisconnectDrop) )
    {
        static 
s_iVip;
        
s_iVip get_pdata_int(iPlrIdm_bIsVIP5);
        
set_pdata_int(iPlrIdm_bIsVIP, (s_iVip&~FLAG_VIP), 5);
        
force_weapon_drop(iPlrId00);
        
set_pdata_int(iPlrIdm_bIsVIPs_iVip5);
    }
}

public 
FM_SetModel_Pre(iEntiModel[])
{
    if( !
equal(iModel"models/w_"9) )
        return 
FMRES_IGNORED;
    
    if( 
equal(iModel[9], "weaponbox.mdl") ) // this weaponbox isn't yet ready to be worked with
        
return FMRES_IGNORED;
    
    static 
s_iClassName[11];
    
pev(iEntpev_classnames_iClassName10);
    
    if( 
equal(s_iClassName"weaponbox") ) // is this a weaponbox with what we can work
    
{
        static 
s_iOwnerFloat:s_fVelocity[3], s_bAliveFloat:s_fAngle[3];
        
s_iOwner pev(iEntpev_owner);
        if( 
0<s_iOwner<=g_iMaxPlayers )
            
s_bAlive = (CheckPlayerBit(g_iAlives_iOwner)?true:false);
        else
            
s_bAlive false;
        
        if( 
s_bAlive && !g_bVipDrop // alive user dropped weapons
        
{
            if( 
get_pcvar_num(g_iCvar_AimDrop) ) // should we change drop direction via player by aim
            
{
                static 
Float:s_fOrigin[3], Float:s_fResult[3];
                
pev(s_iOwnerpev_origins_fOrigin);
                
pev(s_iOwnerpev_v_angles_fAngle);
                
SphereToCartesian(s_fResults_fOrigins_fAngleFloat:{0.00.0200.0}); // some extraterrestrial math by eDark
                
pev(s_iOwnerpev_velocitys_fVelocity);
                
s_fVelocity[0] += (s_fResult[0]-s_fOrigin[0]);
                
s_fVelocity[1] += (s_fResult[1]-s_fOrigin[1]);
                
s_fVelocity[2] -= (s_fResult[2]-s_fOrigin[2]);
                
set_pev(iEntpev_velocitys_fVelocity);
            }
        }
        else if( 
is_player_connected(s_iOwner) ) // weapon is dropped due to death
        
{
            if( 
get_pcvar_num(g_iCvar_DeathDrop) )
            {
                if( 
CheckPlayerBit(g_iHamHook_Actives_iOwner) && 0<=g_iDeathDropsNum[s_iOwner] && g_iDeathDropsNum[s_iOwner]<29 )
                {
                    
g_iDeathDrops[s_iOwner][g_iDeathDropsNum[s_iOwner]] = iEnt// sometimes not all the weapons have speed set right,
                    
g_iDeathDropsNum[s_iOwner]++; // therefor we'll set their speed to again, when we'll be sure it's right
                    
                    
s_fVelocity Float:{0.00.00.0};
                }
                else
                    
pev(s_iOwnerpev_velocitys_fVelocity);
                    
                
s_fVelocity[0] += random_float(-10.010.0);
                
s_fVelocity[1] += random_float(-10.010.0);
                
s_fVelocity[2] += random_float(-5.05.0);
                
set_pev(iEntpev_velocitys_fVelocity);
            }
        }
        else if( 
get_pcvar_num(g_iCvar_DisconnectDrop) ) // weapon is dropped due to disconnect
        
{
            
s_fVelocity Float:{0.00.00.0};
            
s_fVelocity[0] = random_float(-10.010.0);
            
s_fVelocity[1] = random_float(-10.010.0);
            
s_fVelocity[2] = random_float(-5.05.0);
            
set_pev(iEntpev_velocitys_fVelocity);
        }
        
        if( 
0<s_iOwner<=g_iMaxPlayers // should we work a bit more with the weaponbox
        
{
            if( !
s_bAlive )
            {
                
pev(iEntpev_angless_fAngle);
                
s_fAngle[1] = g_fPlayerAngle[s_iOwner];
                
set_pev(iEntpev_angless_fAngle);
            }
            
            if( 
equal(iModel[9], "flashbang.mdl") ) // this weaponbox includes information about flash grenade
            
{
#if defined FAST_METHOD
                
set_pdata_int(iEnt, (m_rgiszAmmo+AMMO_FLASHBANG), m_rgiszAmmoNames[AMMO_FLASHBANG], 4);
#else
                
set_pdata_int(iEnt, (m_rgiszAmmo+AMMO_FLASHBANG), engfunc(EngFunc_AllocStringg_iAmmoNames[AMMO_FLASHBANG]), 4);
#endif
                
if( s_bAlive )
                {
                    
set_pdata_int(iEnt, (m_rgAmmo+AMMO_FLASHBANG), 14); // not working (glitch with grenades)
                    
if( g_iBulletsDropped[s_iOwner][AMMO_FLASHBANG]>)
                    {
                        static 
s_iFwdMsg_AmmoPickups_iFwdMsg_WeapPickup;
                        
s_iFwdMsg_AmmoPickup register_message(g_iMsgId_AmmoPickup"Message_Block");
                        
s_iFwdMsg_WeapPickup register_message(g_iMsgId_WeapPickup"Message_Block");
                        
                        
ham_give_item(s_iOwner"weapon_flashbang");
                        
set_pdata_int(s_iOwner, (m_rgAmmo_player+AMMO_FLASHBANG), g_iBulletsDropped[s_iOwner][AMMO_FLASHBANG], 5);
                        
engclient_cmd(s_iOwner"weapon_flashbang");
                        
                        
unregister_message(g_iMsgId_AmmoPickups_iFwdMsg_AmmoPickup);
                        
unregister_message(g_iMsgId_WeapPickups_iFwdMsg_WeapPickup);
                    }
                }
                else
                    
set_pdata_int(iEnt, (m_rgAmmo+AMMO_FLASHBANG), g_iBulletsDropped[s_iOwner][AMMO_FLASHBANG], 4); // not working (glitch with grenades)
                
                
message_begin(MSG_ALLSVC_TEMPENTITY__); // yep, lets include support for grenade trail plugin
                
write_byte(TE_KILLBEAM);
                
write_short(iEnt);
                
message_end();
            }
            else if( 
equal(iModel[9], "hegrenade.mdl") ) // this weaponbox includes information about he grenade
            
{
                
message_begin(MSG_ALLSVC_TEMPENTITY__); // yep, lets include support for grenade trail plugin
                
write_byte(TE_KILLBEAM);
                
write_short(iEnt);
                
message_end();
                
                
pev(iEntpev_angless_fAngle);
                
s_fAngle[1] += 90.0;
                
set_pev(iEntpev_angless_fAngle);
            }
            else if( 
equal(iModel[9], "smokegrenade.mdl") ) // this weaponbox includes information about smoke grenade
            
{
                
message_begin(MSG_ALLSVC_TEMPENTITY__); // yep, lets include support for grenade trail plugin
                
write_byte(TE_KILLBEAM);
                
write_short(iEnt);
                
message_end();
                
                
pev(iEntpev_angless_fAngle);
                
s_fAngle[1] += 45.0;
                
set_pev(iEntpev_angless_fAngle);
            }
            else if( 
equal(iModel[9], "knife.mdl") ) // dropped knife - lets set bullets info into it
            
{
                
pev(iEntpev_angless_fAngle);
                
s_fAngle[1] += 180.0;
                
set_pev(iEntpev_angless_fAngle);
                
                static 
s_iLoop;
                for( 
s_iLoop=1s_iLoop<11s_iLoop++ )
                {
#if defined FAST_METHOD
                    
set_pdata_int(iEnt, (m_rgiszAmmo+s_iLoop), m_rgiszAmmoNames[s_iLoop], 4);
#else
                    
set_pdata_int(iEnt, (m_rgiszAmmo+s_iLoop), engfunc(EngFunc_AllocStringg_iAmmoNames[s_iLoop]), 4);
#endif
                    
set_pdata_int(iEnt, (m_rgAmmo+s_iLoop), g_iBulletsDropped[s_iOwner][s_iLoop], 4);
                }
                
                
engfunc(EngFunc_SetModeliEntAMMO_MODEL); // and change model to custom one of course
                
return FMRES_SUPERCEDE;
            }
            else if( 
get_pcvar_num(g_iCvar_ModelAngleFix) ) // lets fix angle of the weaponbox model
            
{
                
pev(iEntpev_angless_fAngle);
                
                if( 
equal(iModel[9], "glock18.mdl") )
                    
s_fAngle[1] -= 110.0;
                else if( 
equal(iModel[9], "usp.mdl") )
                    
s_fAngle[1] -= 65.0;
                else if( 
equal(iModel[9], "deagle.mdl") )
                    
s_fAngle[1] -= 110.0;
                else if( 
equal(iModel[9], "p228.mdl") )
                    
s_fAngle[1] -= 60.0;
                else if( 
equal(iModel[9], "elite.mdl") )
                    
s_fAngle[1] -= 180.0;
                else if( 
equal(iModel[9], "fiveseven.mdl") )
                    
s_fAngle[1] -= 50.0;
                else if( 
equal(iModel[9], "m3.mdl") )
                    
s_fAngle[1] -= 125.0;
                else if( 
equal(iModel[9], "xm1014.mdl") )
                    
s_fAngle[1] -= 5.0;
                else if( 
equal(iModel[9], "mp5.mdl") )
                    
s_fAngle[1] += 10.0;
                else if( 
equal(iModel[9], "tmp.mdl") ) // mac10 has a perfect angle - no need to fix
                    
s_fAngle[1] -= 135.0;
                else if( 
equal(iModel[9], "p90.mdl") )
                    
s_fAngle[1] -= 125.0;
                else if( 
equal(iModel[9], "ump45.mdl") )
                    
s_fAngle[1] -= 70.0;
                else if( 
equal(iModel[9], "galil.mdl") )
                    
s_fAngle[1] += 15.0;
                else if( 
equal(iModel[9], "famas.mdl") )
                    
s_fAngle[1] -= 30.0;
                else if( 
equal(iModel[9], "ak47.mdl") )
                    
s_fAngle[1] -= 105.0;
                else if( 
equal(iModel[9], "m4a1.mdl") )
                    
s_fAngle[1] -= 60.0;
                else if( 
equal(iModel[9], "sg552.mdl") )
                    
s_fAngle[1] -= 130.0;
                else if( 
equal(iModel[9], "aug.mdl") )
                    
s_fAngle[1] -= 125.0;
                else if( 
equal(iModel[9], "scout.mdl") )
                    
s_fAngle[1] -= 70.0;
                else if( 
equal(iModel[9], "awp.mdl") )
                    
s_fAngle[1] -= 110.0;
                else if( 
equal(iModel[9], "g3sg1.mdl") )
                    
s_fAngle[1] -= 110.0;
                else if( 
equal(iModel[9], "sg550.mdl") )
                    
s_fAngle[1] -= 115.0;
                else if( 
equal(iModel[9], "m249.mdl") )
                    
s_fAngle[1] -= 95.0;
                
                
set_pev(iEntpev_angless_fAngle);
            }
        }
    }
    
    return 
FMRES_IGNORED;
}

public 
Ham_Spawn_Player_Post(iPlrId)
{
    if( 
is_user_alive(iPlrId) )
        
SetPlayerBit(g_iAliveiPlrId);
    else
        
ClearPlayerBit(g_iAliveiPlrId);
}

public 
Ham_Killed_player_Pre(iPlrIdiAttackerIdiShouldGib)
{
    
g_iDeathDropsNum[iPlrId] = 0;
    if( !
g_iHamHook_Active )
        
EnableHamForward(g_iHamHook_Think);
    
SetPlayerBit(g_iHamHook_ActiveiPlrId);
    
    if( 
get_pcvar_num(g_iCvar_DeathDrop) )
    {
        static 
s_iArmedGrenades_iWeaponType;
        
s_iArmedGrenade get_pdata_cbase(iPlrIdm_pActiveItem5);
        if( 
s_iArmedGrenade>&& pev_valid(s_iArmedGrenade) )
        {
            
s_iWeaponType get_pdata_int(s_iArmedGrenadem_iId4);
            if( 
s_iWeaponType==CSW_FLASHBANG || s_iWeaponType==CSW_HEGRENADE || s_iWeaponType==CSW_SMOKEGRENADE )
            {
                if( 
get_pdata_float(s_iArmedGrenadem_flStartThrow3) && get_pdata_float(s_iArmedGrenadem_flTimeWeaponIdle4)<=0.0 )
                    
s_iArmedGrenade s_iWeaponType// a grenade is ready to explode - save information what grenade it is
                
else
                    
s_iArmedGrenade 0;
            }
            else
                
s_iArmedGrenade 0;
        }
        else
        {
            
s_iWeaponType 0;
            
s_iArmedGrenade 0;
        }
        
        static 
s_iVip;
        
s_iVip get_pdata_int(iPlrIdm_bIsVIP5);
        
set_pdata_int(iPlrIdm_bIsVIP, (s_iVip&~FLAG_VIP), 5);
        
force_weapon_drop(iPlrIds_iArmedGrenades_iWeaponType);
        
set_pdata_int(iPlrIdm_bIsVIPs_iVip5);
    }
}

public 
Ham_Killed_player_Post(iPlrIdiAttackerIdiShouldGib)
{
    if( 
is_user_alive(iPlrId) )
        
SetPlayerBit(g_iAliveiPlrId);
    else
        
ClearPlayerBit(g_iAliveiPlrId);
}

public 
Ham_Think_player_Pre(iPlrId)
{
    if( 
g_iDeathDropsNum[iPlrId] )
    {
        static 
Float:s_fVelocity[3];
        
pev(iPlrIdpev_velocitys_fVelocity);
        
        static 
s_iDeathDropss_iEnt;
        for( 
s_iDeathDrops=0s_iDeathDrops<g_iDeathDropsNum[iPlrId]; s_iDeathDrops++ )
        {
            
s_iEnt g_iDeathDrops[iPlrId][s_iDeathDrops];
            if( 
s_iEnt>&& pev_valid(s_iEnt) )
                
set_pev(s_iEntpev_velocitys_fVelocity);
        }
    }
    
    
ClearPlayerBit(g_iHamHook_ActiveiPlrId);
    if( !
g_iHamHook_Active )
        
DisableHamForward(g_iHamHook_Think);
}

public 
Ham_Touch_safezone_Pre(iEntiPlrId)
{
    if( 
iPlrId>&& iPlrId<=g_iMaxPlayers )
    {
        static 
s_iVip;
        
s_iVip get_pdata_int(iPlrIdm_bIsVIP5);
        if( 
s_iVip&FLAG_VIP )
        {
            
g_bVipDrop true;
            
set_pdata_int(iPlrIdm_bIsVIP, (s_iVip&~FLAG_VIP), 5);
            
force_weapon_drop(iPlrId00);
            
set_pdata_int(iPlrIdm_bIsVIPs_iVip5);
            
g_bVipDrop false;
        }
    }
}

public 
Ham_Item_CanDrop_Pre(iEnt// allow drop of various items when needed
{
    if( 
g_bInAutoDrop )
        
SetHamReturnInteger(1);
    else if( 
get_pcvar_num(g_iCvar_GrenadeDrop) )
    {
        static 
s_iOwner;
        
s_iOwner get_pdata_cbase(iEntm_pPlayer4);
        
        if( 
0<s_iOwner<=g_iMaxPlayers )
        {
            if( 
get_pdata_int(s_iOwnerm_bIsVIP5)&FLAG_VIP // yep, if somehow VIP gets a grenade, don't allow it to be dropped
                
return HAM_IGNORED;
            
            static 
s_iWeaponType;
            
s_iWeaponType get_pdata_int(iEntm_iId4);
            
            if( 
s_iWeaponType==CSW_KNIFE )
                return 
HAM_IGNORED// yep, don't allow manual drop of knife
            
else if( s_iWeaponType==CSW_FLASHBANG )
                
g_iBulletsDropped[s_iOwner][AMMO_FLASHBANG] = (clamp(get_pdata_int(s_iOwner, (m_rgAmmo_player+AMMO_FLASHBANG), 5), 12)-1);
            
SetHamReturnInteger(1);
        }
        else
            return 
HAM_IGNORED;
    }
    else
        return 
HAM_IGNORED;
    
    return 
HAM_OVERRIDE;
}

public 
Ham_Touch_wpnbox_Pre(iEntiPlrId// when weaponbox is touched
{
    if( 
0<iPlrId<=g_iMaxPlayers )
    {
        if( 
get_pdata_int(iPlrIdm_bIsVIP5)&FLAG_VIP || ~pev(iEntpev_flags)&FL_ONGROUND // weaponbox can have an effect on the player
            
return HAM_SUPERCEDE;
        
        static 
s_iBoxAmmos_iUserAmmo;
        if( (
s_iBoxAmmo=get_pdata_int(iEnt, (m_rgAmmo+AMMO_FLASHBANG), 4))>// weaponbox has flashbang information inside
        
{
            if( (
s_iUserAmmo=get_pdata_int(iPlrId, (m_rgAmmo_player+AMMO_FLASHBANG), 5))>=)
                return 
HAM_SUPERCEDE;
            else if( (
s_iUserAmmo<=&& s_iBoxAmmo>=2) )
            {
                
ham_give_item(iPlrId"weapon_flashbang");
                
ham_give_item(iPlrId"weapon_flashbang");
                
                
emit_sound(iPlrIdCHAN_ITEM"items/gunpickup2.wav"VOL_NORMATTN_NORM0PITCH_NORM);
                
emit_sound(iPlrIdCHAN_ITEM"items/9mmclip1.wav"VOL_NORMATTN_NORM0PITCH_NORM);
            
                
set_pev(iEntpev_solidSOLID_NOT);
                
set_pev(iEntpev_effectsEF_NODRAW);
                
dllfunc(DLLFunc_ThinkiEnt);
                
                return 
HAM_SUPERCEDE;
            }
            else if( (
s_iUserAmmo==&& s_iBoxAmmo==1) )
            {
                
ham_give_item(iPlrId"weapon_flashbang");
                
                
emit_sound(iPlrIdCHAN_ITEM"items/9mmclip1.wav"VOL_NORMATTN_NORM0PITCH_NORM);
            
                
set_pev(iEntpev_solidSOLID_NOT);
                
set_pev(iEntpev_effectsEF_NODRAW);
                
dllfunc(DLLFunc_ThinkiEnt);
                
                return 
HAM_SUPERCEDE;
            }
            else if( 
s_iUserAmmo==&& s_iBoxAmmo>=)
            {
                
set_pdata_int(iEnt, (m_rgAmmo+AMMO_FLASHBANG), (s_iBoxAmmo-1), 4);
                
ham_give_item(iPlrId"weapon_flashbang");
                
                
emit_sound(iPlrIdCHAN_ITEM"items/9mmclip1.wav"VOL_NORMATTN_NORM0PITCH_NORM);
                
                return 
HAM_SUPERCEDE;
            }
            else if( 
s_iUserAmmo<=&& ham_give_item(iPlrId"weapon_flashbang")>)
            {
                
emit_sound(iPlrIdCHAN_ITEM"items/gunpickup2.wav"VOL_NORMATTN_NORM0PITCH_NORM);
                
                
set_pev(iEntpev_solidSOLID_NOT);
                
set_pev(iEntpev_effectsEF_NODRAW);
                
dllfunc(DLLFunc_ThinkiEnt);
                
                return 
HAM_SUPERCEDE;
            }
            
            return 
HAM_IGNORED;
        }
        else 
// now check for actual bullets
        
{
            static 
s_iTemp;
            
s_iTemp get_pdata_cbase(iEnt, (m_rgpPlayerItems+3), 4);
            
            if( 
s_iTemp>&& pev_valid(s_iTemp) )
            {
                if( 
get_pdata_int(s_iTempm_iId4)==CSW_KNIFE // check passed - this weaponbox should include information about the bullets
                
{
                    static 
s_iFwdMsg_AmmoPickup;
                    
s_iFwdMsg_AmmoPickup register_message(g_iMsgId_AmmoPickup"Message_AmmoPickup"); // yes, we'll have to edit hud value
                    
                    
g_iBulletsDropped[0][0] = g_iBulletsDropped[iPlrId][0] = 0;
                    for( 
s_iTemp=1s_iTemp<11s_iTemp++ )
                    {
                        if( (
s_iBoxAmmo=get_pdata_int(iEnt, (m_rgAmmo+s_iTemp), 4))>)
                        {
                            if( (
s_iUserAmmo=clamp(get_pdata_int(iPlrId, (m_rgAmmo_player+s_iTemp), 5), 0g_iMaxAmmo[s_iTemp]))>=g_iMaxAmmo[s_iTemp] )
                                
g_iBulletsDropped[0][0] = 1// weaponbox still has ammo - don't remove the entity
                            
else
                            {
                                if( (
s_iUserAmmo+s_iBoxAmmo)<=g_iMaxAmmo[s_iTemp] )
                                {
                                    
g_iBulletsDropped[iPlrId][s_iTemp] = s_iBoxAmmo;
                                    
s_iUserAmmo += s_iBoxAmmo;
                                    
set_pdata_int(iEnt, (m_rgAmmo+s_iTemp), 04);
                                }
                                else
                                {
                                    
g_iBulletsDropped[0][0] = 1// weaponbox still has ammo - don't remove the entity
                                    
                                    
g_iBulletsDropped[iPlrId][s_iTemp] = (g_iMaxAmmo[s_iTemp]-s_iUserAmmo);
                                    
s_iUserAmmo g_iMaxAmmo[s_iTemp];
                                    
set_pdata_int(iEnt, (m_rgAmmo+s_iTemp), (s_iBoxAmmo-g_iBulletsDropped[iPlrId][s_iTemp]), 4);
                                }
                                
g_iBulletsDropped[iPlrId][0] += g_iBulletsDropped[iPlrId][s_iTemp]; // we need to save that some bullets were given
                                
                                
fm_give_item(iPlrIdg_iAmmoEntityNames[s_iTemp]); // we must give ammo this way, else weapon
                                
set_pdata_int(iPlrId, (m_rgAmmo_player+s_iTemp), s_iUserAmmo5); // wont be able to reload
                            
}
                        }
                    }
                    
unregister_message(g_iMsgId_AmmoPickups_iFwdMsg_AmmoPickup);
                    
                    if( 
g_iBulletsDropped[iPlrId][0] ) // bullets were given - emit bullet pick-up sound
                        
emit_sound(iPlrIdCHAN_ITEMAMMO_SOUNDVOL_NORMATTN_NORM0PITCH_NORM);
                    
                    if( !
g_iBulletsDropped[0][0] ) // weaponbox has no more ammo - remove it
                    
{
                        
set_pev(iEntpev_solidSOLID_NOT);
                        
set_pev(iEntpev_effectsEF_NODRAW);
                        
dllfunc(DLLFunc_ThinkiEnt);
                    }
                    
                    return 
HAM_SUPERCEDE;
                }
            }
        }
    }
    
    return 
HAM_IGNORED;
}

force_weapon_drop(iPlrIdiArmedGrenadeiWeaponType)
{
    if( 
g_bChangingMap )
        return;
    
    
g_bInAutoDrop true// allow death drop of grenades and knife
    
    
static s_iUserWeaponsFloat:s_fAngle[3];
    
s_iUserWeapons pev(iPlrIdpev_weapons);
    
pev(iPlrIdpev_v_angles_fAngle);
    
g_fPlayerAngle[iPlrId] = s_fAngle[1];
    
    if( 
iArmedGrenade!=CSW_HEGRENADE && get_pdata_int(iPlrId, (m_rgAmmo_player+AMMO_HEGRENADE), 5)>)
        
engclient_cmd(iPlrId"drop""weapon_hegrenade");
    
    if( (
g_iBulletsDropped[iPlrId][AMMO_FLASHBANG]=(clamp(get_pdata_int(iPlrId, (m_rgAmmo_player+AMMO_FLASHBANG), 5), 02)-((iArmedGrenade==CSW_FLASHBANG)?1:0)))>)
    {
        
engclient_cmd(iPlrId"drop""weapon_flashbang");
        
        if( 
iArmedGrenade==CSW_FLASHBANG // oh, ya, by dropping one flash, we disarm the other one, so we have to bypass it
        
{
            
set_pdata_int(iPlrId, (m_rgAmmo_player+AMMO_FLASHBANG), 15); // just to be on the safe side, in case user had more than 2 flashes
            
iArmedGrenade ham_give_item(iPlrId"weapon_flashbang");
            
set_pdata_int(iPlrId, (m_rgAmmo_player+AMMO_FLASHBANG), 15); // if magically user doesn't die, let him have one flash (not two)
            
            
if( iArmedGrenade>&& pev_valid(iArmedGrenade) )
            {
                
set_pdata_cbase(iPlrIdm_pActiveItemiArmedGrenade5); // yep, lets set it to be the active item
                
set_pdata_float(iArmedGrenadem_flStartThrow1.03); // now arm the grenade, so at death it'll be dropped
                
set_pdata_float(iArmedGrenadem_flTimeWeaponIdle, -0.0014);
            }
            
iArmedGrenade 0;
        }
    }
    
    if( 
iArmedGrenade!=CSW_SMOKEGRENADE && get_pdata_int(iPlrId, (m_rgAmmo_player+AMMO_SMOKENADE), 5)>)
        
engclient_cmd(iPlrId"drop""weapon_smokegrenade");
    
    static 
s_iLoop;
    
g_iBulletsDropped[iPlrId][0] = 0// this will be higher, if player has any bullets at all
    
for( s_iLoop=1s_iLoop<11s_iLoop++ ) // yep, here we get information of specific bullet types
    
{
        
g_iBulletsDropped[iPlrId][s_iLoop] = clamp(get_pdata_int(iPlrId, (m_rgAmmo_player+s_iLoop), 5), 0g_iMaxAmmo[s_iLoop]);
        
set_pdata_int(iPlrId, (m_rgAmmo_player+s_iLoop), 05);
        
g_iBulletsDropped[iPlrId][0] += g_iBulletsDropped[iPlrId][s_iLoop];
    
    }
    
    if( 
g_iBulletsDropped[iPlrId][0] ) // if player has any bullets at all
    
{
        if( ~
s_iUserWeapons&(1<<CSW_KNIFE) ) // if user has no knife - give one
            
ham_give_item(iPlrId"weapon_knife");
        
engclient_cmd(iPlrId"drop""weapon_knife");
        
ham_give_item(iPlrId"weapon_knife"); // after dropping the knife, to be safe, lets give 1 knife back
    
}
    
    
g_bInAutoDrop false// disallow death drop of grenades and knife
    
    
if( s_iUserWeapons&(1<<CSW_P228) && iWeaponType!=CSW_P228 // just drop all the weapons
        
engclient_cmd(iPlrId"drop""weapon_p228");
    if( 
s_iUserWeapons&(1<<CSW_SCOUT) && iWeaponType!=CSW_SCOUT )
        
engclient_cmd(iPlrId"drop""weapon_scout");
    if( 
s_iUserWeapons&(1<<CSW_XM1014) && iWeaponType!=CSW_XM1014 )
        
engclient_cmd(iPlrId"drop""weapon_xm1014");
    if( 
s_iUserWeapons&(1<<CSW_MAC10) && iWeaponType!=CSW_MAC10 )
        
engclient_cmd(iPlrId"drop""weapon_mac10");
    if( 
s_iUserWeapons&(1<<CSW_AUG) && iWeaponType!=CSW_AUG )
        
engclient_cmd(iPlrId"drop""weapon_aug");
    if( 
s_iUserWeapons&(1<<CSW_ELITE) && iWeaponType!=CSW_ELITE )
        
engclient_cmd(iPlrId"drop""weapon_elite");
    if( 
s_iUserWeapons&(1<<CSW_FIVESEVEN) && iWeaponType!=CSW_FIVESEVEN )
        
engclient_cmd(iPlrId"drop""weapon_fiveseven");
    if( 
s_iUserWeapons&(1<<CSW_UMP45) && iWeaponType!=CSW_UMP45 )
        
engclient_cmd(iPlrId"drop""weapon_ump45");
    if( 
s_iUserWeapons&(1<<CSW_SG550) && iWeaponType!=CSW_SG550 )
        
engclient_cmd(iPlrId"drop""weapon_sg550");
    if( 
s_iUserWeapons&(1<<CSW_GALIL) && iWeaponType!=CSW_GALIL )
        
engclient_cmd(iPlrId"drop""weapon_galil");
    if( 
s_iUserWeapons&(1<<CSW_FAMAS) && iWeaponType!=CSW_FAMAS )
        
engclient_cmd(iPlrId"drop""weapon_famas");
    if( 
s_iUserWeapons&(1<<CSW_USP) && iWeaponType!=CSW_USP )
        
engclient_cmd(iPlrId"drop""weapon_usp");
    if( 
s_iUserWeapons&(1<<CSW_GLOCK18) && iWeaponType!=CSW_GLOCK18 )
        
engclient_cmd(iPlrId"drop""weapon_glock18");
    if( 
s_iUserWeapons&(1<<CSW_AWP) && iWeaponType!=CSW_AWP )
        
engclient_cmd(iPlrId"drop""weapon_awp");
    if( 
s_iUserWeapons&(1<<CSW_MP5NAVY) && iWeaponType!=CSW_MP5NAVY )
        
engclient_cmd(iPlrId"drop""weapon_mp5navy");
    if( 
s_iUserWeapons&(1<<CSW_M249) && iWeaponType!=CSW_M249 )
        
engclient_cmd(iPlrId"drop""weapon_m249");
    if( 
s_iUserWeapons&(1<<CSW_M3) && iWeaponType!=CSW_M3 )
        
engclient_cmd(iPlrId"drop""weapon_m3");
    if( 
s_iUserWeapons&(1<<CSW_M4A1) && iWeaponType!=CSW_M4A1 )
        
engclient_cmd(iPlrId"drop""weapon_m4a1");
    if( 
s_iUserWeapons&(1<<CSW_TMP) && iWeaponType!=CSW_TMP )
        
engclient_cmd(iPlrId"drop""weapon_tmp");
    if( 
s_iUserWeapons&(1<<CSW_G3SG1) && iWeaponType!=CSW_G3SG1 )
        
engclient_cmd(iPlrId"drop""weapon_g3sg1");
    if( 
s_iUserWeapons&(1<<CSW_DEAGLE) && iWeaponType!=CSW_DEAGLE )
        
engclient_cmd(iPlrId"drop""weapon_deagle");
    if( 
s_iUserWeapons&(1<<CSW_SG552) && iWeaponType!=CSW_SG552 )
        
engclient_cmd(iPlrId"drop""weapon_sg552");
    if( 
s_iUserWeapons&(1<<CSW_AK47) && iWeaponType!=CSW_AK47 )
        
engclient_cmd(iPlrId"drop""weapon_ak47");
    if( 
s_iUserWeapons&(1<<CSW_P90) && iWeaponType!=CSW_P90 )
        
engclient_cmd(iPlrId"drop""weapon_p90");
    if( 
s_iUserWeapons&(1<<CSW_C4) && iWeaponType!=CSW_C4 )
        
engclient_cmd(iPlrId"drop""weapon_c4");
}

ham_give_item(iPlrIdiClassName[]) // ham fowrad is useful, cause it doesn't emit no item sound
{
    new 
iEnt engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocStringiClassName));
    if( 
iEnt<=|| !pev_valid(iEnt) )
        return 
0;
    
    
set_pev(iEntpev_spawnflagsSF_NORESPAWN);
    
dllfunc(DLLFunc_SpawniEnt);
    
    if( 
ExecuteHamB(Ham_AddPlayerItemiPlrIdiEnt) )
    {
        
ExecuteHamB(Ham_Item_AttachToPlayeriEntiPlrId);
        return 
iEnt;
    }
    
    if( 
pev_valid(iEnt) )
        
set_pev(iEntpev_flags, (pev(iEntpev_flags)|FL_KILLME));
    
    return -
1;
}

fm_give_item(iPlrIdiClassName[]) // fakemeta forward is useful, cause it can be used with ammo_ items
{
    new 
iEnt engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocStringiClassName));
    if( !
pev_valid(iEnt) )
        return 
0;
    
    
set_pev(iEntpev_spawnflags, (pev(iEntpev_spawnflags)|SF_NORESPAWN));
    
dllfunc(DLLFunc_SpawniEnt);
    
    new 
iSolidType pev(iEntpev_solid);
    
dllfunc(DLLFunc_TouchiEntiPlrId);
    if( 
pev(iEntpev_solid)!=iSolidType )
        return 
iEnt;
    
    
set_pev(iEntpev_flags, (pev(iEntpev_flags)|FL_KILLME));
    
    return -
1;
}

bool:is_player_connected(iPlrId)
{
    if( 
0<iPlrId<=g_iMaxPlayers )
    {
        if( 
CheckPlayerBit(g_iConnectediPlrId) )
            return 
true;
    }
    
    return 
false;
}

bool:SphereToCartesian(Float:fDest[3], Float:fOrigin[3], Float:fView[3], Float:fAngle[3])
{
    
fView[1] *= (M_PI/180.0); // and now angle[0] and angle[1] has no effect?
    
fView[0] *= (M_PI/180.0); // yes, this code is eDarks, so I don't remember why I added that comment above
    
    
fAngle[0] *= (M_PI/-180.0);
    
fAngle[1] *= (M_PI/180.0);
    
    static 
Float:s_fSin0Float:s_fCos0Float:s_fSin1Float:s_fCos1;
    
s_fSin0 floatsin((fAngle[0]+(M_PI*0.5)), radian);
    
    
fDest[0] = fAngle[2]*s_fSin0*floatcos(fAngle[1], radian);
    
fDest[1] = fAngle[2]*s_fSin0*floatsin(fAngle[1], radian);
    
fDest[2] = fAngle[2]*floatcos((fAngle[0]+(M_PI*0.5)), radian);
    
    
    
s_fSin0 floatsin(fView[0], radian);
    
s_fCos0 floatcos(fView[0], radian);
    
s_fSin1 floatsin(fView[1], radian);
    
s_fCos1 floatcos(fView[1], radian);
    
    static 
Float:s_fTemp[3];
    
s_fTemp[0] = (fDest[0]*s_fCos0*s_fCos1)-(fDest[1]*s_fSin1)+(fDest[2]*s_fSin0*s_fCos1);
    
s_fTemp[1] = (fDest[0]*s_fCos0*s_fSin1)+(fDest[1]*s_fCos1)+(fDest[2]*s_fSin1*s_fSin0);
    
s_fTemp[2] = (fDest[2]*s_fCos0)-(fDest[0]*s_fSin0);
    
    
fDest[0] = (fOrigin[0]+s_fTemp[0]);
    
fDest[1] = (fOrigin[1]+s_fTemp[1]);
    
fDest[2] = (fOrigin[2]-s_fTemp[2]);
    
    return 
true;

__________________
666 is offline
Old 04-08-2019, 14:13
HiDeath
This message has been deleted by HiDeath.
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode