Raised This Month: $ Target: $400
 0% 

Help with cs_get_weapon_id


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 07-04-2010 , 15:13   Help with cs_get_weapon_id
Reply With Quote #1

I want to know the weapon a guy is holding, and set a string to a value which is what the gun max can hold in one mag. I did it this way:

PHP Code:
new ca
            
            
//find what weapon type the player has
            
switch(cs_get_weapon_id(player))
            {
            case 
CSW_P228 ca 13;
            case 
CSW_SCOUT ca 10;
            case 
CSW_HEGRENADE ca 0;
            case 
CSW_XM1014 ca 7;
            case 
CSW_C4 ca 0;
            case 
CSW_MAC10 ca 30;
            case 
CSW_AUG ca 30;
            case 
CSW_SMOKEGRENADE ca 0;
            case 
CSW_ELITE ca 15;
            case 
CSW_FIVESEVEN ca 20;
            case 
CSW_UMP45 ca 25;
            case 
CSW_SG550 ca 30;
            case 
CSW_GALI ca 35;
            case 
CSW_FAMAS ca 25;
            case 
CSW_USP ca 12;
            case 
CSW_GLOCK18 ca 20;
            case 
CSW_AWP ca 10;
            case 
CSW_MP5NAVY ca 30;
            case 
CSW_M249 ca 100;
            case 
CSW_M3 ca 8;
            case 
CSW_M4A1 ca 30;
            case 
CSW_TMP ca 30;
            case 
CSW_G3SG1 ca 20;
            case 
CSW_FLASHBANG ca 0;
            case 
CSW_DEAGLEca 7;
            case 
CSW_SG552 ca 30;
            case 
CSW_AK47 ca 30;
            case 
CSW_P90 ca 50;
            
            } 
Then I was looking at the includes on how to actually use the native, as of what I heard, it would just give out the CSW_* type, but I can see now, that it is not, but it gives a number. Now here comes my question. First the amxconst.inc:

Code:
/* Id of weapons in CS */
#define CSW_P228        1
#define CSW_SCOUT        3
#define CSW_HEGRENADE        4
#define CSW_XM1014        5
#define CSW_C4            6
#define CSW_MAC10        7
#define CSW_AUG            8
#define CSW_SMOKEGRENADE    9
#define CSW_ELITE        10
#define CSW_FIVESEVEN        11
#define CSW_UMP45        12
#define CSW_SG550        13
#define CSW_GALI        14
#define CSW_GALIL        14
#define CSW_FAMAS        15
#define CSW_USP            16
#define CSW_GLOCK18        17
#define CSW_AWP            18
#define CSW_MP5NAVY        19
#define CSW_M249        20
#define CSW_M3            21
#define CSW_M4A1        22
#define CSW_TMP            23
#define CSW_G3SG1        24
#define CSW_FLASHBANG        25
#define CSW_DEAGLE        26
#define CSW_SG552        27
#define CSW_AK47        28
#define CSW_KNIFE        29
#define CSW_P90            30
#define CSW_VEST        31
#define CSW_VESTHELM    32
I am just curious here. Is there no #2 weapon, or is it just my include which is outdated?
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 07-04-2010 , 15:27   Re: Help with cs_get_weapon_id
Reply With Quote #2

Use get_user_weapon() in this case.
__________________
hleV is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 07-04-2010 , 16:08   Re: Help with cs_get_weapon_id
Reply With Quote #3

Awesome, it works! Thank you!
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 07-05-2010 , 01:40   Re: Help with cs_get_weapon_id
Reply With Quote #4

cs_get_weapon_id() is used with the weapon entity as the first and only parameter. In your case, you were passing the player's id. Just an explanation so you'd learn from this.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
DarkGod
SourceMod DarkCrab
Join Date: Jul 2007
Location: Sweden
Old 07-06-2010 , 10:53   Re: Help with cs_get_weapon_id
Reply With Quote #5

Quote:
Originally Posted by Jelle View Post
I am just curious here. Is there no #2 weapon, or is it just my include which is outdated?
Shield?
__________________
DarkGod is offline
Send a message via AIM to DarkGod Send a message via MSN to DarkGod
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-06-2010 , 16:47   Re: Help with cs_get_weapon_id
Reply With Quote #6

