View Single Post
Durzel
Member
Join Date: Aug 2008
Old 01-12-2009 , 08:48   Re: [L4D] Achievement Notifier
Reply With Quote #17

Quote:
Originally Posted by Antithasys View Post
Further suggestions. I always wonder why people hook the say command when all they want is the chat trigger. Sourcemod does all this for you. Creating your own console command is the way to go.

Replace:
PHP Code:
RegConsoleCmd("say"Command_SayChat);
 
public 
Action:Command_SayChat(clientargs)

 
decl String:text[192];
 if (!
GetConVarBool(cvPluginEnabled) ||
     
IsChatTrigger() ||
  
GetCmdArgString(textsizeof(text)) < 1)
  return 
Plugin_Continue;
 
 
ReplaceString(textsizeof(text), "\"""");
 
ReplaceString(textsizeof(text), " """);
 
 if (
StrEqual(text"!achievements"))
 {
  
DisplayAchievements(client);
  return 
Plugin_Handled;
 }
 
 return 
Plugin_Continue;

With:

PHP Code:
RegConsoleCmd("sm_achievements"Command_DisplayAchievements"Display Achievements");
 
public 
Action:Command_DisplayAchievements(clientargs)

 if (
GetConVarBool(cvPluginEnabled))
     
DisplayAchievements(client);
 return 
Plugin_Handled;

As elegant as this is the only problem I can forsee is that it requires users to have access to the console. Some players don't even know what the console is, much less how to enable it and which key brings it down. Telling those people just to type a command in say is a lot easier than trying to teach them to bring up the console and type a command.

Code wise though the console command method is a lot more elegant.
Durzel is offline