View Single Post
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-10-2022 , 04:37   Re: Can't get a command to target all players
Reply With Quote #4

Either a loop code to look all client indexs, like post above.


Or another function is ProcessTargetString(), which is little advance
https://sm.alliedmods.net/new-api/co...ssTargetString

PHP Code:



public void OnPluginStart()
{
    
RegConsoleCmd("sm_test1"test1);
    
RegConsoleCmd("sm_test2"test2);

    
LoadTranslations("common.phrases"); // You need load translation files when use ProcessTargetString and ReplyToTargetError()
}

void PrintPlayerNameInConsole(int clientint target)
{
    
PrintToConsole(client"Index %i = Player %N"targettarget);
}



public 
Action test1(int clientint args)
{
    for(
int i 1<= MaxClientsi++)
    {
        if(!
IsClientInGame(i) || IsClientSourceTV(i) || IsClientReplay(i))
            continue;

        
PrintPlayerNameInConsole(clienti);
    }

    return 
Plugin_Handled;
}

public 
Action test2(int clientint args)
{
    
// When using command without arguments, print command tip
    
if(args 1)
    {
        
ReplyToCommand(client"[SM] Command usage: sm_test2 @all, sm_test2 @me, sm_test2 @!me, sm_test2 #userid, sm_test2 \"#STEAM_0:1:123\"");

        return 
Plugin_Handled;
    }

    
// Get command first argument
    
char pattern[MAX_NAME_LENGTH];
    
GetCmdArg(1patternsizeof(pattern));




    
int targetcount;
    
int targetsarray[MAXPLAYERS+1];

    
char target_name[MAX_NAME_LENGTH];

    
bool tn_is_ml// true, when target_name return as multi-target phrase. False, when return one target name

    
targetcount ProcessTargetString(pattern,
                                    
0,    // When admin is server console = 0 index, we bypass admin immunity check
                                    
targetsarray,
                                    
sizeof(targetsarray),
                                    
0,
                                    
target_name,
                                    
sizeof(target_name),
                                    
tn_is_ml);

    if(
targetcount <= COMMAND_TARGET_NONE)
    {
        
ReplyToTargetError(clienttargetcount);
        return 
Plugin_Handled;
    }
    else
    {
        for(
int x 0targetcountx++)
        {
            
PrintPlayerNameInConsole(clienttargetsarray[x]);
        }
        
        if(
tn_is_ml)
        {
            
PrintToConsole(client"tn_is_ml - Admin argument %s, target to %s"patterntarget_name);
        }
        else
        {
            
PrintToConsole(client"Admin argument %s, target to %s"patterntarget_name);
        }
    }

    return 
Plugin_Handled;

__________________
Do not Private Message @me
Bacardi is offline