Raised This Month: $32 Target: $400
 8% 

Solved [CSGO] Fetch client's weapons, grenades, etc...


Post New Thread Reply   
 
Thread Tools Display Modes
JoaoRodrigoGamer
Junior Member
Join Date: Jul 2019
Location: Portugal
Old 08-23-2019 , 05:20   Re: [CSGO] Fetch client's weapons, grenades, etc...
Reply With Quote #21

Quote:
Originally Posted by ShD3luxe View Post
It looks like now it's listing all the weapons except for the healthshot . In what slot do you have the healthshot ? It should be on the 5 (the c4 slot). Try checking if the debug command is showing weapon_c4 if you have it on you.
On the chat debug it does not show the c4 but it takes and then gives it back to the player.

The health shot is not in the c4 slot but below it (see attachment).

Code:
僕の kill‎ : !test
[DEBUG] User weapon weapon_glock , weapon to check for : weapon_healthshot
[DEBUG] User weapon weapon_knife , weapon to check for : weapon_healthshot
[DEBUG] User weapon weapon_taser , weapon to check for : weapon_healthshot
[DEBUG] User weapon weapon_tagrenade , weapon to check for : weapon_healthshot
[DEBUG] User weapon weapon_hegrenade , weapon to check for : weapon_healthshot
[DEBUG] User weapon weapon_flashbang , weapon to check for : weapon_healthshot
Quote:
Originally Posted by ShD3luxe View Post
If you want to limit the user to just one healthshot(per round) use the cvar :


ammo_item_limit_healthshot 1
I could do that but then, the script would be giving extra health shots and those would be dropped on the floor.

