View Single Post
Author Message
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 04-20-2018 , 04:24   [INC] Menu Targeting
Reply With Quote #1

I didn't like the behaviour of the stock SM function FindTarget so I made this instead. Issue with FindTarget is that when you type a name and there are multiple matches it does pretty much nothing (other than an error).

This include file defines a stock function SelectTarget that works similar to FindTarget, but opens a menu to the client with all the possible matches if there are more than 1.

Best way to explain this is through an example:
PHP Code:
#include <sourcemod>
#include <menu_targeting>

public void OnPluginStart()
{
    
RegConsoleCmd"sm_selecttarget"Command_SelectTarget );
}

public 
Action Command_SelectTargetint clientint args )
{
    
char target[MAX_NAME_LENGTH];
    
GetCmdArgStringtargetsizeof(target) );
    
    
// stock bool SelectTarget( int client, const char[] targetname, MenuTargetingCB cb )
    
if( !SelectTargetclienttargetPrintName ) )
    {
        
ReplyToCommandclient"[SM] No targets found ..." );
    }

    return 
Plugin_Handled;
}

public 
void PrintNameint clientint target )
{
    
PrintToChattarget"[SM] I wish lambdas existed in SourcePawn :(" );

If there were 3 players on the server named "Ta", "Tac" and "Taco" and the user input was "Ta", then a menu shows up to the client with those 3 possible matches and the callback is called for whichever is chosen.
If the user input was instead "Taco", there is only 1 match and the callback is called immediately.
Attached Files
File Type: inc menu_targeting.inc (2.1 KB, 264 views)

Last edited by hmmmmm; 04-20-2018 at 04:28. Reason: Actually add the include :D
hmmmmm is offline