View Single Post
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 04-21-2018 , 05:35   Re: [INC] Menu Targeting
Reply With Quote #2

Or, you could just use ProcessTargetString, which is what FindTarget calls internally.

Edit: For an example of how to use it:

PHP Code:
// Somewhere earlier on, such as OnPluginStart
    
LoadTranslations("common.phrases");

public 
Action Command_SelectTargetint clientint args )
{
    
// Note: We changed this char length; this is defined in commandfilters.inc
    
char target[MAX_TARGET_LENGTH];
    
GetCmdArgStringtargetsizeof(target) );
    
    
int displayTo[MaxClients];

    
// Since this is intended to display a menu:
    // Filters say to ignore admin immunity levels and also not select bots
    
int count ProcessTargetString(targetclientdisplayTosizeof(displayTo), COMMAND_FILTER_NO_IMMUNITY|COMMAND_FILTER_NO_BOTS);
    if (
count 1)
    {
        
// This handles "target not found" and the like
        
ReplyToTargetError(clientcount);
        return 
Plugin_Handled;
    }

    
// displayTo[0] through displayTo[count-1] now contain client indexes of all matching clients that you can iterate through using a for loop
    
for (int i 0counti++)
    {
        
// Do something with displayTo[i]
        
PrintToChatdisplayTo[i], "[SM] This is boring and uses a for loop instead of a callback :(" );
    }
    return 
Plugin_Handled;

__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 04-21-2018 at 05:57.
Powerlord is offline