Quote:
Originally Posted by ShD3luxe View Post
Also try just giving the item back to the player without equiping it:
PHP Code:
stock bool WeaponsClientHasWeapon(int client, const char weapon[32])
{
    
// Get all of client's current weapons.
    
int weapons[WeaponsSlot][WEAPONS_ON_SLOTS_MAX];
    
WeaponsGetClientWeapons(clientweapons);  
    
char classname[64];
    
    
// x = slot index
    
for (int x 0WEAPONS_SLOTS_MAXx++)
    {
        for(
int w 0;WEAPONS_ON_SLOTS_MAX;w++) 
        {
            
// If slot is empty or is 0(WORLD index) then stop.
            
if (weapons[x][w] <= 0
            {
                continue;
            }
                        
// Use the weapon index to get her name (weapon_...)
            
GetEdictClassname(weapons[x][w], classnamesizeof(classname));
            
// Now give the user item back 
            
GivePlayerItem(clientclassname);
            
// Debug for test
            
PrintToChat(client,"[DEBUG] User weapon %s , weapon to check for : %s",classname,weapon);
            
// If the weapon's classname matches, then return true.
            
if (StrEqual(weaponclassnamefalse))
            {
                return 
true;
            }
        }
    }   
    return 
false;

Not sure what you've changed, but now the grenades are being detected
Attached Images
File Type: jpg 20190823095809_1.jpg (34.8 KB, 28 views)
JoaoRodrigoGamer is offline
ShD3luxe
Member
Join Date: Aug 2019
Location: Localhost
Old 08-23-2019 , 05:38   Re: [CSGO] Fetch client's weapons, grenades, etc...
Reply With Quote #22

Try changing it to this :
PHP Code:
#define WEAPONS_SLOTS_MAX 6 // from 5 to 6

enum WeaponsSlot
{
    
Slot_Invalid        = -1,   /** Invalid weapon (slot). */
    
Slot_Primary        0,    /** Primary weapon slot. */
    
Slot_Secondary      1,    /** Secondary weapon slot. */
    
Slot_Melee          2,    /** Melee (knife) weapon slot. */
    
Slot_Projectile     3,    /** Projectile (grenades, flashbangs, etc) weapon slot. */
    
Slot_Explosive      4,    /** Explosive (c4) weapon slot. */
    
Slot_NVGs          5,    /** NVGs (fake) equipment slot. */ // and this new slot
}; 
Question : What key do you press to change to the healthshot ? 6? I'm not sure why but in the wiki it says that the healthshot is in the c4 slot (lol) .

Last edited by ShD3luxe; 08-23-2019 at 05:46.
ShD3luxe is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-23-2019 , 06:00   Re: [CSGO] Fetch client's weapons, grenades, etc...
Reply With Quote #23

Use this to check if a client has certain weapons

PHP Code:

    int size 
GetEntPropArraySize(clientProp_Send"m_hMyWeapons");
    
    for (
int i0m_hMyWeapons_sizei++) 
    { 
        
int item GetEntPropEnt(clientProp_Send"m_hMyWeapons"i); 

        if (
item != -1
        { 
            
char classname[64];
            
GetEntityClassname(itemclassnamesizeof(classname));
        } 
    } 
__________________

Last edited by Ilusion9; 08-23-2019 at 06:02.
Ilusion9 is offline
JoaoRodrigoGamer
Junior Member
Join Date: Jul 2019
Location: Portugal
Old 08-23-2019 , 06:13   Re: [CSGO] Fetch client's weapons, grenades, etc...
Reply With Quote #24

Quote:
Originally Posted by ShD3luxe View Post
Try changing it to this :
PHP Code:
#define WEAPONS_SLOTS_MAX 6 // from 5 to 6

enum WeaponsSlot
{
    
Slot_Invalid        = -1,   /** Invalid weapon (slot). */
    
Slot_Primary        0,    /** Primary weapon slot. */
    
Slot_Secondary      1,    /** Secondary weapon slot. */
    
Slot_Melee          2,    /** Melee (knife) weapon slot. */
    
Slot_Projectile     3,    /** Projectile (grenades, flashbangs, etc) weapon slot. */
    
Slot_Explosive      4,    /** Explosive (c4) weapon slot. */
    
Slot_NVGs          5,    /** NVGs (fake) equipment slot. */ // and this new slot
}; 
Unfortunately, the code did not change anything.

Code:
僕の kill‎ : !test
[DEBUG] User weapon weapon_glock , weapon to check for : weapon_healthshot
[DEBUG] User weapon weapon_knife , weapon to check for : weapon_healthshot
[DEBUG] User weapon weapon_taser , weapon to check for : weapon_healthshot
[DEBUG] User weapon weapon_tagrenade , weapon to check for : weapon_healthshot
[DEBUG] User weapon weapon_hegrenade , weapon to check for : weapon_healthshot
[DEBUG] User weapon weapon_flashbang , weapon to check for : weapon_healthshot
[DEBUG] User weapon weapon_c4 , weapon to check for : weapon_healthshot
Quote:
Originally Posted by ShD3luxe View Post
Question : What key do you press to change to the healthshot ? 6? I'm not sure why but in the wiki it says that the healthshot is in the c4 slot (lol) .
When I'm playing, I use the mouse scroll, but the in-game shortcut is "X".
6 to 0 is to select an individual type of grenade, like: he, flashbang, smoke, etc...
JoaoRodrigoGamer is offline
ShD3luxe
Member
Join Date: Aug 2019
Location: Localhost
Old 08-23-2019 , 06:14   Re: [CSGO] Fetch client's weapons, grenades, etc...
Reply With Quote #25

Quote:
Originally Posted by Ilusion9 View Post
Use this to check if a client has certain weapons

PHP Code:

    int size 
GetEntPropArraySize(clientProp_Send"m_hMyWeapons");
    
    for (
int i0m_hMyWeapons_sizei++) 
    { 
        
int item GetEntPropEnt(clientProp_Send"m_hMyWeapons"i); 

        if (
item != -1
        { 
            
char classname[64];
            
GetEntityClassname(itemclassnamesizeof(classname));
        } 
    } 
Will this return all the weapons even if the player has more than one in one slot ?

Also this as a function :
PHP Code:
stock bool ClientHasWeapon(int client, const char weapon[32])
{
    
int size GetEntPropArraySize(clientProp_Send"m_hMyWeapons");
    for (
int i0sizei++) 
    { 
        
int item GetEntPropEnt(clientProp_Send"m_hMyWeapons"i); 
        if (
item != -1
        { 
            
char classname[64];
            
GetEntityClassname(itemclassnamesizeof(classname));
            if(
StrEqual(weaponclassnamefalse))
            {
                return 
true;
            }
        } 
    }  
    return 
false;

ShD3luxe is offline
JoaoRodrigoGamer
Junior Member
Join Date: Jul 2019
Location: Portugal
Old 08-23-2019 , 06:15   Re: [CSGO] Fetch client's weapons, grenades, etc...
Reply With Quote #26

Quote:
Originally Posted by Ilusion9 View Post
Use this to check if a client has certain weapons

PHP Code:

    int size 
GetEntPropArraySize(clientProp_Send"m_hMyWeapons");
    
    for (
int i0m_hMyWeapons_sizei++) 
    { 
        
int item GetEntPropEnt(clientProp_Send"m_hMyWeapons"i); 

        if (
item != -1
        { 
            
char classname[64];
            
GetEntityClassname(itemclassnamesizeof(classname));
        } 
    } 
Can you please explain how that code works and how can it be applied to, for example, find if the player has a health shot?
JoaoRodrigoGamer is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 08-23-2019 , 06:25   Re: [CSGO] Fetch client's weapons, grenades, etc...
Reply With Quote #27

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

__________________
Ilusion9 is offline
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
JoaoRodrigoGamer
Junior Member
Join Date: Jul 2019
Location: Portugal
Old 08-23-2019 , 07:09   Re: [CSGO] Fetch client's weapons, grenades, etc...
Reply With Quote #29

Quote:
Originally Posted by Ilusion9 View Post
Use this to check if a client has certain weapons
Yeah, your code works just fine

Thank you all for your help!
JoaoRodrigoGamer 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 15:23.


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