AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Trash (https://forums.alliedmods.net/forumdisplay.php?f=22)
-   -   get_user_weapon2() (https://forums.alliedmods.net/showthread.php?t=88242)

xPaw 03-22-2009 04:05

get_user_weapon2()
 
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!" );
    } 


M1R0n,M' 03-22-2009 04:09

Re: get_user_weapon2()
 
good :)

ConnorMcLeod 03-22-2009 05:08

Re: get_user_weapon2()
 
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;



xPaw 03-22-2009 05:16

Re: get_user_weapon2()
 
updated :)

Arkshine 03-22-2009 06:30

Re: get_user_weapon2()
 
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.

alan_el_more 03-22-2009 07:35

Re: get_user_weapon2()
 
GJ :D

Bugsy 03-22-2009 08:10

Re: get_user_weapon2()
 
I've always used szWeapon[7] to solve this. It would be cool to have this implemented into the core though.

Hawk552 03-22-2009 08:40

Re: get_user_weapon2()
 
Quote:

Originally Posted by Bugsy (Post 786427)
I've always used szWeapon[7] to solve this. It would be cool to have this implemented into the core though.

Natives can't return arrays.

Exolent[jNr] 03-22-2009 12:54

Re: get_user_weapon2()
 
Shouldn't the function's name be more appropriate, such as get_user_weaponname()?

minimiller 03-22-2009 13:25

Re: get_user_weapon2()
 
i thought there allready was a get_user_weaponname?
It returns "weapon_"

EDIT:
My bad
its just get_weaponname(index)


All times are GMT -4. The time now is 23:11.

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