Hy!
I'm very much a novice when it comes to tampering with plugins...
I want to enable the usage of more custom colors ({YELLOW} in particular) in this plugin via using "colorvariables.inc" (the same one, which the well known "Advertisements 2.0" plugin uses)
So far I've tried adding "#include <colorvariables>" to the first line of the source code and then compiling the "Autoresponder" plugin with the complier included in the latest sourcemod build.
The compilation was succesful (I had the colorvariables.inc placed in the includes folder), but I'm still not able to use other colors than the four basic ones which were available by default...
Please enlighten me.
Btw, is there a good "getting started with sourcepawn" kind of tutorial available anywhere?
First and most importantly, use the search function on the site. All the answers you seek are more than likely already answered.
Second, this is the wrong place to be seeking help, this section of the forum is for Source Servers (SRCDS). Ask in the correct section, such as scripting. As for why you can only use four of the basic ones, we have no idea, you haven't given any information on what game, any of the code you used, or even what colors you have tried. Don't expect help if you don't provide us with the information to help you. If this is a post about scripting, provide what you are doing and the code you are using, give examples. Also, don't go making another post, edit your post with the correct content and report the post so that a moderator can move it for you.
Tutorials are everywhere if you search. Review the introduction for SourcePawn 1.7: Here you go.
Nice passive aggression on your end, must be a pretty miserable life you lead if you took the time to make me seem stupid, instead of trying to actually help me.
It would have been very easy for someone more versed in plugin making to give me an answer based on the information I gave.
I gave a link to the plugin I was talking about and very clearly worded what my intents were.
This is a very simple problem, yet all I get is an elitist, condescending response with a "let me google that for you" link baked into it.
The all so "abundant" tutorials are nowhere to be found.
The only proper search results in google are the very long winded introductory alliedmods wiki articles, and those, despite their lenght, don't answer my simple, but specific question.
I'm most likely more versed in video editing, monitors and computer mice than you are, but if you were to ask a simple question about them, I wouldn't treat you like a stupid mongrel, (which you just did) but instead I would answer your question, and would be glad that you trusted me with the task of giving you more wisdom... which in turn would leave a good impression in you.
With this toxic and alienating of an approach to newcomers, this community shouldn't be surprised that not many people have the drive to continue trying to learn about sm and sourcepawn, and much less contributing to it.
My apologies for making it come off that way. I still suggest supplying the game(s) you are trying to do this for. Different games handle colors differently, such as TF2 and CS:GO do not handle the same way, and even colors from CS:S and CS:GO are different as well. If colorvariables.inc isn't working for you, it could be how you're using it. There may be a better include that would work for you in this case instead.
You can also check the Snippets and Tutorials section if you want more things to browse.
The game in question is CS:S, and I don't even know if I did the "including" right....did I?
Is putting the include file in the correct folder, and adding that string (#include <colorvariables>) to the first line of the script for the plugin, all there is to "including"?
(I don't even know the proper name for it...up to this point I've only touched config files, not the plugins themselves)
If you would, attach or use the code tags/php tags and give us the code you are using. That include should work with CS:S as it's in the list as supported.
However, I don't see yellow as a listing of available colors in CSS itself, but I do see it in colorvariables.inc as \x09. With that said you don't need to incorporate the include you can just add it to the replacement string, like such:
Spoiler
PHP Code:
#include <sourcemod>
// Cvar new Handle:g_cvar_file = INVALID_HANDLE;
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/" };
public OnPluginStart( ) { // Commands RegConsoleCmd("say", Command_Say); RegConsoleCmd("say_team", Command_Say);
// Cvars g_cvar_file = CreateConVar("sm_chat_file", "chat_responses.txt", "Name of the file that contains all the advertisements"); }
public Action:Command_Say(client, args) { new String:text[192]; new String:buffers[3][64]; new startidx = 0;
GetCmdArgString(text, sizeof(text));
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'; } }
In the above, we've added the replacement ability for {YELLOW} which will use \x09 so that it appears in the game as yellow. You can go ahead and try that one and see if it does come out as yellow. Otherwise we would move onto what the issue you may have been facing. The issue which is that just because you added the include it may not be used, you would need to use the functions that would call those colors.
For this we remove the replacement of colors, such as {GREEN} and let the include do the hard work in replacing that. HOWEVER, you would need to change your .cfg file that has {GREEN} in it to {green} as that's how colorvariables treats those. We use the function CPrintToChat, much like PrintToChat but with the benefit of colorvariables doing the print and changing the colors for us.
Spoiler
PHP Code:
#include <sourcemod> #include <colorvariables>
// Cvar new Handle:g_cvar_file = INVALID_HANDLE;
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/" };
public OnPluginStart( ) { // Commands RegConsoleCmd("say", Command_Say); RegConsoleCmd("say_team", Command_Say);
// Cvars g_cvar_file = CreateConVar("sm_chat_file", "chat_responses.txt", "Name of the file that contains all the advertisements"); }
public Action:Command_Say(client, args) { new String:text[192]; new String:buffers[3][64]; new startidx = 0;
GetCmdArgString(text, sizeof(text));
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'; } }
Let me know if you have any issues compiling it, and of course if I've made any mistakes someone here would certainly love to point it out for me. Unfortunately I can't test it right now but will later and make any corrections to point you in the right direction.
Last edited by Maxximou5; 01-25-2019 at 14:39.
Reason: made a mistake already
Thank you, that was very informative!
I've learned so much from this single post...because it is explained in a relatively noob friendly way, with real world examples!
And yes, CS:S doesn't have a {yellow} text color by default, the advertisements 2.0 plugin does however, which most (including mine) CS:S servers employ.
Now that we've dived into this, let me bore you a bit with the whole story:
I have set up the advertisements plugin so that it displays adverts in green, with a yellow prefix. (Which prefix is the name of my clan: |Happy Lads|)
Which is all fine and dandy, but now that I downloaded the Autoresponder plugin for my servers, I'm stuck wanting consistency... I don't just want to leave out the prefix, or display it in the default color... I want it displayed in yellow.
So I've started looking into how Dj Tsunami got all those colors working in his plugin...looked at the source code of his plugin, and saw that he had these two lines right at the beginning of it:
#include <sourcemod>
#include <colorvariables>
The rest is probably obvious... I'm trying to get all those colors (or at least yellow) working with the Autoresponder plugin.
So back to topic:
I've compiled the second version... because all colors is better than some colors, right? And it works! Thank you! Not only did I accomplish what I wanted, I also learnt things in the process.
However, you saying "With that said you don't need to incorporate the include you can just add it to the replacement string"
makes me wonder, what does incorporating an "include" actually do? Does it have it's drawbacks compared to using a replacement string? And what are the drawbacks of using a replacement string other than the obvious? (More typing to be done)
I'm sorry for seemingly wasting your time btw, but I'm really curious.
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
}
One thing I noticed is that the version which you edited to use "CPrintToChat" now prints a the response to a player's trigger, before their message...
which makes it so that it doesn't seem like it's actually "responding" to it anymore.
The color codes Max used above (yellow = \x09) are specific to CS:GO. For CS:S, some colors can be done using \x03, \x04, etc., but most are achieved using hex color codes. Everywhere you want to change color, put \x07 followed by the 6-digit color code. e.g. Red = \x07FF0000
Hex color codes can be found on many websites such as this or this. Basically, just google search "hex color codes". Hope that helps.
Note: Using the above for formatting colors, you do not need any includes. If you wish to use the More Colors include, you would use its functions (e.g. CPrintToChat or CPrintToChatAll) in combo with the color names in brackets that the plugin creates. However, that is just a wrapper for doing the above hex color codes.