View Single Post
Franc1sco
Veteran Member
Join Date: Oct 2010
Location: Spain (Madrid)
Old 06-10-2020 , 11:52   Re: [CS:GO] Auto strip extra knives
Reply With Quote #6

This in your current plugin will delete tasers since it share the same weapon slot than knives
PHP Code:
public void RemoveExtraKnives(int client)
{
    
int weapon GetPlayerWeaponSlot(client2);
       while (
weapon!= -1)
       {
        
RemovePlayerItem(clientweapon);
        
weapon GetPlayerWeaponSlot(client2);
    }
        
GivePlayerItem(client"weapon_knife");

I made this code that should works better and without issues. It just remove extra knives when it necessary.
PHP Code:
public void RemoveExtraKnives(int client)
{
    
int size GetEntPropArraySize(clientProp_Send"m_hMyWeapons");
    
bool haveKnife false;
    
    for (
int i 0sizei++) // run for all the weapons that player have
    
{
        
int weapon GetEntPropEnt(clientProp_Send"m_hMyWeapons"i);
        if (
IsValidEdict(weapon) && IsValidEntity(weapon))
        {
            
char weaponClass[64];
            if (!
GetEdictClassname(weaponweaponClasssizeof(weaponClass)))continue; // if invalid entity then continue
            
            
if(StrContains(weaponClass"weapon_knife"false) == || StrContains(weaponClass"weapon_bayonet"false) == 0// knife entity
            
{
                if(
haveKnife// player already have knife and this is other knife?
                
{
                    
// delete extra knife because he only need one
                    
RemovePlayerItem(clientweapon);
                    
AcceptEntityInput(weapon"Kill");
                }
                
haveKnife true// set that player have knife
            
}
            
        }
    }        


Also I recommend you to have the plugins in a github repository like I have, for allow others to make pulls requests for improve plugins if they want and for see the code changes easily. Cheers
__________________
Veteran Coder -> Activity channel
Coding on CS2 and taking paid and free jobs.

Contact: Steam, Telegram or discord ( franug ).

You like my work? +Rep in my steam profile comments or donate.


Last edited by Franc1sco; 06-10-2020 at 12:08.
Franc1sco is offline
Send a message via MSN to Franc1sco