diff --git a/plugin_loading_unloading/scripting/plugin_loader_unloader.sp b/plugin_loading_unloading/scripting/plugin_loader_unloader.sp index 0ebae1a9..5cc1962d 100644 --- a/plugin_loading_unloading/scripting/plugin_loader_unloader.sp +++ b/plugin_loading_unloading/scripting/plugin_loader_unloader.sp @@ -14,10 +14,11 @@ public Plugin myinfo = 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]; 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. new Handle:fileHandle = OpenFile(sConfigFile, "r" ); char lineBuffer[256]; - bool finished_globals = false; bool found_nextmap = false; while( !IsEndOfFile( fileHandle ) && ReadFileLine( fileHandle, lineBuffer, sizeof( lineBuffer ) ) ) { TrimString( 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)) { found_nextmap = true; @@ -62,3 +54,35 @@ public Action init_plugins(Handle hTimer) CloseHandle( fileHandle ); 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; +}