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

Solved CSGO. How to check if a player has certain grenades


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 01-25-2019 , 16:47   CSGO. How to check if a player has certain grenades
Reply With Quote #1

How to check if a player has certain grenades. For example I want to check if player has inc grenade.

Last edited by impossible_cc; 01-26-2019 at 09:08. Reason: solved
impossible_cc is offline
PandahChan
New Member
Join Date: Mar 2017
Old 01-25-2019 , 19:19   Re: CSGO. How to check if a player has certain grenades
Reply With Quote #2

Hello, This is a very scrappy way of it but you want to be doing something on the lines of this.

There is a lot tidier ways of doing this but this is what I quickly made

What this does is on map start it will run through the character array of the grenade types and get the offsets as the offsets can change. From there on command it will take 1 argument, the players name.

On check it will check what inventory the player has. Again there is a lot more optimised and cleaner ways of doing this. But this was a scrappy code I just whipped up.
Attached Files
File Type: sp Get Plugin or Get Source (grenade_check.sp - 117 views - 3.9 KB)
PandahChan is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 01-26-2019 , 07:01   Re: CSGO. How to check if a player has certain grenades
Reply With Quote #3

Thank you. It works.
I used it to give player random grenade, but I need to check if he already owns it.

PHP Code:
#include <sourcemod>
#include <sdktools>
char g_GrenadeWeaponNames[][] = 
{
    
"weapon_flashbang",
    
"weapon_smokegrenade",
    
"weapon_hegrenade",
    
"weapon_decoy",
    
"weapon_incgrenade"
};
int g_GrenadeOffset[sizeof(g_GrenadeWeaponNames)];
public 
void OnMapStart()
{
    if (!
g_GrenadeOffset[0])
    {
        for (
int i 0sizeof(g_GrenadeWeaponNames); i++)
        {
            
int entindex CreateEntityByName(g_GrenadeWeaponNames[i]);
            
DispatchSpawn(entindex);
            
g_GrenadeOffset[i] = GetEntProp(entindexProp_Send"m_iPrimaryAmmoType");
            
AcceptEntityInput(entindex"Kill");
        }
    }
}
void GiveRandomGrenade(int client)
{
    
int counter 0;
    for(
int i 05i++)
    {
        if(!
HasPlayerGrenade(clientg_GrenadeOffset[i]))
        {
            
counter++;
        }
    }
    if(
counter 0)
    {
        
char[][] tempArray = new char[counter][32];
        
        
int newcounter 0;
        
        for(
int i 0&& newcounter counteri++)
        {
            if(!
HasPlayerGrenade(clientg_GrenadeOffset[i]))
            {
                
Format(tempArray[newcounter], 32"%s"g_GrenadeWeaponNames[i]);
                
newcounter++;
            }
        }
        
//for(int i = 0; i < counter; i++)
        //{
        //    PrintToChat(client, "%s\n", tempArray[i]);
        //}
        
GivePlayerItem(clienttempArray[GetRandomInt(0counter 1)]);
    }
}

bool HasPlayerGrenade(int clientint offset)
{
    return 
GetEntProp(clientProp_Send"m_iAmmo"_offset)>0;

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 01:30.


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