Instead of using a switch you could create an array, having an element for each weapon index.
Just be sure to add a blank/zero value as a place holder if there is no weapon for a given index.
PHP Code:
new const GunMax31 ] =
{
     
0,
     
13,
     
0,
     
10,
     
0
// etc for all weapons

Then access value

GunMax[ get_user_weapon( id ) ]

If you choose to do this, it is a good idea to check the value returned by get_user_weapon prior to passing it into the array.
__________________

Last edited by Bugsy; 07-06-2010 at 16:53.
Bugsy is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 07-06-2010 , 19:02   Re: Help with cs_get_weapon_id
Reply With Quote #7

Quote:
Originally Posted by DarkGod View Post
Shield?
It does not say so in amxconst.inc, but thank you.

Quote:
Originally Posted by wrecked_ View Post
cs_get_weapon_id() is used with the weapon entity as the first and only parameter. In your case, you were passing the player's id. Just an explanation so you'd learn from this.
I see now. Thank you.

Quote:
Originally Posted by Bugsy View Post
Instead of using a switch you could create an array, having an element for each weapon index.
Just be sure to add a blank/zero value as a place holder if there is no weapon for a given index.
PHP Code:
new const GunMax31 ] =
{
     
0,
     
13,
     
0,
     
10,
     
0
// etc for all weapons

Then access value

GunMax[ get_user_weapon( id ) ]

If you choose to do this, it is a good idea to check the value returned by get_user_weapon prior to passing it into the array.
I believe get_user_weapon() returns the CSW_* value of the gun the index is holding, so I do not quite understand what you are trying to explain me here.
I think it was cs_get_user_weapon() which gave a number.

But why add a 0 after each weapon? And I do not quite follow you on how to store max clips and such. I rarely use arrays. Is it any faster to do it that way, and not with a switch?
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-06-2010 , 23:26   Re: Help with cs_get_weapon_id
Reply With Quote #8

Quote:
Originally Posted by Jelle View Post
I believe get_user_weapon() returns the CSW_* value of the gun the index is holding, so I do not quite understand what you are trying to explain me here.
I think it was cs_get_user_weapon() which gave a number.

But why add a 0 after each weapon? And I do not quite follow you on how to store max clips and such. I rarely use arrays. Is it any faster to do it that way, and not with a switch?
Add this to your bookmarks: http://www.amxmodx.org/funcwiki.php

cs_get_weapon_id( weapon_entity_index ) returns the CSW_ constant of the weapon entity index passed to it.

get_user_weapon( player_index ) returns the CSW_ constant of the weapon a player is holding.

Both of these return the same thing (a number / CSW_ constant). The difference is what you pass to the function as a parameter.

What you should be using is get_user_weapon() since you are passing a player-id.

The array method I was showing you will allow you to not use switch statement which will make your code more efficient.

Since there are no weapons with an index (CSW_ value) of 0 or 2, we need to put placeholders in these locations so the remainder of the array will stay in order (this can be any number since it will never be used). Maybe this code will be easier to understand...you can continue for the remaining weapons, there are no other 'empty slots'.
PHP Code:
new const GunMax31 ] =
{
     
0//0 - empty slot
     
13//1 - P228
     
0//2 - empty slot
     
10//3 - SCOUT
     
0//4 - HEGRENADE
     
7//5 - XM1014
     
0//6 - C4
     
30//7 - MAC10
     
30//8 - AUG
     
0//9 - SMOKEGRENADE
     
15//10 - ELITE
// etc for all weapons

Just be sure the weapons are all in order identical to the CSW constants.
Code:
/* Id of weapons in CS */
#define CSW_P228        1
#define CSW_SCOUT        3
#define CSW_HEGRENADE        4
#define CSW_XM1014        5
#define CSW_C4            6
...
__________________

Last edited by Bugsy; 07-06-2010 at 23:33.
Bugsy is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-07-2010 , 00:22   Re: Help with cs_get_weapon_id
Reply With Quote #9

2 doesn't exists AFAIK.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 07-07-2010 , 07:11   Re: Help with cs_get_weapon_id
Reply With Quote #10

Oh I see what you mean bugsy. What I do not get, is after making the array, how do I look thou it? I was looking at the function reference on amxmodx.org for get_user_weapon, and I still have no idea how you want me to use the array.

Quote:
Originally Posted by ConnorMcLeod View Post
2 doesn't exists AFAIK.
DarkGod just wrote it is the shield.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
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 07:07.


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