Code:
/* Plugin Template generated by Pawn Studio */
// Thanks DJ Tsunami
#include <sourcemod>
#define CVAR_FLAGS FCVAR_PLUGIN
#define PLUGIN_VERSION "1.7"
public Plugin:myinfo =
{
name = "Game Mode Config Loader",
author = "Thraka",
description = "Executes a config file based on the current mp_gamemode and z_difficulty",
version = PLUGIN_VERSION,
url = "http://forums.alliedmods.net/showthread.php?t=93212"
}
new Handle:g_hGameMode;
new Handle:g_hDifficulty;
//coop,realism,survival,versus,teamversus,scavenge,teamscavenge
new Handle:g_hConVar_ConfigCoop;
new Handle:g_hConVar_ConfigVersus;
new Handle:g_hConVar_ConfigTeamVersus;
new Handle:g_hConVar_ConfigSurvival;
new Handle:g_hConVar_ConfigRealism;
new Handle:g_hConVar_ConfigScavenge;
new Handle:g_hConVar_ConfigTeamScavenge;
new Handle:g_hConVar_ConfigCoop_Easy;
new Handle:g_hConVar_ConfigCoop_Normal;
new Handle:g_hConVar_ConfigCoop_Hard;
new Handle:g_hConVar_ConfigCoop_Impossible;
new Handle:g_hConVar_ConfigReal_Easy;
new Handle:g_hConVar_ConfigReal_Normal;
new Handle:g_hConVar_ConfigReal_Hard;
new Handle:g_hConVar_ConfigReal_Impossible;
public OnPluginStart()
{
g_hGameMode = FindConVar("mp_gamemode"); //coop, versus, survival
g_hDifficulty = FindConVar("z_difficulty"); //Easy, Normal, Hard, Impossible
CreateConVar("gamemode_config_ver", PLUGIN_VERSION, "Version of the game mode config loader plugin.", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY);
g_hConVar_ConfigCoop = CreateConVar("gamemode_config_coop", "coop.cfg", "CFG file to execute when game mode is coop.", CVAR_FLAGS);
g_hConVar_ConfigVersus = CreateConVar("gamemode_config_versus", "versus.cfg", "CFG file to execute when game mode is versus.", CVAR_FLAGS);
g_hConVar_ConfigTeamVersus = CreateConVar("gamemode_config_teamversus", "teamversus.cfg", "CFG file to execute when game mode is teamversus.", CVAR_FLAGS);
g_hConVar_ConfigSurvival = CreateConVar("gamemode_config_survival", "survival.cfg", "CFG file to execute when game mode is survival.", CVAR_FLAGS);
g_hConVar_ConfigRealism = CreateConVar("gamemode_config_realism", "realism.cfg", "CFG file to execute when game mode is realism.", CVAR_FLAGS);
g_hConVar_ConfigScavenge = CreateConVar("gamemode_config_scavenge", "scavenge.cfg", "CFG file to execute when game mode is scavenge.", CVAR_FLAGS);
g_hConVar_ConfigTeamScavenge = CreateConVar("gamemode_config_teamscavenge", "teamscavenge.cfg", "CFG file to execute when game mode is teamscavenge.", CVAR_FLAGS);
g_hConVar_ConfigCoop_Easy = CreateConVar("gamemode_config_coop_easy", "coop_easy.cfg", "CFG file to execute when game mode is coop and the difficulty is Easy.", CVAR_FLAGS);
g_hConVar_ConfigCoop_Normal = CreateConVar("gamemode_config_coop_normal", "coop_normal.cfg", "CFG file to execute when game mode is coop and the difficulty is Normal.", CVAR_FLAGS);
g_hConVar_ConfigCoop_Hard = CreateConVar("gamemode_config_coop_hard", "coop_hard.cfg", "CFG file to execute when game mode is coop and the difficulty is Advanced.", CVAR_FLAGS);
g_hConVar_ConfigCoop_Impossible = CreateConVar("gamemode_config_coop_impossible", "coop_impossible.cfg", "CFG file to execute when game mode is coop and the difficulty is Expert.", CVAR_FLAGS);
g_hConVar_ConfigReal_Easy = CreateConVar("gamemode_config_realism_easy", "realism_easy.cfg", "CFG file to execute when game mode is realism and the difficulty is Easy.", CVAR_FLAGS);
g_hConVar_ConfigReal_Normal = CreateConVar("gamemode_config_realism_normal", "realism_normal.cfg", "CFG file to execute when game mode is realism and the difficulty is Normal.", CVAR_FLAGS);
g_hConVar_ConfigReal_Hard = CreateConVar("gamemode_config_realism_hard", "realism_hard.cfg", "CFG file to execute when game mode is realism and the difficulty is Advanced.", CVAR_FLAGS);
g_hConVar_ConfigReal_Impossible = CreateConVar("gamemode_config_realism_impossible", "realism_impossible.cfg", "CFG file to execute when game mode is realism and the difficulty is Expert.", CVAR_FLAGS);
HookConVarChange(g_hGameMode, ConVarChange_GameMode);
HookConVarChange(g_hDifficulty, ConVarChange_Difficulty);
}
public OnMapStart()
{
ExecuteConfig();
}
public ConVarChange_GameMode(Handle:convar, const String:oldValue[], const String:newValue[])
{
if (strcmp(oldValue, newValue) != 0)
{
ExecuteConfig();
}
}
public ConVarChange_Difficulty(Handle:convar, const String:oldValue[], const String:newValue[])
{
if (strcmp(oldValue, newValue) != 0)
{
ExecuteConfig();
}
}
ExecuteConfig()
{
decl String:sGameMode[16];
decl String:sConfigName[256];
GetConVarString(g_hGameMode, sGameMode, sizeof(sGameMode));
if (StrEqual(sGameMode, "coop", false))
{
GetConVarString(g_hConVar_ConfigCoop, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
// Exec difficulty
decl String:sGameDifficulty[16];
GetConVarString(g_hDifficulty, sGameDifficulty, sizeof(sGameDifficulty));
if (StrEqual(sGameDifficulty, "Easy", false))
{
GetConVarString(g_hConVar_ConfigCoop_Easy, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
else if (StrEqual(sGameDifficulty, "Normal", false))
{
GetConVarString(g_hConVar_ConfigCoop_Normal, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
else if (StrEqual(sGameDifficulty, "Hard", false))
{
GetConVarString(g_hConVar_ConfigCoop_Hard, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
else if (StrEqual(sGameDifficulty, "Impossible", false))
{
GetConVarString(g_hConVar_ConfigCoop_Impossible, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
}
else if (StrEqual(sGameMode, "survival", false))
{
GetConVarString(g_hConVar_ConfigSurvival, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
else if (StrEqual(sGameMode, "versus", false))
{
GetConVarString(g_hConVar_ConfigVersus, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
else if (StrEqual(sGameMode, "teamversus", false))
{
GetConVarString(g_hConVar_ConfigTeamVersus, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
else if (StrEqual(sGameMode, "realism", false))
{
GetConVarString(g_hConVar_ConfigRealism, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
// Exec difficulty
decl String:sGameDifficulty[16];
GetConVarString(g_hDifficulty, sGameDifficulty, sizeof(sGameDifficulty));
if (StrEqual(sGameDifficulty, "Easy", false))
{
GetConVarString(g_hConVar_ConfigReal_Easy, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
else if (StrEqual(sGameDifficulty, "Normal", false))
{
GetConVarString(g_hConVar_ConfigReal_Normal, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
else if (StrEqual(sGameDifficulty, "Hard", false))
{
GetConVarString(g_hConVar_ConfigReal_Hard, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
else if (StrEqual(sGameDifficulty, "Impossible", false))
{
GetConVarString(g_hConVar_ConfigReal_Impossible, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
}
else if (StrEqual(sGameMode, "scavenge", false))
{
GetConVarString(g_hConVar_ConfigScavenge, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
else if (StrEqual(sGameMode, "teamscavenge", false))
{
GetConVarString(g_hConVar_ConfigTeamScavenge, sConfigName, sizeof(sConfigName));
TrimString(sConfigName);
ServerCommand("exec %s", sConfigName);
}
}