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

Solved loops through weapons


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-04-2019 , 17:48   loops through weapons
Reply With Quote #1

PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1

char g_sWeapons[][] =
{
    
"weapon_deagle",
    
"weapon_elite"
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_test"Cmd_Test);
}

public 
Action Cmd_Test(int iClientint iArgs)
{
    if (
IsValidClient(iClient))
    {
        
char sWeapon[MAXPLAYERS 1][5][32];
        
        
int iWeapons_Size GetEntPropArraySize(iClientProp_Send"m_hMyWeapons");
        
        
// loop through the clients weapons, based on the amount of slots the client has occupied
        
for (int x 0iWeapons_Sizex++)
        {
            
// get the weapon index based on that slot
            
int iWeapon_Entity_Index GetEntPropEnt(iClientProp_Send"m_hMyWeapons"x);
            
            
// and from that, get the weapon classname
            
GetWeaponClassname(iWeapon_Entity_IndexsWeapon[iClient][x], sizeof(sWeapon[][]));
            
            
// this will loop through the g_sWeapons array, checking if the weapon -
            // classname is equivalent to any of the ones in the array
            
for (int y 0sizeof(g_sWeapons[]); y++)
            {
                if (
StrEqual(sWeapon[iClient][x], g_sWeapons[y]))
                {
                    
PrintToChatAll("the client has one of the weapons in the g_sWeapons array");
                }
            }
        }
    }
    
    return 
Plugin_Handled;
}

public 
void GetWeaponClassname(int iWeapon_Entity_Indexchar[] sBufferint iBuffer_Size)
{
    switch (
GetEntProp(iWeapon_Entity_IndexProp_Send"m_iItemDefinitionIndex"))
    {
        case 
60:
            
Format(sBufferiBuffer_Size"weapon_m4a1_silencer");
        
        case 
61:
            
Format(sBufferiBuffer_Size"weapon_usp_silencer");
        
        case 
63:
            
Format(sBufferiBuffer_Size"weapon_cz75a");
        
        case 
64:
            
Format(sBufferiBuffer_Size"weapon_revolver");
        
        default:
            
GetEntityClassname(iWeapon_Entity_IndexsBufferiBuffer_Size);
    }
}

public 
bool IsValidClient(int iClient)
{
    if (!(
iClient <= MaxClients) || !IsClientConnected(iClient) || !IsClientInGame(iClient) || IsFakeClient(iClient))
        return 
false;
    
    return 
true;

the statement at line 38 just returns false. I don't even know if this code does what I want it to, can I have a second pair of eyes, thanks.
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: Stefan Milivojevic#5311

Last edited by I am inevitable; 07-04-2019 at 18:26.
I am inevitable is offline
Whai
Senior Member
Join Date: Jul 2018
Old 07-08-2019 , 18:16   Re: loops through weapons
Reply With Quote #2

Try this :
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>

#pragma semicolon 1
#pragma newdecls required

char sWeapon[MAXPLAYERS 1][4][32];

char g_sWeapons[][] =
{
    
"weapon_deagle",
    
"weapon_elite"
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_test"Cmd_Test);
}

public 
Action Cmd_Test(int iClientint iArgs)
{
    if (
IsValidClient(iClient))
    {
        
// NOTE : we don't care about C4 slot (informations from cstrike.inc)
        
for (int x 0<= 3x++)
        {
            
// get the weapon index based on that slot
            
int iWeapon_Entity_Index GetPlayerWeaponSlot(iClientx);

            
// check if the weapon was found
            
if(IsValidEntity(iWeapon_Entity_Index))
            {
                continue; 
// skip this
            
}
            
            
// and from that, get the weapon classname
            
GetWeaponClassname(iWeapon_Entity_IndexsWeapon[iClient][x], sizeof(sWeapon[][])); 
            
            
            
// this will loop through the g_sWeapons array, checking if the weapon -
            // classname is equivalent to any of the ones in the array
            
for (int y 0sizeof(g_sWeapons[]); y++)
            {
                if (
StrEqual(sWeapon[iClient][x], g_sWeapons[y]))
                {
                    
PrintToChatAll("the client has one of the weapons in the g_sWeapons array");
                }
            }
        }
    }
    
    return 
Plugin_Handled;
}

public 
void GetWeaponClassname(int iWeapon_Entity_Indexchar[] sBufferint iBuffer_Size)
{
    switch (
GetEntProp(iWeapon_Entity_IndexProp_Send"m_iItemDefinitionIndex"))
    {
        case 
60:
            
Format(sBufferiBuffer_Size"weapon_m4a1_silencer");
        
        case 
61:
            
Format(sBufferiBuffer_Size"weapon_usp_silencer");
        
        case 
63:
            
Format(sBufferiBuffer_Size"weapon_cz75a");
        
        case 
64:
            
Format(sBufferiBuffer_Size"weapon_revolver");
        
        default:
            
GetEntityClassname(iWeapon_Entity_IndexsBufferiBuffer_Size);
    }
}

public 
bool IsValidClient(int iClient)
{
    if (!(
iClient <= MaxClients) || !IsClientConnected(iClient) || !IsClientInGame(iClient) || IsFakeClient(iClient))
        return 
false;
    
    return 
true;

__________________
Whai is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-09-2019 , 01:29   Re: loops through weapons
Reply With Quote #3

I think GetPlayerWeaponSlot doesn't require IsValidEntity, only requires to ensure it is not equal to -1 (minus one)
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Whai
Senior Member
Join Date: Jul 2018
Old 07-09-2019 , 15:48   Re: loops through weapons
Reply With Quote #4

Yes, I firstly did that but I replaced it to be sure he will understand the code. It does not matter (or maybe there is a latence to find if it exists or not by looking for every entity id, I don't know), the code will do what he wanted
__________________
Whai is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-09-2019 , 16:00   Re: loops through weapons
Reply With Quote #5

there's nothing wrong with my code, and if you didn't notice, I marked the thread as solved way before I got responses.
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: Stefan Milivojevic#5311
I am inevitable is offline
Whai
Senior Member
Join Date: Jul 2018
Old 07-09-2019 , 16:07   Re: loops through weapons
Reply With Quote #6

He was talking on my code, not yours
__________________
Whai is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-09-2019 , 16:10   Re: loops through weapons
Reply With Quote #7

Quote:
Originally Posted by Whai View Post
He was talking on my code, not yours
I know lol?
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: Stefan Milivojevic#5311
I am inevitable is offline
Whai
Senior Member
Join Date: Jul 2018
Old 07-09-2019 , 16:30   Re: loops through weapons
Reply With Quote #8

I was just answering to eyal282 to justify why I did this
__________________
Whai is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-09-2019 , 19:48   Re: loops through weapons
Reply With Quote #9

All good
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: Stefan Milivojevic#5311
I am inevitable is offline
Reply



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 18:03.


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