as: 1, #1, # 1, and by their nickname.
{
if(argc >= 3)
{
- entity tell_to = GetFilteredEntity(argv(1));
+ entity tell_to = GetIndexedEntity(argc, 1);
float tell_accepted = VerifyClientEntity(tell_to, TRUE, FALSE);
if(tell_accepted > 0) // the target is a real client
{
if(tell_to != self) // and we're allowed to send to them :D
{
- Say(self, FALSE, tell_to, substring(command, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)), TRUE);
+ Say(self, FALSE, tell_to, substring(command, argv_start_index(next_token), argv_end_index(-1) - argv_start_index(next_token)), TRUE);
return;
}
else { print_to(self, "You can't ^2tell^7 a message to yourself."); return; }
return TRUE;
}
+entity GetIndexedEntity(float argc, float start_index)
+{
+ entity tmp_player, selection;
+ float tmp_number;
+ string tmp_string;
+
+ next_token = -1;
+
+ if(argc > start_index)
+ {
+ if(substring(argv(start_index), 0, 1) == "#")
+ {
+ tmp_string = substring(argv(start_index), 1, -1);
+ ++next_token;
+
+ if(tmp_string) // is it all one token? like #1
+ {
+ tmp_number = stof(tmp_string);
+ }
+ else if(argc > next_token) // no, it's two tokens? # 1
+ {
+ tmp_number = stof(argv(next_token));
+ ++next_token;
+ }
+ }
+ else // maybe it's ONLY a number?
+ {
+ tmp_number = stof(argv(start_index));
+ ++next_token;
+ }
+
+ if(VerifyClientNumber(tmp_number))
+ {
+ selection = edict_num(tmp_number); // yes, it was a number
+ }
+ else // no, maybe it's a name?
+ {
+ next_token = (start_index + 1);
+
+ FOR_EACH_CLIENT(tmp_player)
+ if (strdecolorize(tmp_player.netname) == strdecolorize(argv(start_index)))
+ selection = tmp_player;
+ }
+ }
+
+ return selection;
+}
+
// find a player which matches the input string, and return their entity
entity GetFilteredEntity(string input)
{
void timeout_handler_think();
// used by common/command/generic.qc:GenericCommand_dumpcommands to list all commands into a .txt file
-void CommonCommand_macro_write_aliases(float fh);
\ No newline at end of file
+void CommonCommand_macro_write_aliases(float fh);
+
+// keep track of the next token to use for argc
+float next_token;
\ No newline at end of file
{
case CMD_REQUEST_COMMAND:
{
- entity client = GetFilteredEntity(argv(1));
+ entity client = GetIndexedEntity(argc, 1);
float accepted = VerifyClientEntity(client, FALSE, FALSE);
if(accepted > 0)
if(argc == 2)
{
- client = GetFilteredEntity(argv(1));
+ client = GetIndexedEntity(argc, 1);
accepted = VerifyClientEntity(client, TRUE, FALSE);
if(accepted > 0)
{
case "read":
{
- client = GetFilteredEntity(argv(2));
+ client = GetIndexedEntity(argc, 2);
accepted = VerifyClientEntity(client, FALSE, TRUE);
if not(accepted > 0)
}
self = client;
- playerdemo_open_read(argv(3));
+ playerdemo_open_read(argv(next_token));
return;
}
case "write":
{
- client = GetFilteredEntity(argv(2));
+ client = GetIndexedEntity(argc, 2);
accepted = VerifyClientEntity(client, FALSE, FALSE);
if not(accepted > 0)
}
self = client;
- playerdemo_open_write(argv(3));
+ playerdemo_open_write(argv(next_token));
return;
}
{
if(argv(2))
{
- entity client = GetFilteredEntity(argv(1));
+ entity client = GetIndexedEntity(argc, 1));
float accepted = VerifyClientEntity(client, TRUE, FALSE);
if(accepted > 0)
{
- stuffcmd(client, strcat("\n", argv(2), "\n"));
- print(strcat("Command: \"", argv(2), "\" sent to ", GetCallerName(client), " (", argv(1) ,").\n"));
+ stuffcmd(client, strcat("\n", argv(next_token), "\n"));
+ print(strcat("Command: \"", argv(next_token), "\" sent to ", GetCallerName(client), " (", argv(1) ,").\n"));
}
else
print("stuffto: ", GetClientErrorString(accepted, argv(1)), ".\n");