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

How to loop through all player weapons?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hell Phoenix
Senior Member
Join Date: Jan 2005
Old 07-20-2007 , 12:10   How to loop through all player weapons?
Reply With Quote #1

Anyone know how I can loop through all the players weapons? Im looking to create a stock to strip all users weapons. I tried to follow what Team06 did in gungame...but there are things everywhere and it made my head spin....lol.
__________________
Hell Phoenix is offline
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 07-20-2007 , 12:31   Re: How to loop through all player weapons?
Reply With Quote #2

There two ways to do it. You can do it via a Prop Offset CAI_BaseNPC::m_hMyWeapons. You can look at devicenull first plugin. The weapon restriction plugin for usage.

The other way would be using sdktools GetPlayerWeaponSlot() would be mod dependent. You can see the sdktools.games.txt for which mod support GetPlayerWeaponSlot.

For CS:S the slots would be 0 for primary, 1 for secondary, 2 for knife, 3 for grenades, 4 for c4.

For grenades you have to loop threw the grenade slot to get all the clients grenades but you need to be very careful because if they have aleast 1 grenade. You can do an infinite loop if you do a while loop incorrectly.
Code:
Usage for getting all the grenades are wrong. Because GetPlayerWeaponSlot will always hit the first grenade in m_hMyWeapons. If he has hegrenade in the slot before flash, or smoke. It will always return hegrenade. You have to walk the m_hMyWeapons to get the entity index. Then use CBaseCombatWeapon::GetSlot() to retrieve the slot in which that weapon hold. This is the only way you can retrieve all the grenades slots.
__________________
No private support via Instant Message
GunGame:SM Released

Last edited by teame06; 07-25-2007 at 23:44.
teame06 is offline
Send a message via AIM to teame06
Hell Phoenix
Senior Member
Join Date: Jan 2005
Old 07-20-2007 , 12:40   Re: How to loop through all player weapons?
Reply With Quote #3

Thanks teame06...very helpfull =D
__________________
Hell Phoenix is offline
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 07-28-2007 , 00:03   Re: How to loop through all player weapons?
Reply With Quote #4

"kappa.games.txt"
Code:
/* Do not edit this file if you do not know what your doing. */
"Games"
{
	"#default"
	{
		"#supported"
		{
			"game"		"cstrike"
		}

		"Offsets"
		{

			"GetSlot"
			{
				"windows"		"280"
				"linux"			"281"
			}
		}
	}
}
Code:
#include <sourcemod> #include <sdktools> new m_hMyWeapons; new Handle:GetSlot; new Handle:GameConf public OnPluginStart() {     m_hMyWeapons = FindSendPropOffs("CBasePlayer", "m_hMyWeapons");     if(m_hMyWeapons == -1)     {         decl String:Error[128];         FormatEx(Error, sizeof(Error), "FATAL ERROR m_hMyWeapons [%d]. Please contact the author.", m_hMyWeapons);         SetFailState(Error);     }     GameConf = LoadGameConfigFile("kappa.games");     CreateGetSlotHack(); } DisplayPlayerGrenades(client) {     decl String:Class[64];     for(new i = 0, ent; i < 128; i += 4)     {         ent = GetEntDataEnt(client, m_hMyWeapons + i);         if(ent > 0 && HACK_GetSlot(ent) == 3)         {             GetEdictClassname(ent, Class, sizeof(Class));             PrintToServer("Has [%s]", Class);         }     } } CreateGetSlotHack() {     StartPrepSDKCall(SDKCall_Entity);     PrepSDKCall_SetFromConf(GameConf, SDKConf_Virtual, "GetSlot");     PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);     GetSlot = EndPrepSDKCall();     if(GetSlot == INVALID_HANDLE)     {         SetFailState("Virtual CBaseCombatWeapon::GetSlot Failed. Please contact the author.");     } } HACK_GetSlot(entity) {     return SDKCall(GetSlot, entity); }

Just use DisplayPlayerGrenades(client) on a player print out all the players grenades. This will walk the m_hMyWeapons for any weapon entity that is the grenade slot.

This is so you can see what grenades they have. Since GetPlayerWeaponSlot will return the first grenade in the m_hMyWeapons.

Code is untested but compiles.
__________________
No private support via Instant Message
GunGame:SM Released

Last edited by teame06; 07-28-2007 at 04:39.
teame06 is offline
Send a message via AIM to teame06
steambob
Member
Join Date: Sep 2007
Old 09-25-2007 , 04:26   Re: How to loop through all player weapons?
Reply With Quote #5

I want to loop over the weapons in HL2MP.
But in the following code:

Code:
myweaponsoffset = FindSendPropOffs("CHL2MP_Player", "m_hMyWeapons");
new entit;

    decl String:Class[64];

    for(new i = 0; i < 128; i += 4)
    {
        entit = GetEntDataEnt(client, myweaponsoffset + i);
        }
entit always returns 0.

Am I doing something wrong or is this just HL2MP thing?
steambob is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 09-25-2007 , 16:12   Re: How to loop through all player weapons?
Reply With Quote #6

I am not quite sure, but instead of using "+= 4", try using "++"
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
BAILOPAN
Join Date: Jan 2004
Old 09-25-2007 , 16:32   Re: How to loop through all player weapons?
Reply With Quote #7

Incrementing by 4 is essential.

That said, I can't see anything immediately wrong with that code snippet.
__________________
egg
BAILOPAN is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 09-25-2007 , 16:43   Re: How to loop through all player weapons?
Reply With Quote #8

Hm... How do you know all that stuff BAILOPAN?

The only difference I see now is that he is using CBasePlayer and you are using CHL2MP_Player
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
ferret
SourceMod Developer
Join Date: Dec 2004
Location: Atlanta, GA
Old 09-25-2007 , 16:50   Re: How to loop through all player weapons?
Reply With Quote #9

4-byte words. Have to increment by 4 to get to the start of the next word, instead of the middle of one.
__________________
I'm a blast from the past!
ferret is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 09-25-2007 , 16:59   Re: How to loop through all player weapons?
Reply With Quote #10

Ah! I see now, I went to http://plugins.mfzb.de/offsets/CSTRIKE_Props.txt and found this:
PHP Code:
            m_hMyWeapons (1704)
               
000 (0)
               
001 (4)
               
002 (8)
               
003 (12)
               
004 (16)
               
005 (20)
               
006 (24)
               
007 (28)
               
008 (32)
               
009 (36)
               
010 (40)
               
011 (44)
               
012 (48)
               
013 (52)
               
014 (56)
               
015 (60)
               
016 (64)
               
017 (68)
               
018 (72)
               
019 (76)
               
020 (80)
               
021 (84)
               
022 (88)
               
023 (92)
               
024 (96)
               
025 (100)
               
026 (104)
               
027 (108)
               
028 (112)
               
029 (116)
               
030 (120)
               
031 (124)
               
032 (128)
               
033 (132)
               
034 (136)
               
035 (140)
               
036 (144)
               
037 (148)
               
038 (152)
               
039 (156)
               
040 (160)
               
041 (164)
               
042 (168)
               
043 (172)
               
044 (176)
               
045 (180)
               
046 (184)
               
047 (188
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
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 15:05.


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