Raised This Month: $ Target: $400
 0% 

Problem with users ID.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheDiamant953
Member
Join Date: Jan 2013
Old 01-10-2016 , 15:01   Problem with users ID.
Reply With Quote #1

I have a little problem with user id.

I have two plugin, the first use a Server Command:

Code:
ServerCommand("sm_test1 %d", client);
And the second plugin received it:

Code:
public Action:Command_Test1(args)
{
	if (args != 1)
	{
		return Plugin_Handled;
	}
	
	new String:arg1[10];
	GetCmdArg(1, arg1, sizeof(arg1));
	
	new argument1;
	argument1 = StringToInt(arg1);
		
	new target;
	target = GetClientOfUserId(argument1);
	
	if(target && 0 < target <= MaxClients)
	{
		if(g_eClients[target][bChefCt] == false)
		{
			g_eClients[target][bChefCt] = true;
		}
	}
	return Plugin_Continue;
}
In this case, i wan't to turn "bChefCt" to true by using the command in the first plugin with the userid of the player.

My problem: the command work, but the player in not the good one.

For example, when i use status in the console i have:
15 14 Payer1 ....
16 15 Player2 ...

When the plugin use the command on the player2, it's the player1 who is the target and not player2.

I thing i have done something wrong with GetClientOfUserId or by sending client to the command.

Can you maybe help me, it's would be really apreciate.

Thanks and have a good day.
TheDiamant953 is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 01-10-2016 , 15:45   Re: Problem with users ID.
Reply With Quote #2

Use
Code:
ServerCommand("sm_test1 %d", GetClientUserId(client));
Client index isn't userid. Client index means online player index and can be 0-65 (0 is server).
Userid is index means player session.
Example: while timer gone, one player (with client index 1) left the game, and another connected (and get index 1 because it's free). After timer you will get wrong target. But userid for 1st player is n, and n+1 for 2nd.
Kailo is offline
TheDiamant953
Member
Join Date: Jan 2013
Old 01-10-2016 , 16:00   Re: Problem with users ID.
Reply With Quote #3

Quote:
Originally Posted by Kailo View Post
Use
Code:
ServerCommand("sm_test1 %d", GetClientUserId(client));
Client index isn't userid. Client index means online player index and can be 0-65 (0 is server).
Userid is index means player session.
Example: while timer gone, one player (with client index 1) left the game, and another connected (and get index 1 because it's free). After timer you will get wrong target. But userid for 1st player is n, and n+1 for 2nd.
But in the second code quote, i take the GetClientUserId, why it dosn't work ?

And what is the differences betwen GetClientUserId and GetClientOfUserId ?

Thanks

Last edited by TheDiamant953; 01-10-2016 at 16:07.
TheDiamant953 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-10-2016 , 16:20   Re: Problem with users ID.
Reply With Quote #4

Quote:
Originally Posted by TheDiamant953
And what is the differences betwen GetClientUserId and GetClientOfUserId ?
One is the opposite of the other. One gives you the client index using the user ID, and the other gives you the user ID using the client index.
__________________
ddhoward is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 01-10-2016 , 18:03   Re: Problem with users ID.
Reply With Quote #5

Quote:
Originally Posted by TheDiamant953 View Post
But in the second code quote, i take the GetClientUserId, why it dosn't work ?

And what is the differences betwen GetClientUserId and GetClientOfUserId ?

Thanks
When you run command you pass client index and next try to get client index from userid, but you used client index as userid.
Another way just remove
Code:
target = GetClientOfUserId(argument1);
because you already pass client index and don't need convert userid in client index.
But pass userid more safety.
Kailo is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-10-2016 , 19:21   Re: Problem with users ID.
Reply With Quote #6

If you're writing a command that takes users as an argument, please use FindTarget (for single-target commands) or ProcessTargetString.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-11-2016 , 10:44   Re: Problem with users ID.
Reply With Quote #7

Quote:
Originally Posted by Powerlord View Post
If you're writing a command that takes users as an argument, please use FindTarget (for single-target commands) or ProcessTargetString.
And if you're just creating commands for inter-plugin communication, create natives instead.
__________________
asherkin is offline
TheDiamant953
Member
Join Date: Jan 2013
Old 01-12-2016 , 16:11   Re: Problem with users ID.
Reply With Quote #8

Thanks for your help.

I don't think i will use FindTaget or ProcessTargetString, i don't understand them, i'm not good at all in scripting and in english :p

But now it's work. Thanks.
TheDiamant953 is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 01-12-2016 , 20:01   Re: Problem with users ID.
Reply With Quote #9

Quote:
Originally Posted by TheDiamant953 View Post
I don't think i will use FindTaget or ProcessTargetString, i don't understand them, i'm not good at all in scripting and in english :p\
FindTarget is more simple and manageable for new scripters. It works like this:
PHP Code:
FindTarget(clientString:target[], bool:nobotsbool:immunity); 
client = client who issued command.
target = String of target to search for by name. In your case, the argument string.
nobots = True for no bots. False otherwise.
immunity = True for admin immunity. You get the idea.

HELPFUL TOOL: https://sm.alliedmods.net/new-api/
thecount 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 19:17.


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