Raised This Month: $ Target: $400
 0% 

get_user_name ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
iloverain
Junior Member
Join Date: Jun 2012
Old 06-23-2012 , 14:49   get_user_name ?
Reply With Quote #1

Hi all! I'm trying to get a users name. So I looked at the get_user_name function.
I saw someone post:

Code:
new name[18] 
get_user_name(id, name, 17) 
client_print(id, print_chat, "Your name is: %s", name)


Now, what I don't understand is the array, name[18]. What exactly does this do?

Then there's get_user_name(id, name, 17). what exactly is "id" for (index)? Then name? Also why's it 17 now?

client_print(id, ...) Whats the index there for? What is the index?


Sorry I'm just getting started in scripting. This may probably be the noobiest question ever asked. Hah.

Thanks in advance.
iloverain is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 06-23-2012 , 14:53   Re: get_user_name ?
Reply With Quote #2

You should start to read the existing tutorials for beginner : https://forums.alliedmods.net/showth...awnProgramming
__________________
Arkshine is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-23-2012 , 14:56   Re: get_user_name ?
Reply With Quote #3

It's a string, not an array. The number means it can have 18 characters max. It looks exactly like an array because it works similiar to this:
Code:
new string[ 2 ] format( string, 1 /* max characters - 1 */, "oh" ) // we're copying "oh" into variable string string[ 0 ] = 'o' string[ 1 ] = 'h'
For a name, you should put 32 there, because 18 will not be enough if the player's nick reaches 18 characters and part of it will be cut off.

For the second question, id is the player index. It starts from 1 and ends with 32. It is passed in forwards like client_connect( id ). In your example, it means you're getting the name of player with index id.
name means you're copying the user's name into name string.
It is 17 because every string starts from 0 (not 1, see my example above), thus it's always max characters - 1.

For the third question, see above.

Last edited by Backstabnoob; 06-23-2012 at 14:56.
Backstabnoob is offline
iloverain
Junior Member
Join Date: Jun 2012
Old 06-23-2012 , 15:04   Re: get_user_name ?
Reply With Quote #4

Thank you guys for taking the time to answer. I really apreciate it. I understand now

edit;
Ok so I made this plugin but there are some errors:
Code:
Error: Invalid function or declaration on line 11
Error: Syntax error in the expression, or invalid function call on line 20
Error: Declaration of a local variable must appear in a compound block on line 22
Error: Undefined symbol "name" on line 22
Warning: Expression has no effect on line 22
Error: Expected token: ";", but found "]" on line 22
Error: Too many error messages on one line on line 22

Compilation aborted.
6 Errors.
Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "jm0d"
#define VERSION "1.0"
#define AUTHOR "iloverain"

new bool:isSimon
isSimon = false        // <----------------------------------------- LINE 11

public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    
    register_clcmd ( "say /simon", "SetSimon" )
}

public SetSimon() {
    if ( get_user_team == 2 )      // <--------------------------------------------- LINE 20
    
    new name[32];                    // <------------------------------------------------- LINE 22
    get_user_name( id, name, 31 );
    
    if ( isSimon == true ) {
        client_print(id, print_chat, "Someone is already Simon!");
    } else {
        client_print(id, print_chat, "%s is Simon!", name);
        isSimon = true
    }    
}
__________________
Just A n00b Learning. ^-^

Last edited by iloverain; 06-23-2012 at 15:25.
iloverain is offline
Old 06-23-2012, 15:29
Waleed
This message has been deleted by Waleed. Reason: combined two messages
Waleed
Senior Member
Join Date: May 2012
Location: Pakistan
Old 06-23-2012 , 15:36   Re: get_user_name ?
Reply With Quote #5

To get user name use this method:

PHP Code:
new name[32
get_user_name(id,name,charsmax(name// Getting name here
client_print(id,print_chat," Your name is %s",name//Chat message to verify 
I think
PHP Code:
new bool:isSimon 
should be:

PHP Code:
new bool:isSimon[] or [33
To get team You can do this:

PHP Code:
if(cs_get_user_team(id) == CS_TEAM_CT//Include cstrike for this native 
Error on line 22 should be because you didn't put " { " or " } " after team check

EDIT: Check my practice plugin here : http://forums.alliedmods.net/showthread.php?t=188202
It would help you.
__________________
Working On:
  1. Gameplay 1 - 0% [PAUSED]

Last edited by Waleed; 06-23-2012 at 15:47. Reason: tagged a bit
Waleed is offline
Send a message via Skype™ to Waleed
iloverain
Junior Member
Join Date: Jun 2012
Old 06-23-2012 , 15:47   Re: get_user_name ?
Reply With Quote #6

@above Perfect! Thanks so much! I appreciate your help all!

I changed the bool to
Code:
new bool:isSimon=false
which worked perfectly.
I used the user name method Waleed suggested which worked perfectly.
I also googled how to get user team and i found the cstrike one too so yeah using that one.

Here's the working code:
Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>

#define PLUGIN "jm0d"
#define VERSION "1.0"
#define AUTHOR "iloverain"

new bool:isSimon=false 

public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    
    register_clcmd ( "say /simon", "SetSimon" )
}

public SetSimon(id) {
    (cs_get_user_team(id) == CS_TEAM_CT)
    
    new name[32];
    get_user_name( id, name, charsmax ( name ) )
    
    if ( isSimon == true ) {
        client_print( id, print_chat, "Someone is already Simon!" )
    } else {
        client_print( id, print_chat, "%s is Simon!", name )
        isSimon = true
    }    
}
Thanks all!

LOL edit;

last question. how would one reset a boolean to false after round end? o.0 I dont want to create a new thread for each question. Lmfao sorry.
__________________
Just A n00b Learning. ^-^

Last edited by iloverain; 06-23-2012 at 15:57.
iloverain is offline
Waleed
Senior Member
Join Date: May 2012
Location: Pakistan
Old 06-23-2012 , 15:58   Re: get_user_name ?
Reply With Quote #7

To find what natives or constants you need use AMX Wiki ---> http://www.amxmodx.org/funcwiki.php <---
Google is good for searching but AMX Wiki would be faster and easier to get info on modules and constants
__________________
Working On:
  1. Gameplay 1 - 0% [PAUSED]
Waleed is offline
Send a message via Skype™ to Waleed
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 06-23-2012 , 16:10   Re: get_user_name ?
Reply With Quote #8

Every bool has false as default value, so you don't need to set it.
__________________
<VeCo> is offline
iloverain
Junior Member
Join Date: Jun 2012
Old 06-23-2012 , 16:11   Re: get_user_name ?
Reply With Quote #9

oh ok thanks. ^ i also figured out how to make it back to false if it was true after round end. so I'm done for now! Thanks all
__________________
Just A n00b Learning. ^-^
iloverain is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-23-2012 , 16:34   Re: get_user_name ?
Reply With Quote #10

Quote:
Originally Posted by Backstabnoob View Post
It's a string, not an array. The number means it can have 18 characters max.
Let's not lie to him. A string is an array [of characters] with an "end of string" character to identify the end of the string. Also, if a string is declared with 18 then you can only use 17 characters (hence the 17 in the get_user_name() function).

Quote:
Originally Posted by <VeCo> View Post
Every bool has false as default value, so you don't need to set it.
It is a good habit to initialize variables when they are declared regardless of whether they have a default value or not.
__________________
fysiks 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 06:16.


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