Here's a function that retrieves a keyvalue from the worldspawn entity in the current map.
Code:
#include <amxmodx>
#include <regex>
#define CACHE_WORLDSPAWN_DATA
public bool:get_worldspawn_keyvalue(szKeyName[], szRet[], iLen)
{
#if defined CACHE_WORLDSPAWN_DATA
static bGotWorldData = false, szWorldData[1024];
if(!bGotWorldData)
{
#else
new szWorldData[1024];
#endif
new szFileName[128], szMapName[64];
get_mapname(szMapName, 63);
formatex(szFileName, 127, "maps/%s.bsp", szMapName);
new hFile = fopen(szFileName, "rb");
if (hFile)
{
new iOffset, chNewChar, n;
fseek(hFile, 4, SEEK_SET);
fread(hFile, iOffset, BLOCK_INT);
fseek(hFile, iOffset, SEEK_SET);
do
{
fread(hFile, chNewChar, BLOCK_CHAR)
szWorldData[n++] = chNewChar;
}while(n<1024&&chNewChar!='}')
fclose(hFile);
new szBuf[32], iNum, szError[128];
formatex(szBuf, 31, "^"%s^"(.+)^"(.+)^"", szKeyName);
new Regex:hReg = regex_match(szWorldData, szBuf, iNum, szError, 127);
if(hReg>=REGEX_OK)
{
regex_substr(hReg, 2, szRet, iLen-1);
regex_free(hReg);
return true;
}
}
#if defined CACHE_WORLDSPAWN_DATA
}
#endif
return false;
}