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

[HL2MP ]How to know when a player is reloading


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Master53
Veteran Member
Join Date: Dec 2009
Old 12-02-2010 , 13:27   [HL2MP ]How to know when a player is reloading
Reply With Quote #1

this shows you when a player is reloadnig the current weapon in there hand. you need to put "IsReloading(Weapon)" on a timer or hook "IN_RELOAD" to see if the player is reloading or not

PHP Code:
stock bool:IsReloading(Weapon)
{

    
//Valid Weapon:
    
if(Weapon != -1)
    {

        
//Declare
        
new ReloadOffset GetEntProp(WeaponProp_Data"m_bInReload");

        
//Not Reloading:
        
if(ReloadOffset == 1)
        {

            
//Return:
            
return true;
        }
    }

    
//Return:
    
return false;
}

stock bool:IsValidWeapon(Client)
{

    
//Declare:
    
decl String:WeaponName[32];

    
//Initialize:
    
GetClientWeapon(ClientWeaponNamesizeof(WeaponName));


    
//Valid Weapon:
    
if((StrEqual(WeaponName"weapon_crowbar") || StrEqual(WeaponName"weapon_stunstick")))
    {

        
//Return:
        
return false;
    }

    
//Return:
    
return true;
}

stock HasClientWeapon(Client)

{


    
//Declare
    
new Offset FindSendPropOffs("CBasePlayer""m_hMyWeapons");

    new 
MaxGuns 256;



    
//Loop:
    
for(new 0MaxGuns= (4))

    {


        
//Declare:
        
new WeaponId GetEntDataEnt2(ClientOffset X);


        
//Valid Weapon:
        
if(WeaponId 0)

        {


            
//Declare:
            
decl String:ClassName[32], String:WeaponName[32];


            
//Initialize:
            
GetClientWeapon(ClientWeaponNamesizeof(WeaponName));
            
GetEdictClassname(WeaponIdClassNamesizeof(ClassName));


            
//Valid Weapon:
            
if(IsValidWeapon(Client) == true)
            {
                
//Is Current Weapon:
                
if(StrEqual(WeaponNameClassName))

                {


                    
//Return:
                    
return WeaponId;

                }
            }

        }

    }

    
//Return:
    
return -1;


__________________
Master(d)




Last edited by Master53; 12-03-2010 at 19:36.
Master53 is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 12-02-2010 , 15:57   Re: [HL2MP ]How to know when a player is reloading
Reply With Quote #2

HasClientWeapon returning an weapon index -> bad coding style.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Master53
Veteran Member
Join Date: Dec 2009
Old 12-02-2010 , 16:19   Re: [HL2MP ]How to know when a player is reloading
Reply With Quote #3

tbf yea but it works i didnt really standalone it i just took it out a plugin i was making and i was hooking player reloading so...
__________________
Master(d)



Master53 is offline
Master53
Veteran Member
Join Date: Dec 2009
Old 12-02-2010 , 17:23   Re: [HL2MP ]How to know when a player is reloading
Reply With Quote #4

should i add all game sopport?
__________________
Master(d)



Master53 is offline
javalia
Senior Member
Join Date: May 2009
Location: korea, republic of
Old 12-03-2010 , 12:50   Re: [HL2MP ]How to know when a player is reloading
Reply With Quote #5

change "CHL2MP_Player"to "CBasePlayer" to make it work with all games heheh
__________________
javalia is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 12-04-2010 , 04:32   Re: [HL2MP ]How to know when a player is reloading
Reply With Quote #6

Besides, HL2MP didn't have autoreload last time I checked.
OnPlayerRunCmd => button & IN_RELOAD should be sufficient.

This would be useful for games like TF2, like the examples in the Scripting forum, where you got this from.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 12-04-2010 , 09:07   Re: [HL2MP ]How to know when a player is reloading
Reply With Quote #7

Quote:
Originally Posted by Monkeys View Post
OnPlayerRunCmd => button & IN_RELOAD should be sufficient.
Pressing reload with full clip.
__________________
FaTony is offline
Master53
Veteran Member
Join Date: Dec 2009
Old 12-06-2010 , 12:18   Re: [HL2MP ]How to know when a player is reloading
Reply With Quote #8

Quote:
Originally Posted by FaTony View Post
Pressing reload with full clip.
yes i also found this out to. but unlick css where you have "player_reload" this can actually detect when the player reloads even if the gun automaticly reloads without pressing "IN_RELOAD"
__________________
Master(d)



Master53 is offline
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 08:45.


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