Raised This Month: $7 Target: $400
 1% 

Finding all clients with a partial name match using ProcessTargetString


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ScardyBob
New Member
Join Date: Jul 2008
Old 09-04-2016 , 04:08   Finding all clients with a partial name match using ProcessTargetString
Reply With Quote #1

What I Want to Do: Get a list of all players based on a partial name match

For example, if players bob1, bob2, and bob3 are on the server and I type !pick bob, it'll put the client id's of bob1, bob2, and bob3 in an array for later use.

Currently, I'm using ProcessTargetString to find a client based on a partial name match, but it only works if there is only one possible client match (I get "More than one client matched the given pattern" for the above scenario). Can ProcessTargetString be used for multiple targets or is there another way to get what I want?

The relevant sections of the code are shown here:
Code:
public Action:PUG_pick(ccid, args)
{
	char atname[MAX_NAME_LENGTH], tname[MAX_NAME_LENGTH];
	int tlist[MAXPLAYERS], tcount;
	bool tn_is_ml;
	GetCmdArg(1, atname, sizeof(atname));
	if ((tcount = ProcessTargetString(
			atname,
			ccid,
			tlist,
			MAXPLAYERS,
			COMMAND_FILTER_CONNECTED,
			tname,
			sizeof(tname),
			tn_is_ml)) <= 0)
	{
		//This function replies to the admin with a failure message
		ReplyToTargetError(ccid, tcount);
		return Plugin_Handled;
	}
	for (int i = 0; i<tcount; i++)
	{
		PrintToChatAll("tcount: %i, tlist[i]: %i, atname: %s, tname: %s, i: %i, tn_is_ml: %i", tcount, tlist[i], atname, tname, i, tn_is_ml);
	}
	return Plugin_Handled;
}
ScardyBob is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-04-2016 , 05:28   Re: Finding all clients with a partial name match using ProcessTargetString
Reply With Quote #2

I would do second processtargetstring when it return that error COMMAND_TARGET_AMBIGUOUS
and rearrange targets array with matching argument.

quick snip
PHP Code:
public void OnPluginStart()
{
    
RegConsoleCmd("sm_test"test);
}

public 
Action test(int clientint args)
{
    
char arg[MAX_NAME_LENGTH];
    
GetCmdArg(1argsizeof(arg));

    
int targets[MAXPLAYERS];
    
int count;
    
bool tn_is_ml;
    
char target_name[MAX_TARGET_LENGTH];
    
int filter COMMAND_FILTER_CONNECTED

    
if((count ProcessTargetString(arg,
                           
client
                           
targets,
                           
sizeof(targets),
                           
filter,
                           
target_name,
                           
sizeof(target_name),
                           
tn_is_ml)) <= 0)
        {
            if(
count == COMMAND_TARGET_AMBIGUOUS)
            {
                
char buffer[MAX_NAME_LENGTH];
                
int new_count;

                
count ProcessTargetString("@all",
                                           
client
                                           
targets,
                                           
sizeof(targets),
                                           
filter,
                                           
target_name,
                                           
sizeof(target_name),
                                           
tn_is_ml);
                for(
int i 0counti++)
                {
                    
GetClientName(targets[i], buffersizeof(buffer));
                    if(
StrContains(bufferargfalse) != -1)
                    {
                        
targets[new_count] = targets[i];
                        
new_count++;
                    }
                }
                
count new_count;
                
tn_is_ml false;
                
Format(target_namesizeof(target_name), arg);
            }
            else
            {
                
//ReplyToTargetError(client, count);
                
PrintToServer("error %i"count);
                return 
Plugin_Handled;
            }
        }


    for(
int i 0counti++)
    {
        
PrintToServer("targets %N"targets[i]);
    }

    if(
tn_is_ml)
    {
        
PrintToServer("Perform action to %T"target_nameclient);
    }
    else
    {
        
PrintToServer("Perform action to %s"target_name);
    }
    return 
Plugin_Handled;

__________________
Do not Private Message @me

Last edited by Bacardi; 09-04-2016 at 05:40. Reason: asd
Bacardi is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 09-04-2016 , 06:42   Re: Finding all clients with a partial name match using ProcessTargetString
Reply With Quote #3

Are you sure you are not passing COMMAND_FILTER_NO_MULTI as a filter flag? There are plenty of examples in the stock plugins of ProcessTargetString working just fine for multiple targets with the code you posted.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-04-2016 , 07:52   Re: Finding all clients with a partial name match using ProcessTargetString
Reply With Quote #4

I remember this "problem" have been a while.
Still can use multi target strings like @all, but can't target multiple players by partial of name.
Quote:
Originally Posted by DJ Tsunami View Post
Are you sure you are not passing COMMAND_FILTER_NO_MULTI as a filter flag? There are plenty of examples in the stock plugins of ProcessTargetString working just fine for multiple targets with the code you posted.
__________________
Do not Private Message @me
Bacardi is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 09-04-2016 , 13:52   Re: Finding all clients with a partial name match using ProcessTargetString
Reply With Quote #5

A future version of Dynamic Targeting will include a way to target multiple clients by partial name match, without modifying the plugin which "owns" the command.
__________________
ddhoward is offline
Reply


Thread Tools
Display Modes

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:37.


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