Raised This Month: $51 Target: $400
 12% 

different ways to trigger !chat command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 03-24-2016 , 23:28   different ways to trigger !chat command
Reply With Quote #1

hi,
i'm not familar with sourcepawn, i couldnd write a plugin from scratch. but i know how to read & edit sourcecodes. i read many sources recently and found 3 different ways to trigger/read a chat command.
What are the pros and contras of these ways to handle a chat command?

thanks in advance

shanapu

Code:
public OnPluginStart()
{
	
	RegConsoleCmd("sm_test1", TestOn);
	
}

public Action:TestOn(client, args)
{
	PrintToChatAll("Hello world")
}
Code:
public OnPluginStart()
{
	
	HookEvent("player_say", PlayerSay);
	
}


public PlayerSay(Handle:event, String:name[], bool:dontBroadcast)
{
	
	decl String:text[256];
	GetEventString(event, "text", text, sizeof(text));
	if (StrEqual(text, "!test2"))
	{
		PrintToChatAll("Hello world")
	}
}
Code:
public OnPluginStart()
{
	
	AddCommandListener(Event_Say, "say");
	AddCommandListener(Event_Say, "say_team");
	
}

public Action:Event_Say(clientIndex, const String:command[], arg)
{
	static String:menuTriggers[][] = { "!test3" };
	
	decl String:text[24];
	GetCmdArgString(text, sizeof(text));
	StripQuotes(text);
	TrimString(text);
	
	for(new i = 0; i < sizeof(menuTriggers); i++)
		{
			if (StrEqual(text, menuTriggers[i], false))
			{
				PrintToChatAll("Hello world")
			}
		}
}
shanapu is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 03-25-2016 , 00:47   Re: different ways to trigger !chat command
Reply With Quote #2

Unless you have a special reason not to (like the command already exists, and you're trying to block it with another plugin), you pretty much always want to use the Reg*Cmd natives to create commands. In addition to being simple and pretty much handled by Sourcemod itself, it also allows use of simple overrides.

Another advantage is that it supports the changing of the triggers without needing to edit the plugin. For example, some servers might set their silent trigger, which is / on most servers, to be something weird like \ or even $. Similarly, the non-silent trigger can also be changed.
__________________

Last edited by ddhoward; 03-25-2016 at 00:49.
ddhoward is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 03-25-2016 , 16:09   Re: different ways to trigger !chat command
Reply With Quote #3

Quote:
Originally Posted by ddhoward View Post
Unless you have a special reason not to (like the command already exists, and you're trying to block it with another plugin), ...
What are other special reasons? and what the advantage of using Method 2 & 3?

I understand the advantage of RegConsoleCmd but why i see "so many" plugins doesnt use regconsolecmd? cant explain it with cmd exist.
shanapu is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 03-25-2016 , 16:15   Re: different ways to trigger !chat command
Reply With Quote #4

There is pretty much no reason to use method 2, ever.

Method 3 is only useful if the command already exists and you're trying to hook it, or you, for some reason, don't want to "register" an actual command.

Method 1 is the only sane option.
__________________

Last edited by ddhoward; 03-25-2016 at 16:19.
ddhoward is offline
blaacky
Senior Member
Join Date: Oct 2012
Old 03-25-2016 , 17:32   Re: different ways to trigger !chat command
Reply With Quote #5

I'd say only ever use method 2 or 3 if you ever have a reason to unregister a command. Because you can't remove commands that have been registered via RegConsoleCmd
blaacky is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 03-25-2016 , 18:37   Re: different ways to trigger !chat command
Reply With Quote #6

Quote:
Originally Posted by ddhoward View Post
... or you, for some reason, don't want to "register" an actual command...
Quote:
Originally Posted by blaacky View Post
... if you ever have a reason to unregister a command. Because you can't remove commands that have been registered via RegConsoleCmd
What could be a reasons you want a unregistered cmd? im not fully through it.
shanapu is offline
blaacky
Senior Member
Join Date: Oct 2012
Old 03-25-2016 , 19:12   Re: different ways to trigger !chat command
Reply With Quote #7

I've had to unregister commands before because in a large plugin I made some commands are created through a config file. If the server owner changes the words in the config file then it needs different commands then before, so I use something like method 3
blaacky is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-25-2016 , 19:40   Re: different ways to trigger !chat command
Reply With Quote #8

Ive hit this deregistering issue for similar reasons.

I worked around this by registering all my commands to one callback for processing.

When a command is no longer used i just ignore it.
__________________
Neuro Toxin is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 03-25-2016 , 20:20   Re: different ways to trigger !chat command
Reply With Quote #9

http://ddhoward.bitbucket.org/script...alidClient.inc
http://ddhoward.bitbucket.org/script...rd_updater.inc

In these includes, which I made, exist "commands" which must be shared between all plugins that utilize the include. AddCommandListener seems more appropriate in this case. Further, the use of AddCommandListener causes the "command" to not appear in sm_searchcmd or sm_help, preventing cluttering up these lists.
__________________

Last edited by ddhoward; 03-25-2016 at 20:21.
ddhoward is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 03-26-2016 , 21:31   Re: different ways to trigger !chat command
Reply With Quote #10

thanks for your feedback guys!
shanapu is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode