Raised This Month: $12 Target: $400
 3% 

get_user_weapon2()


Post New Thread Reply   
 
Thread Tools Display Modes
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-23-2009 , 06:47   Re: get_user_weapon2()
Reply With Quote #11

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 #12

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 #13

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
Styles
Veteran Member
Join Date: Jul 2004
Location: California
Old 04-01-2009 , 14:01   Re: get_user_weapon2()
Reply With Quote #14

ya, this is a simple stock haha, but useful, I have something like this laying around or did at one pint..
Styles is offline
Send a message via AIM to Styles
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 05-16-2009 , 09:50   Re: get_user_weapon2()
Reply With Quote #15

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
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-16-2009 , 10:03   Re: get_user_weapon2()
Reply With Quote #16

Quote:
Originally Posted by Lee View Post
Calling a native such as format eliminates the purpose of using string slicing instead of replace().
Replace searches, format don't. So it would be less expensive.

In this case the best way would be:

PHP Code:
public get_user_weapon2id 
{
    new 
szWeapon[20];
    
get_weaponname(get_user_weapon(id), szWeaponcharsmax(szWeapon));
    return 
szWeapon[7];

But i didn't know that
PHP Code:
return szWeapon[7]; 
was possible
__________________
joaquimandrade is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 05-16-2009 , 12:21   Re: get_user_weapon2()
Reply With Quote #17

So, if I understood right:
PHP Code:
func() {
    new 
s[5];
    
s[0] = 'h';
    
s[1] = 'e';
    
s[2] = 'l';
    
s[3] = 'l';
    
s[4] = 'o';
    return 
s[1];

would return "ello". So the question is, what would return the second char then, like 'e'?
SnoW is offline
Send a message via MSN to SnoW
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 05-16-2009 , 12:40   Re: get_user_weapon2()
Reply With Quote #18

The syntax for both is the same; it depends on whether the function to which you pass func() as a parameter expects a value or a reference to an array.

Code:
console_print("%c %s", func(), func());
This would, I believe, output "e ello".

Code:
if(func() == 101)     console_print("My name is Vinny.");
This should also output the string "My name is Vinny.", because 'e' (encoded in ASCII) is equal to 101.

In your example however you would need to declare s with six cells and assign s[5] to '\0'.
__________________
No support via PM.

Last edited by Lee; 05-16-2009 at 12:49.
Lee is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 05-17-2009 , 04:17   Re: get_user_weapon2()
Reply With Quote #19

Thank you.
SnoW is offline
Send a message via MSN to SnoW
AussenSeiter
BANNED
Join Date: May 2010
Old 05-08-2010 , 11:05   Re: get_user_weapon2()
Reply With Quote #20

Code:
client_print( id, print_chat, "* Your weapon is %s!", get_user_weapon2(id) );  
If weapon is tmp/m4a1 or something it shows only the first letter why?
Example:
M4a1 = Weapon: m
tmp = Weapon: t
smokegrenade = weapon: s

EXIT: Fixed !

Last edited by AussenSeiter; 05-08-2010 at 11:22.
AussenSeiter 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 22:12.


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