Raised This Month: $12 Target: $400
 3% 

[INC] Menu Targeting


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 


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 17:49.


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