AlliedModders Donor
|
01-25-2019
, 19:04
Re: Novice needing sourcepawn help
|
#8
|
Excellent, good to hear you were able to compile it and get it working the way you wanted.
An include won't do anything more than be included in the compilation of the plugin. It is up to the coder (you) to use what functions, forwards, natives, or stocks that it may have inside it. If none of it is used, you should remove the include as to reduce the size and it's just a good coding habit. In the case I presented earlier, the code used CPrintToChat which was inside of the include you wanted to use (colorvariables.inc). CPrintToChat has other functions inside of it that did all the work in finding the {yellow} color and replacing it with what CS:S uses in order to make the text appear that color when you specified it in your configuration file.
I'll do a step by step for you in trying to describe the replacement string in the first example I provided earlier.
Spoiler
PHP Code:
#include <sourcemod> // Include SourceMod, it has many things this plugin will use
// Cvar
new Handle:g_cvar_file = INVALID_HANDLE; // Creating a global handle so that it can be accessed by other functions.
// This is just to provide the plugin with information regarding who made it and what the plugin does
public Plugin:myinfo =
{
name = "Autoresponder",
author = "Russianeer",
description = "Displays chat advertisements when specified text is said in player chat.",
version = "1.0",
url = "http://www.protf2.com/"
};
// When the plugin starts do this.
public OnPluginStart( )
{
// Commands
RegConsoleCmd("say", Command_Say); // We're registering a console command, say, so that when a client uses the say command (typing in all chat) it will interpret the message.
RegConsoleCmd("say_team", Command_Say); // Same as above but for teamchat.
// Cvars
g_cvar_file = CreateConVar("sm_chat_file", "chat_responses.txt", "Name of the file that contains all the advertisements"); // Create a console variable so that someone can change this if need be, and mentioned before it's global, which means it can be accessed here and elsewhere if desired.
}
// The say hook from before, it has the option of passing along the client and args (arguments), we can use this to find out who said what.
public Action:Command_Say(client, args)
{
new String:text[192]; // declare a string with a certain size, the size can be a length that is either the maximum of what we want, or the maximum it can provide us, up to the conditions you want.
new String:buffers[3][64]; // buffer, we will use this to store information so that it can be passed along since we can't always use the same variable for everything.
new startidx = 0; // A variable set to 0, in this case it's set to 0 as the starting point.
GetCmdArgString(text, sizeof(text)); // Get the command string sent with Say, it's all the text that was sent over.
if (text[0] == '"') {/* Strip the ending quote, if there is one */
startidx = 1;
new len = strlen(text);
if (text[len-1] == '"') {
text[len-1] = '\0';
}
}
ExplodeString( text[startidx], " ", buffers, 3, 64 ); // Breaks a string into pieces and stores each piece into an array of buffers. In this case " " (space) instance, break that into each buffer.
decl String:output[256];
if(LoadAds(text[startidx], output, sizeof(output))) // If LoadAds returns true, value other than 0, do the following.
{
if(StrContains(output, "{GREEN}") != -1) // If the string contains {GREEN} do this...
ReplaceString(output, sizeof(output), "{GREEN}", "\x04"); // Replace {GREEN} which we know now exists with \x04 (code that when used with SayText turns it into a color.
if(StrContains(output, "{OLIVE}") != -1)
ReplaceString(output, sizeof(output), "{YELLOW}", "\x05"); // Added yellow replacement
if(StrContains(output, "{YELLOW}") != -1)
ReplaceString(output, sizeof(output), "{OLIVE}", "\x09");
if(StrContains(output, "{TEAM}") != -1)
ReplaceString(output, sizeof(output), "{TEAM}", "\x03");
if(StrContains(output, "{DEFAULT}") != -1)
ReplaceString(output, sizeof(output), "{DEFAULT}", "\x01");
for (new i = 1; i <= MaxClients; i++) // From 1 to the maximum clients do this...
{
if (IsClientConnected(i) && IsClientInGame(i)) // If the client is in game and connected
SayText2(i, output); // Do this function (SayText2)
}
}
return Plugin_Continue; // Continue doing it is that you do, say
}
I think this is what you will find most helpful in seeing the relationship of \xYY and where in the include it uses it.
https://github.com/ErikMinekus/sm-ad....inc#L966-L983
|
|