Help with cs_get_weapon_id
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:
Code:
/* Id of weapons in CS */ |
Re: Help with cs_get_weapon_id
Use get_user_weapon() in this case.
|
Re: Help with cs_get_weapon_id
Awesome, it works! Thank you!
|
Re: Help with cs_get_weapon_id
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.
|
Re: Help with cs_get_weapon_id
Quote:
|
Re: Help with cs_get_weapon_id
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:
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. |
Re: Help with cs_get_weapon_id
Quote:
Quote:
Quote:
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? |
Re: Help with cs_get_weapon_id
Quote:
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:
Code:
/* Id of weapons in CS */ |
Re: Help with cs_get_weapon_id
2 doesn't exists AFAIK.
|
Re: Help with cs_get_weapon_id
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:
|
| All times are GMT -4. The time now is 07:07. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.