PDA

View Full Version : Suppress visible chat triggers?


Dr. McKay
01-15-2012, 17:21
I need a way to suppress the visible chat triggers (such as !rtd). I know a slash can be used instead, but I need a way to suppress the visible trigger also for specific commands.

I tried hooking say and returning Plugin_Handled, but that prevents the command from being used.

Can someone help me out please?

Impact123
01-15-2012, 17:56
#include <sourcemod>



public OnPluginStart()
{
RegConsoleCmd("sm_test", Command_Test);
AddCommandListener(Listener, "say");
}



public Action:Command_Test(client, args)
{
if(client > 0 && IsClientConnected(client) && IsClientInGame(client))
{
PrintToChat(client, "It works!");
}

}



public Action:Listener(client, const String:command[], argc)
{
if(IsChatTrigger())
{
return Plugin_Handled;
}

return Plugin_Continue;
}Works for me.
Here (http://forums.alliedmods.net/showpost.php?p=1631379&postcount=7) is another example.

Yours sincerely
Impact

Dr. McKay
01-15-2012, 21:33
#include <sourcemod>



public OnPluginStart()
{
RegConsoleCmd("sm_test", Command_Test);
AddCommandListener(Listener, "say");
}



public Action:Command_Test(client, args)
{
if(client > 0 && IsClientConnected(client) && IsClientInGame(client))
{
PrintToChat(client, "It works!");
}

}



public Action:Listener(client, const String:command[], argc)
{
if(IsChatTrigger())
{
return Plugin_Handled;
}

return Plugin_Continue;
}Works for me.
Here (http://forums.alliedmods.net/showpost.php?p=1631379&postcount=7) is another example.

Yours sincerely
Impact

Yes, but is there a way to suppress only certain chat triggers? Like !command1 doesn't show up in chat but !command2 does?

McFlurry
01-15-2012, 22:10
The below code should go in the listener.
decl String:command[32];
GetCmdArg(0, command, sizeof(command));Cmd argument 0 is the name of the command. Then simply compare to what you want to block
if(IsChatTrigger() && StrEqual(command, "commandtoblock"))
{
return Plugin_Handled;
}

But you would also have to make sure that the player didn't put in the "sm_" prefix in the trigger.

Impact123
01-16-2012, 01:41
Here's an untested example if you wanna hardcode it.
You can also do it per cvar & ExplodeString, or KV or something you like.


#include <sourcemod>



new String:MyCommands[][] = {"!command1", "!command2"}
new MComSize = sizeof(MyCommands);




public OnPluginStart()
{
RegConsoleCmd("sm_test", Command_Test);
AddCommandListener(Listener, "say");
}



public Action:Command_Test(client, args)
{
if(client > 0 && IsClientConnected(client) && IsClientInGame(client))
{
PrintToChat(client, "It works!");
}
}



public Action:Listener(client, const String:command[], argc)
{
if(IsChatTrigger())
{
new String:Arg0[128];
GetCmdArg(0, Arg0, sizeof(Arg0));
StripQuotes(Arg0);

for(new i; i < MComSize; i++)
{
if(StrEqual(Arg0, MyCommands[i], false))
{
return Plugin_Handled;
}
}
}

return Plugin_Continue;
}
Yours sincerely
Impact

McFlurry
01-16-2012, 02:44
One thing with your snippet Impact, command triggers are case sensitive, you have to use case sensitive checking when you compare the strings.