moved it into two seperate timers

This commit is contained in:
jenz 2024-07-29 02:25:04 +02:00
parent 466b9e5849
commit 46a699dbd9

View File

@ -14,10 +14,11 @@ public Plugin myinfo =
public void OnMapStart() public void OnMapStart()
{ {
CreateTimer(15.0, init_plugins); CreateTimer(10.0, init_plugins_global);
CreateTimer(17.0, init_plugins_map);
} }
public Action init_plugins(Handle hTimer) public Action init_plugins_map(Handle hTimer)
{ {
char sConfigFile[PLATFORM_MAX_PATH]; char sConfigFile[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sConfigFile, sizeof(sConfigFile), "configs/plugins_loading_unloading.cfg"); BuildPath(Path_SM, sConfigFile, sizeof(sConfigFile), "configs/plugins_loading_unloading.cfg");
@ -32,20 +33,11 @@ public Action init_plugins(Handle hTimer)
//for some reason keyvalues did not play along so just reading file instead. //for some reason keyvalues did not play along so just reading file instead.
new Handle:fileHandle = OpenFile(sConfigFile, "r" ); new Handle:fileHandle = OpenFile(sConfigFile, "r" );
char lineBuffer[256]; char lineBuffer[256];
bool finished_globals = false;
bool found_nextmap = false; bool found_nextmap = false;
while( !IsEndOfFile( fileHandle ) && ReadFileLine( fileHandle, lineBuffer, sizeof( lineBuffer ) ) ) while( !IsEndOfFile( fileHandle ) && ReadFileLine( fileHandle, lineBuffer, sizeof( lineBuffer ) ) )
{ {
TrimString( lineBuffer ); TrimString( lineBuffer );
ReplaceString(lineBuffer, sizeof(lineBuffer), "\"", ""); ReplaceString(lineBuffer, sizeof(lineBuffer), "\"", "");
if (StrContains(lineBuffer, "sm plugins") != -1 && !finished_globals)
{
ServerCommand(lineBuffer);
}
if (StrEqual(lineBuffer, "}") && !finished_globals)
{
finished_globals = true;
}
if (StrEqual(lineBuffer, map)) if (StrEqual(lineBuffer, map))
{ {
found_nextmap = true; found_nextmap = true;
@ -62,3 +54,35 @@ public Action init_plugins(Handle hTimer)
CloseHandle( fileHandle ); CloseHandle( fileHandle );
return Plugin_Handled; return Plugin_Handled;
} }
public Action init_plugins_global(Handle hTimer)
{
char sConfigFile[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sConfigFile, sizeof(sConfigFile), "configs/plugins_loading_unloading.cfg");
if(!FileExists(sConfigFile))
{
LogMessage("Could not find config: \"%s\"", sConfigFile);
return Plugin_Handled;
}
char map[PLATFORM_MAX_PATH];
GetCurrentMap(map, PLATFORM_MAX_PATH);
//for some reason keyvalues did not play along so just reading file instead.
new Handle:fileHandle = OpenFile(sConfigFile, "r" );
char lineBuffer[256];
while( !IsEndOfFile( fileHandle ) && ReadFileLine( fileHandle, lineBuffer, sizeof( lineBuffer ) ) )
{
TrimString( lineBuffer );
ReplaceString(lineBuffer, sizeof(lineBuffer), "\"", "");
if (StrContains(lineBuffer, "sm plugins") != -1)
{
ServerCommand(lineBuffer);
}
if (StrEqual(lineBuffer, "}"))
{
break;
}
}
CloseHandle( fileHandle );
return Plugin_Handled;
}