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

Get client's weapons.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-15-2018 , 13:09   Get client's weapons.
Reply With Quote #1

Hi, I'm trying to loop through all weapons that the client has then store it in an array.

Eg.
sWeapon[0] = "weapon_awp";
sWeapon[1] = "weapon_deagle";
sWeapon[2] = "weapon_knife";

the index = the weapon slots.

I found this so difficult I came here to ask for help (trust me, I already googled a whole lot).
mug1wara is offline
Indarello
Senior Member
Join Date: Nov 2015
Location: Russia
Old 08-15-2018 , 13:32   Re: Get client's weapons.
Reply With Quote #2

1)
int ent = GetPlayerWeaponSlot(client, i);
if (ent != -1)
2)Grenades:
int fnddat = FindDataMapInfo(client, "m_iAmmo");
GetEntData(client, fnddat + (CSGO_HE * 4);

#define CSGO_HE 14 // HE
#define CSGO_FLASH 15 // Flashbang
#define CSGO_SMOKE 16 // Smoke Grenade
3)
Code:
GetEdictClassname(weapon, sweapon, sizeof(sweapon));
int weaponindex = GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex");
switch (weaponindex)
{
	case 60: strcopy(sweapon, 64, "weapon_m4a1_silencer");
	case 61: strcopy(sweapon, 64, "weapon_usp_silencer");
	case 63: strcopy(sweapon, 64, "weapon_cz75a");
	case 64: strcopy(sweapon, 64, "weapon_revolver");
}
4)char sWeapon[MAXPLAYERS + 1][?][64];

Last edited by Indarello; 08-15-2018 at 13:35.
Indarello is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-15-2018 , 14:00   Re: Get client's weapons.
Reply With Quote #3

Nothing of that is what I asked for...
mug1wara is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 08-15-2018 , 15:06   Re: Get client's weapons.
Reply With Quote #4

Quote:
Originally Posted by mug1wara View Post
Nothing of that is what I asked for...
It is, you just have to put the puzzle pieces together.
If it is not what you are asking for, you should specify your question.
Spoiler
__________________
coding & free software

Last edited by shanapu; 08-15-2018 at 15:24.
shanapu is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 08-15-2018 , 15:36   Re: Get client's weapons.
Reply With Quote #5

This may not work 100% I did this from memory but it should work for you...
Namely where the Format Size of section is...not sure thats quite right...

Code:
char sWeapon[MAXPLAYERS+1][5][32]; //CREATE A GLOBAL MULTIDIMENSIONAL CHAR ARRAY

void SaveAllPlayerWeaponClassname(int client)
{
	Format(sWeapon[client][0], sizeof(sWeapon[][]), "%s", GetWeaponClassname(client, 0));
	Format(sWeapon[client][1], sizeof(sWeapon[][]), "%s", GetWeaponClassname(client, 1));
	Format(sWeapon[client][2], sizeof(sWeapon[][]), "%s", GetWeaponClassname(client, 2));
	Format(sWeapon[client][3], sizeof(sWeapon[][]), "%s", GetWeaponClassname(client, 3));
	Format(sWeapon[client][4], sizeof(sWeapon[][]), "%s", GetWeaponClassname(client, 4));
}

stock char GetWeaponClassname(int client, int slot = -1)
{
	int weapon;
	char ClsName[32];

	if(slot == -1)
		weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
	else if(slot == 0)
		weapon = GetPlayerWeaponSlot(client, 0);
	else if(slot == 1)
		weapon = GetPlayerWeaponSlot(client, 1);
	else if(slot == 2)
		weapon = GetPlayerWeaponSlot(client, 2);
	else if(slot == 3)
		weapon = GetPlayerWeaponSlot(client, 3);
	else if(slot == 4)
		weapon = GetPlayerWeaponSlot(client, 4);

	if(weapon > -1)		
		GetEntityClassname(weapon, ClsName, sizeof(ClsName));

	return ClsName;
}

Last edited by MasterMind420; 08-15-2018 at 15:37.
MasterMind420 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 08-15-2018 , 16:13   Re: Get client's weapons.
Reply With Quote #6

in csgo use this instead of GetEntityClassname:
https://github.com/MitchDizzle/Exten...l.sp#L652-L661
Mitchell is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-15-2018 , 17:53   Re: Get client's weapons.
Reply With Quote #7

Right, sorry for being ignorant. Just saw grenades, but I meant weapon slots

I managed to scramble this code together.
PHP Code:
char g_sWeapons[][] =  { "weapon_awp""weapon_glock18" };

int iEntity;
int iSize GetEntPropArraySize(iClientProp_Send"m_hMyWeapons");
    
for (
int X 0iSizeX++)
{
    if ((
iEntity GetEntPropEnt(iClientProp_Send"m_hMyWeapons"X)) != -1)
    {
        
GetEntityClassname(iEntitysWeaponsizeof(sWeapon));

        for (
int Y 0sizeof(g_sWeapons); Y++)
        {
            
// If any of the client's weapon is equivalent to any of the ones in the array. Then print it to the chat.
            
if (StrEqual(sWeapong_sWeapons[Y]))
            {
                
PrintToChat(iClient"%s"g_sWeapons[Y]);
            }
        }
    }

But it prints it nothing to the chat.
Why is that and how do I fix it?

EDIT:

Might be because it stores every weapon the client has in the array "sWeapon".

Last edited by mug1wara; 08-15-2018 at 20:59.
mug1wara is offline
Maxximou5
AlliedModders Donor
Join Date: Feb 2013
Old 08-16-2018 , 16:42   Re: Get client's weapons.
Reply With Quote #8

Here's two different methods I've used. All of which can be made better, but the bones are there.

Method of looping through m_hMyWeapons:
Spoiler


Method of looping through client's weapon slots:
Spoiler
Maxximou5 is offline
mug1wara
AlliedModders Donor
Join Date: Jun 2018
Old 08-16-2018 , 18:27   Re: Get client's weapons.
Reply With Quote #9

Got it working by doing a hell'a debugging, thank's anyways people!
mug1wara 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 10:35.


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