Raised This Month: $ Target: $400
 0% 

Help with cs_get_weapon_id


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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