Raised This Month: $ Target: $400
 0% 

get_user_weapon2()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 03-22-2009 , 04:05   get_user_weapon2()
Reply With Quote #1

get_user_weapon2

PHP Code:
public get_user_weapon2id ) {
    new 
szWeapon20 ];
    
get_weaponnameget_user_weaponid ), szWeaponcharsmaxszWeapon ) );
    
    return 
szWeapon[7];

.: Description :.
Do you even wanted to return weapon name in format like: usp, knife?
This simple stock returns you weapon name like: usp, knife, awp ;)
.: Example usage #1 :.
PHP Code:
    client_printidprint_chat"* Your weapon is %s!"get_user_weapon2(id) ); 
.: Example usage #2 :.
PHP Code:
    new szWeapon[20];
    
szWeapon get_user_weapon2id );

    if( 
equal(szWeapon"knife") ) {
        
client_printidprint_chat"* You have knife, some cool stuff!" );
    } 
__________________

Last edited by xPaw; 07-10-2009 at 03:21.
xPaw is offline
M1R0n,M'
Senior Member
Join Date: Jan 2009
Location: Lithuania
Old 03-22-2009 , 04:09   Re: get_user_weapon2()
Reply With Quote #2

good
__________________
PHP Code:
#include <hambeer>
RegisterHamBeer(HamBeer_Spawn"player""GivePlayerBeer"1);
public 
GivePlayerBeer(Pl){
    if(!
is_user_alive(Pl)){
        
ham_give_beer(Pl5)
        
client_print(Plprint_chat"Go Go Go"){

M1R0n,M' is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-22-2009 , 05:08   Re: get_user_weapon2()
Reply With Quote #3

szWeapon size is too small to contain "weapon_smokegrenade"
You don't need this badly named var szWeaponCSW ( <- it's an integer so iWeaponCSW would have been better if the var had been needed)

PHP Code:
stock get_user_weapon2id )
{
    new 
szWeapon[20]; // weapon_smokegrenade = 19
    
get_weaponname(get_user_weapon(id), szWeaponcharsmax(szWeapon));
    
replace(szWeaponcharsmax(szWeapon), "weapon_""");

    return 
szWeapon;

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 03-22-2009 , 05:16   Re: get_user_weapon2()
Reply With Quote #4

updated
__________________
xPaw is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-22-2009 , 06:30   Re: get_user_weapon2()
Reply With Quote #5

To avoid to use replace() ; using szWeapon[7] directly should work.

[edit] Arg, it will give an error "Array must be indexed" for the #2. Not good. Though, using szWeapon[0] to get should work, but not sure if it's a good idea.

Last edited by Arkshine; 03-22-2009 at 06:40.
Arkshine is offline
alan_el_more
Veteran Member
Join Date: Jul 2008
Location: amxmodx-es.com
Old 03-22-2009 , 07:35   Re: get_user_weapon2()
Reply With Quote #6

GJ
__________________
alan_el_more is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-23-2009 , 06:47   Re: get_user_weapon2()
Reply With Quote #7

Quote:
Originally Posted by arkshine View Post
To avoid to use replace() ; using szWeapon[7] directly should work.

[edit] Arg, it will give an error "Array must be indexed" for the #2. Not good. Though, using szWeapon[0] to get should work, but not sure if it's a good idea.
In this case it would be

format(szWeapon,13,szWeapon[7]);

I had never saw this. (returning an array pointer) (i guess it's how this is called)
__________________
joaquimandrade is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-23-2009 , 08:03   Re: get_user_weapon2()
Reply With Quote #8

Quote:
Originally Posted by joaquimandrade View Post
I had never saw this. (returning an array pointer) (i guess it's how this is called)
Calling array size must match the returned array.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-23-2009 , 08:07   Re: get_user_weapon2()
Reply With Quote #9

Quote:
Originally Posted by ConnorMcLeod View Post
Calling array size must match the returned array.
I tried it and it can be bigger.
__________________
joaquimandrade is offline
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 05-16-2009 , 09:50   Re: get_user_weapon2()
Reply With Quote #10

Quote:
Originally Posted by joaquimandrade View Post
In this case it would be: format(szWeapon,13,szWeapon[7]);
Calling a native such as format eliminates the purpose of using string slicing instead of replace().
__________________
No support via PM.
Lee is offline
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 23:11.


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