Oh how I hate such randomizing.
Code:
#include <amxmodx>
#include <fakemeta>
new const g_szFile[] = "dgn.ini"; // This should be located in game/mod's directory
new Array:g_aList;
new g_szCurrent[64]; // Don't know the limit of characters for game name
new g_iCount;
new g_iNext;
new g_pType;
new g_pInterval;
public plugin_init()
{
register_plugin("Dynamic Game Name", "1.1", "hleV");
g_pType = register_cvar("amx_dgn_type", "1"); // 0 - one by one, 1 - random
g_pInterval = register_cvar("amx_dgn_interval", "5.0"); // In minutes
g_aList = ArrayCreate(sizeof(g_szCurrent), 1);
new pFile = fopen(g_szFile, "r");
if (!pFile)
return;
new szData[sizeof(g_szCurrent)];
while (!feof(pFile))
{
fgets(pFile, szData, charsmax(g_szCurrent));
trim(szData);
if (szData[0] == ';' || (szData[0] == '/' && szData[1] == '/'))
continue;
ArrayPushString(g_aList, szData);
g_iCount++;
}
register_forward(FM_GetGameDescription, "fnGetGameDescription");
fnUpdateGameName();
}
public fnGetGameDescription()
{
forward_return(FMV_STRING, g_szCurrent);
return FMRES_SUPERCEDE;
}
public fnUpdateGameName()
{
switch (get_pcvar_num(g_pType))
{
case 0:
ArrayGetString(g_aList, g_iCount == 1 ? 0 : ++g_iNext < g_iCount ? g_iNext : (g_iNext = 0), g_szCurrent, charsmax(g_szCurrent));
case 1:
{
if (g_iCount > 1)
while (g_iNext == (g_iNext = random(g_iCount))) {}
else
g_iNext = 0;
ArrayGetString(g_aList, g_iNext, g_szCurrent, charsmax(g_szCurrent));
}
}
set_task(get_pcvar_float(g_pInterval) * 60.0, "fnUpdateGameName");
}