Onconsoletext always returns unknown command ...
#3

Код:
new UsePlayerid = -1;

public OnRconCommand(cmd[])
{
	new cmdtext[256], tmp[256], idx;
	new String[128];
	cmdtext = strtok(cmd, idx);

	if(!strcmp(cmdtext,"chat",true))
	{
		tmp = bigstrtok(cmd, idx);
		if(strlen(tmp))
		{
			if(UsePlayerid != -1 && IsPlayerConnected(UsePlayerid))
			{
				new name[MAX_PLAYER_NAME];
				new textstring[128];
				format(textstring, sizeof(textstring), "[%i] %s", UsePlayerid, tmp);
				GetPlayerName(UsePlayerid, name, sizeof name);
				SendPlayerMessageToAll(UsePlayerid, textstring);
				printf("[chat] [%s]: %s", name, tmp);
			}
			else
			{
				format(String, sizeof String, "RconPlayer: [-1] %s", tmp);
				SendClientMessageToAll(0xFFFFFFAA, String);
				printf("[chat] [RconPlayer]: %s", tmp);
			}
		}
		return 1;
	}

	if(!strcmp(cmdtext,"useplayer",true))
	{
		tmp = strtok(cmd, idx);
		if(strlen(tmp))
		{
			UsePlayerid = strval(tmp);
			if(IsPlayerConnected(UsePlayerid) || UsePlayerid == -1)
			{
				if(UsePlayerid == -1)
				{
					print("You are now using RconPlayer (ID -1) to chat with.");
				}
				else
				{
					new name[MAX_PLAYER_NAME];
					GetPlayerName(UsePlayerid, name, sizeof name);
					printf("You are now using %s (ID %i) to chat with.", name, UsePlayerid);
				}
			}
			else
			{
				printf("ID %i is not a valid playerid.", UsePlayerid);
			}
		}
		return 1;
	}
	return 1;
}

strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' '))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}

stock bigstrtok(const string[], &idx)
{
  new length = strlen(string);
	while ((idx < length) && (string[idx] <= ' '))
	{
		idx++;
	}
	new offset = idx;
	new result[128];
	while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
	{
		result[idx - offset] = string[idx];
		idx++;
	}
	result[idx - offset] = EOS;
	return result;
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)