Skip to content

Instantly share code, notes, and snippets.

@rsKliPPy
Last active November 24, 2015 00:00
Show Gist options
  • Save rsKliPPy/965270db41f16503770d to your computer and use it in GitHub Desktop.
Save rsKliPPy/965270db41f16503770d to your computer and use it in GitHub Desktop.
My InfoTop plugin
/*
====================================================================================================
Infotop v2.4.0
by KliPPy
Plugin prikazuje informacije svakom igracu na ekranu tokom igre.
Cvarovi:
infotop_colors - RGB kombinacija boja HUDa koji prikazuje informacije(default "200200200")
infotop_hudposx - X pozicija HUDa na ekranu(default "-1.0")
infotop_hudposy - Y poziciija HUDa na ekranu(default "0.02")
infotop_hudchannel - Kanal u kojem se nalazi HUD poruka (default "-1")
infotop_refreshrate - Koliko cesto se refreshuje HUD(default "0.5")
infotop_showto - Kome da se HUD pokazuje? -1 - mrtvima, 1 - zivima, 0 - oboma (default "0")
====================================================================================================
*/
#include <amxmodx>
#include <fakemeta>
#include <engine>
#pragma ctrlchar '\'
#define PLUGIN "Infotop New"
#define VERSION "v2.4.0"
#define AUTHOR "KliPPy"
#define MAX_FILE_CHARS 192
#define MAX_HUD_CHARS 256
#define PATH_MAX 260 // At least for Windows, but should be enough
#define SHOWTO_ALIVE 1
#define SHOWTO_DEAD (-1)
new const ENT_CLASS[] = "infotop_hud";
new const FILE_NAME[] = "infotop_hud.ini";
new const g_szDefaultContent[][] =
{
"# You can use this file to create your own customised info HUD message",
"# Line with a hash sign ( # ) as a first character is a comment, and will not appear in the message",
"# Keep in mind that empty lines are NOT ignored!\n#",
"# There are few \"format specifiers\" which you can use in your message, they will be replaced when shown to a player.",
"# Format Specifiers:",
"# \t%H, %M, %S - Current time (Hours, Minutes, Seconds)",
"# \t%m - Current map name",
"# \t%n - Next map name",
"# \t%p - Current number of players online",
"# \t%c - Server capacity (maximum players)",
"# \t%l - Time/Rounds left, depending on mp_maxrounds/mp_timelimit cvars.",
"# \t%i - Server IP",
"# \t%h - Host name",
"# \t%% - A SINGLE percentage sign\n#",
"# For example:",
"# \tWelcome to %h!",
"# \tAdd our IP to favorites: %i!",
"# Would display something like:",
"# \tWelcome to KliPPy's Public Server!",
"# \tAdd our IP to favorites: 192.168.0.100!",
"#\n#",
"Welcome to %h!",
"IP: %i"
};
new g_pRounds, g_pColors, g_pHudposx, g_pHudposy, g_pRefreshRate, g_pNextMap, g_pHudChannel, g_pHudShowTo;
new g_szMap[32], g_szIp[32], g_szHostName[32];
new g_iTeamScore[2];
new g_iCachedColors[3], Float: g_fCachedHudPos[2], g_iMode, Float: g_fCachedRefRate, g_szCachedHudString[MAX_FILE_CHARS],
g_szCachedMaxPlayers[3], g_iCachedHudChannel, g_iCachedHudShowTo;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
g_pColors = register_cvar("infotop_colors", "200200200");
g_pHudposx = register_cvar("infotop_hudposx", "-1.0");
g_pHudposy = register_cvar("infotop_hudposy", "0.02");
g_pRefreshRate = register_cvar("infotop_refreshrate", "0.5");
g_pHudChannel = register_cvar("infotop_hudchannel", "-1");
g_pHudShowTo = register_cvar("infotop_showto", "3");
g_pRounds = get_cvar_pointer("mp_maxrounds");
g_pNextMap = get_cvar_pointer("amx_nextmap");
register_cvar("infotop_new", VERSION, FCVAR_SERVER | FCVAR_SPONLY);
if(get_pcvar_num(g_pRounds) > 0 && get_cvar_num("mp_timelimit") > 0)
{
log_amx("[Infotop] Both cvars mp_maxrounds and mp_timelimit are greater than 0");
pause("ad");
}
else
{
if(get_pcvar_num(g_pRounds) > 0)
{
g_iMode = 0;
register_message(get_user_msgid("TeamScore"), "msgTeamScore");
}
else
g_iMode = 1;
}
get_mapname(g_szMap, charsmax(g_szMap));
get_user_ip(0, g_szIp, charsmax(g_szIp));
get_user_name(0, g_szHostName, charsmax(g_szHostName));
#if AMXX_VERSION_NUM < 183
num_to_str(get_maxplayers(), g_szCachedMaxPlayers, charsmax(g_szCachedMaxPlayers));
#else
num_to_str(MaxPlayers, g_szCachedMaxPlayers, charsmax(g_szCachedMaxPlayers));
#endif
ReadHudFile();
CacheCvars();
CreateEntity();
}
ReadHudFile()
{
new szLine[MAX_FILE_CHARS / 2]; // You would need at least 2 full lines to create the longeast possible message
new szFile[PATH_MAX];
new hFile;
get_localinfo("amxx_configsdir", szFile, charsmax(szFile));
format(szFile, charsmax(szFile), "%s/%s", szFile, FILE_NAME); // Can't use formatex()!
if(!file_exists(szFile))
{
for(new i = 0; i < sizeof(g_szDefaultContent); i++)
write_file(szFile, g_szDefaultContent[i]);
}
hFile = fopen(szFile, "rt");
if(hFile)
{
while(fgets(hFile, szLine, charsmax(szLine)))
{
if(!szLine[0] || szLine[0] == '#')
continue;
add(g_szCachedHudString, charsmax(g_szCachedHudString), szLine);
}
fclose(hFile);
}
}
CacheCvars()
{
new szColors[10];
get_pcvar_string(g_pColors, szColors, charsmax(szColors));
GetColors(szColors, g_iCachedColors);
g_fCachedHudPos[0] = floatclamp(get_pcvar_float(g_pHudposx), -1.0, 1.0)
g_fCachedHudPos[1] = floatclamp(get_pcvar_float(g_pHudposy), -1.0, 1.0);
g_fCachedRefRate = get_pcvar_float(g_pRefreshRate);
g_iCachedHudChannel = get_pcvar_num(g_pHudChannel);
g_iCachedHudShowTo = get_pcvar_num(g_pHudShowTo);
if(g_iCachedHudChannel != -1)
clamp(g_iCachedHudChannel, 1, 4);
}
CreateEntity()
{
new iEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
if(!pev_valid(iEnt))
{
log_amx("[Infotop] Couldn't create HUD entity.");
return;
}
set_pev(iEnt, pev_classname, ENT_CLASS);
register_think(ENT_CLASS, "fwThink_Hud");
set_pev(iEnt, pev_nextthink, get_gametime() + 3.0);
}
GetColors(const szColors[], iRet[3])
{
new szR[4], szG[4], szB[4];
for(new i = 0; i < 3; i++)
{
szR[i] = szColors[i];
szG[i] = szColors[i + 3];
szB[i] = szColors[i + 6];
}
iRet[0] = str_to_num(szR);
iRet[1] = str_to_num(szG);
iRet[2] = str_to_num(szB);
}
FormatHudString(szHudString[MAX_HUD_CHARS])
{
new i = 0, j = 0;
static iLen;
if(!iLen)
iLen = strlen(g_szCachedHudString);
while(i < MAX_HUD_CHARS - 1 && j <= iLen)
{
if(g_szCachedHudString[j] == '%')
{
static sz3CharString[3];
switch(g_szCachedHudString[++j])
{
case '%':
{
szHudString[i] = '%';
i++;
}
case 'H', 'M', 'S':
{
copy(sz3CharString, charsmax(sz3CharString), g_szCachedHudString[j - 1]);
get_time(sz3CharString, sz3CharString, charsmax(sz3CharString));
i = add(szHudString, charsmax(szHudString), sz3CharString);
}
case 'm':
i = add(szHudString, charsmax(szHudString), g_szMap);
case 'n':
{
static szNextMap[32];
get_pcvar_string(g_pNextMap, szNextMap, charsmax(szNextMap));
if(szNextMap[0] == EOS)
i = add(szHudString, charsmax(szHudString), "None");
else
i = add(szHudString, charsmax(szHudString), szNextMap);
}
case 'p':
{
num_to_str(get_playersnum(), sz3CharString, charsmax(sz3CharString));
i = add(szHudString, charsmax(szHudString), sz3CharString);
}
case 'c':
i = add(szHudString, charsmax(szHudString), g_szCachedMaxPlayers);
case 'l':
{
static szMapLeft[12];
switch(g_iMode)
{
case 1:
{
new iTimeleft = get_timeleft();
new iMinutes = iTimeleft / 60;
new iSeconds = iTimeleft % 60;
formatex(szMapLeft, charsmax(szMapLeft), "%d:%02d", iMinutes, iSeconds);
}
case 0:
{
new iRounds = get_pcvar_num(g_pRounds) - (g_iTeamScore[0] + g_iTeamScore[1]);
num_to_str(iRounds, szMapLeft, charsmax(szMapLeft));
}
}
i = add(szHudString, charsmax(szHudString), szMapLeft);
}
case 'i':
i = add(szHudString, charsmax(szHudString), g_szIp);
case 'h':
i = add(szHudString, charsmax(szHudString), g_szHostName);
}
j++;
continue;
}
szHudString[i++] = g_szCachedHudString[j++]
}
szHudString[i] = EOS;
}
public fwThink_Hud(iEnt)
{
if(!pev_valid(iEnt))
return PLUGIN_CONTINUE;
new szHudString[MAX_HUD_CHARS];
FormatHudString(szHudString);
set_hudmessage(g_iCachedColors[0], g_iCachedColors[1], g_iCachedColors[2],
g_fCachedHudPos[0], g_fCachedHudPos[1], 0, 0.0, g_fCachedRefRate + 0.025, 0.0, 0.0, g_iCachedHudChannel);
new flags[2] = "";
if(g_iCachedHudShowTo == SHOWTO_ALIVE)
flags = "a";
else if(g_iCachedHudShowTo == SHOWTO_DEAD)
flags = "b";
new players[32], iNum;
get_players(players, iNum, flags);
for(new i = 0; i < iNum; i++)
{
show_hudmessage(players[i], szHudString);
}
set_pev(iEnt, pev_nextthink, get_gametime() + g_fCachedRefRate);
return PLUGIN_CONTINUE;
}
public msgTeamScore()
{
new szTeam[2];
get_msg_arg_string(1, szTeam, charsmax(szTeam));
g_iTeamScore[(szTeam[0] == 'C') ? 0 : 1] = get_msg_arg_int(2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment