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

Solved [CSGO] How to prevent reloading if you have too much ammo


Post New Thread Reply   
 
Thread Tools Display Modes
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 01-13-2019 , 18:14   Re: [CSGO] How to prevent reloading if you have too much ammo
Reply With Quote #11

Quote:
Originally Posted by Bacardi View Post
In csgo, you not get weapon name from entity classname
I don't think that you are right because it prints to me 'Stop reloading...weapon - weapon_usp_silencer'

PHP Code:

if(WeaponMaxAmmo[WeaponArrayIndex] < CurrentAmmo

 
PrintToChat(client"Stop reloading...weapon - %s"classname); 
 return 
Plugin_Handled

I used to get weapon names through the classname always, and it worked fine, I'm sure.
impossible_cc is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 01-13-2019 , 18:29   Re: [CSGO] How to prevent reloading if you have too much ammo
Reply With Quote #12

That is the best result I could achieve for now. But not perfect anyways.
PHP Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>

#define WEAPONS_MAX 34

char WeaponList[WEAPONS_MAX][] = 
{
    
// pistols
    
"weapon_deagle",        // 0
    
"weapon_elite",            // 1
    
"weapon_fiveseven",        // 2
    
"weapon_glock",            // 3
    
"weapon_cz75a",            // 4
    
"weapon_p250",            // 5
    
"weapon_hkp2000",        // 6
    
"weapon_revolver",        // 7
    
"weapon_tec9",            // 8
    
"weapon_usp_silencer",    // 9
    // shotguns
    
"weapon_xm1014",        // 10
    
"weapon_mag7",            // 11
    
"weapon_nova",            // 12
    
"weapon_sawedoff",        // 13
    // smg    
    
"weapon_mac10",            // 14
    
"weapon_p90",            // 15
    
"weapon_ump45",            // 16
    
"weapon_mp7",            // 17
    
"weapon_mp9",            // 18
    
"weapon_bizon",            // 19
    // nice guns
    
"weapon_ak47",            // 20
    
"weapon_aug",            // 21
    
"weapon_famas",            // 22
    
"weapon_galilar",        // 23
    
"weapon_m4a1",            // 24
    
"weapon_m4a1_silencer",    // 25
    
"weapon_sg556",            // 26
    // snipers
    
"weapon_awp",            // 27
    
"weapon_g3sg1",            // 28
    
"weapon_scar20",        // 29
    
"weapon_ssg08",            // 30
    // machineguns            
    
"weapon_m249",            // 31
    
"weapon_negev",            // 32
    //added later :)
    
"weapon_mp5sd"            // 33
};


int WeaponMaxAmmo[WEAPONS_MAX] =
{
    
7,        //0"weapon_deagle",    
    
30,        //1"weapon_elite",        
    
20,        //2"weapon_fiveseven",        
    
20,        //3"weapon_glock",            
    
12,        //4"weapon_cz75a",            
    
13,        //5"weapon_p250",            
    
13,        //6"weapon_hkp2000",        
    
8,        //7"weapon_revolver",    
    
18,        //8"weapon_tec9",            
    
12,        //9"weapon_usp_silencer",    
    
7,        //10"weapon_xm1014",        
    
5,        //11"weapon_mag7",            
    
8,        //12"weapon_nova",            
    
7,        //"weapon_sawedoff",13        
    
30,        //"weapon_mac10",        14    
    
50,        //"weapon_p90",            15
    
25,        //"weapon_ump45",        16
    
30,        //"weapon_mp7",        17
    
30,        //"weapon_mp9",            18
    
64,        //"weapon_bizon",        19
    
30,        //"weapon_ak47",        20
    
30,        //"weapon_aug",21
    
25,        //"weapon_famas",22        
    
35,        //"weapon_galilar",23    
    
30,        //"weapon_m4a1",    24        
    
20,        //"weapon_m4a1_silencer",25
    
30,        //"weapon_sg556",        26
    
10,        //"weapon_awp",        27
    
20,        //"weapon_g3sg1",        28
    
20,        //"weapon_scar20",        29
    
10,        //"weapon_ssg08",            30
    
100,    //"weapon_m249",            31
    
150,    //"weapon_negev"            32
    
30        //"weapon_mp5sd"            33
};

char classname[32];
public 
Action OnPlayerRunCmd(int clientintbuttonsintimpulsefloat vel[3], float angles[3], intweaponintsubtypeintcmdnuminttickcountintseedint mouse[2])
{
    if(
buttons IN_RELOAD)
    {
        
int WeaponIndex GetEntPropEnt(clientProp_Data"m_hActiveWeapon");
        if(
IsValidEdict(WeaponIndex))
        {
            
int CurrentAmmo GetEntProp(WeaponIndexProp_Send"m_iClip1");
            if(
CurrentAmmo 0)
            {
                
GetClientWeapon(clientclassname32);
                if(!
StrEqual(classname"weapon_knife"))
                {
                    
int WeaponArrayIndex = -1;
                    for(
int i 0WEAPONS_MAXi++)
                    {
                        if(
StrEqual(classnameWeaponList[i]))
                        {
                            
WeaponArrayIndex i;
                            break;
                        }
                    }
                    if(
WeaponArrayIndex != -1)
                    {
                        if(
WeaponMaxAmmo[WeaponArrayIndex] < CurrentAmmo)
                        {
                            
buttons ^= IN_RELOAD;
                            return 
Plugin_Changed;
                        }
                    }
                    else
                    {
                        
LogError("Unknown weapon - %s"classname);
                    }
                }
            }
        }
    }
    return 
Plugin_Continue;

impossible_cc is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-14-2019 , 02:57   Re: [CSGO] How to prevent reloading if you have too much ammo
Reply With Quote #13

PHP Code:
public Action OnPlayerRunCmd(int clientintbuttonsintimpulsefloat vel[3], float angles[3], intweaponintsubtypeintcmdnuminttickcountintseedint mouse[2])
{
    if(
buttons IN_RELOAD)
    {
        
buttons &= ~IN_RELOAD;
        
    }
    return 
Plugin_Continue;

test

Last edited by Bacardi; 01-14-2019 at 04:35.
Bacardi is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 01-14-2019 , 07:10   Re: [CSGO] How to prevent reloading if you have too much ammo
Reply With Quote #14

Thank you very much, I will stay with your version.
Btw
PHP Code:
^= 
always equals to

PHP Code:
&= ~
impossible_cc is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 01-16-2019 , 09:49   Re: [CSGO] How to prevent reloading if you have too much ammo
Reply With Quote #15

Quote:
Originally Posted by impossible_cc View Post
Thank you very much, I will stay with your version.
Btw
PHP Code:
^= 
always equals to

PHP Code:
&= ~
I'm wrong, it is equal only if b is like (1 << 0) or (1<<1) (1<<15) etc..
impossible_cc is offline
Reply


Thread Tools
Display Modes

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 07:34.


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