View Single Post
JoaoRodrigoGamer
Junior Member
Join Date: Jul 2019
Location: Portugal
Old 08-23-2019 , 06:57   Re: [CSGO] Fetch client's weapons, grenades, etc...
Reply With Quote #28

Quote:
Originally Posted by Ilusion9 View Post
PHP Code:

stock bool HasWeapon
(int client, const char[] weapon)
{
    
int length GetEntPropArraySize(clientProp_Send"m_hMyWeapons"); 
     
    for (
int i0lengthi++)  
    {  
        
int item GetEntPropEnt(clientProp_Send"m_hMyWeapons"i);  

        if (
item != -1)  
        {  
            
char classname[64]; 
            
            if (
GetEntityClassname(itemclassnamesizeof(classname)))
            {
                if (
StrEqual(weaponclassnamefalse))
                {
                    return 
true;
                }
            }
        }  
    } 

    return 
false;
}

if (
HasWeapon(client"weapon_healthshot"))
{
    
// do something

I just tested your code with this plugin and it seems to be working just fine

Also, I used this simple plugin to test your code:
PHP Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR ""
#define PLUGIN_VERSION "0.00"

#include <sourcemod>
#include <sdktools>

#pragma newdecls required

public Plugin myinfo 
{
    
name "",
    
author PLUGIN_AUTHOR,
    
description "",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_check"check);
}

public 
Action check(int clientint agrs)
{
    if (
HasWeapon(client"weapon_healthshot")) 
    { 
        
PrintCenterText(client"Has healthshot");
    }
    else
    {
        
PrintCenterText(client"Does not have a healthshot");
    }
}

stock bool HasWeapon(int client, const char[] weapon

    
int length GetEntPropArraySize(clientProp_Send"m_hMyWeapons");  
      
    for (
int i0lengthi++)   
    {   
        
int item GetEntPropEnt(clientProp_Send"m_hMyWeapons"i);   

        if (
item != -1)   
        {   
            
char classname[64];  
             
            if (
GetEntityClassname(itemclassnamesizeof(classname))) 
            { 
                if (
StrEqual(weaponclassnamefalse)) 
                { 
                    return 
true
                } 
            } 
        }   
    }  

    return 
false

JoaoRodrigoGamer is offline