Skip to content

Commit

Permalink
Fix effects being parsed on every map change
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikusch committed Jan 8, 2024
1 parent 7daa4ea commit f8aa2a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
25 changes: 15 additions & 10 deletions addons/sourcemod/scripting/chaos.sp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <vscript>
#include <morecolors>

#define PLUGIN_VERSION "1.5.2"
#define PLUGIN_VERSION "1.5.3"

ConVar sm_chaos_enabled;
ConVar sm_chaos_effect_cooldown;
Expand All @@ -23,6 +23,7 @@ ConVar sm_chaos_meta_effect_chance;
ConVar sm_chaos_effect_update_interval;

bool g_bEnabled;
bool g_bInitialized;
bool g_bNoChaos;
ArrayList g_hEffects;
Handle g_hTimerBarHudSync;
Expand Down Expand Up @@ -124,6 +125,7 @@ public void OnPluginStart()
g_hEffects = new ArrayList(sizeof(ChaosEffect));
g_hTimerBarHudSync = CreateHudSynchronizer();

Data_Initialize();
Events_Initialize();
}

Expand All @@ -139,16 +141,19 @@ public void OnMapStart()
// Initialize VScript system
ServerCommand("script_execute %s", "chaos");

// Initialize all effects
GameData hGameConf = new GameData("chaos");
if (hGameConf)
// Initialize all effects in OnMapStart to guarantee it being called after VScriptServerInit
if (!g_bInitialized)
{
Data_Initialize(hGameConf);
delete hGameConf;
}
else
{
LogError("Failed to find chaos gamedata");
GameData hGameConf = new GameData("chaos");
if (hGameConf)
{
Data_OnVScriptServerInit(hGameConf);
delete hGameConf;
}
else
{
LogError("Failed to find chaos gamedata");
}
}

int nLength = g_hEffects.Length;
Expand Down
18 changes: 10 additions & 8 deletions addons/sourcemod/scripting/chaos/data.sp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ enum struct ProgressBar
}
}

void Data_Initialize(GameData hGameData)
void Data_OnVScriptServerInit(GameData hGameData)
{
// Parse effects
char szFilePath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, szFilePath, sizeof(szFilePath), "configs/chaos/effects.cfg");

Expand Down Expand Up @@ -195,20 +194,23 @@ void Data_Initialize(GameData hGameData)
kv.GoBack();
}
kv.GoBack();

g_bInitialized = true;
LogMessage("Registered %d effects", g_hEffects.Length);
}
else
{
LogError("Could not read from file '%s'", szFilePath);
}
delete kv;
LogMessage("Registered %d effects", g_hEffects.Length);
// Parse visuals
szFilePath[0] = EOS;
}

void Data_Initialize()
{
char szFilePath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, szFilePath, sizeof(szFilePath), "configs/chaos/visuals.cfg");

kv = new KeyValues("visuals");
KeyValues kv = new KeyValues("visuals");
if (kv.ImportFromFile(szFilePath))
{
if (kv.JumpToKey("timer_bar"))
Expand Down

0 comments on commit f8aa2a4

Please sign in to comment.