Today I was looking through my server browser, and noticed the lack of tags for game mode indication. I would assume this primarily comes from the fact that sv_tags is a cvar, and I think people are scared of messing with it. With the code here, you will be able to ensure that a tag is always included for your game mode or plugin. Please note this isn't the only way to do this, and probably isn't the most efficient either, but it works.
I didn't code in support for multiple tags per plugin (or at least I didn't intend to)... this can be accomplished easily, but I didn't design this specific example with it in mind. To be honest, one tag is all a plugin should really allocate in order to show it's presence.
Code:
#define CUSTOM_TAG "mycoolplugin"
new bool:KeepMyMouthShut;
new Handle:hTagsCvar;
public OnPluginStart()
{
hTagsCvar = FindConVar("sv_tags");
if(hTagsCvar)
{
HookConVarChange(hTagsCvar, CallbackTags);
KeepMyMouthShut = false;
}
else
{
SetFailState("Error attempting to hook sv_tags! This game doesn't support it?");
}
}
EnsureTagsInclusion(const String:IncludeMe[], const String:CurrentValue[])
{
new String:CurVal[512];
strcopy(CurVal,512,CurrentValue);
// Always just fix their tiny formatting errors.
ReplaceString(CurVal, 512, " ,",",",false);
ReplaceString(CurVal, 512, ", ",",",false);
// Trim it too.
TrimString(CurVal);
// Are we empty? If we are, then automatically append.
// Otherwise, check it and append only if necessary.
if(strlen(CurVal)==0)
{
SetConVarString(hTagsCvar, IncludeMe);
}
else
{
// Now lets get all the current values.
// An easy way to do this is to explode by the comma.
new String:TheStrings[64][64];
new ExpCount = ExplodeString(CurVal, ",", TheStrings, 64, 64);
new bool:IsFound = false;
for(new i=0;i<ExpCount;i++)
{
if(StrEqual(TheStrings[i], IncludeMe, false))
{
IsFound = true;
break;
}
}
if(!IsFound)
{
Format(CurVal, 512, "%s, %s", CurVal, IncludeMe);
SetConVarString(hTagsCvar, CurVal);
}
}
}
public CallbackTags(Handle:convar, const String:oldValue[], const String:newValue[])
{
if(!KeepMyMouthShut)
{
KeepMyMouthShut = true;
EnsureTagsInclusion(CUSTOM_TAG, newValue);
KeepMyMouthShut = false;
}
}
public OnMapStart()
{
new String:CurrentValue[512];
GetConVarString(hTagsCvar, CurrentValue, 512);
EnsureTagsInclusion(CUSTOM_TAG, CurrentValue);
}
Oh... by the way... I haven't tested it. Maybe someone else can?
__________________