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 client, int target)
{
PrintToConsole(client, "Index %i = Player %N", target, target);
}
public Action test1(int client, int args)
{
for(int i = 1; i <= MaxClients; i++)
{
if(!IsClientInGame(i) || IsClientSourceTV(i) || IsClientReplay(i))
continue;
PrintPlayerNameInConsole(client, i);
}
return Plugin_Handled;
}
public Action test2(int client, int 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(1, pattern, sizeof(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(client, targetcount);
return Plugin_Handled;
}
else
{
for(int x = 0; x < targetcount; x++)
{
PrintPlayerNameInConsole(client, targetsarray[x]);
}
if(tn_is_ml)
{
PrintToConsole(client, "tn_is_ml - Admin argument %s, target to %s", pattern, target_name);
}
else
{
PrintToConsole(client, "Admin argument %s, target to %s", pattern, target_name);
}
}
return Plugin_Handled;
}
__________________