Hey, I've been trying to get chat commands (/command in chat) to work for quite some time now but all tries have been unsuccessful, I have tried several methods but none of them work.
Firstly, I've been trying to hook into `say` command and using that with the code I found online.
OnPluginStart:
Code:
AddCommandListener(Command_SAY, "say");
And after OnPluginStart:
Code:
public Action:Command_SAY(client, const String:command[], argc)
{
decl String:text[192];
new startidx = 0;
if (GetCmdArgString(text, sizeof(text)) < 1)
{
return Plugin_Continue;
}
if (text[strlen(text)-1] == '"')
{
text[strlen(text)-1] = '\0';
startidx = 1;
}
if(strcmp(text[startidx], "/test", false) == 0)
{
PrintToChat(client, "TEST");
}
return Plugin_Continue;
}
Secondly, I tried using Action:OnClientCommand:
Code:
public Action:OnClientCommand(client, args)
{
new String:cmd[16];
GetCmdArg(0, cmd, sizeof(cmd)); /* Get command name */
if(StrEqual(cmd, "test2"))
{
PrintToChat(client, "You have executed the command!!!");
return Plugin_Handled;
}
return Plugin_Continue;
}
Any help would be useful.