/*================================================================================
   
    ----------------------------
    -*- [ZP] HUD Information -*-
    ----------------------------
   
    This plugin is part of Zombie Plague Mod and is distributed under the
    terms of the GNU General Public License. Check ZP_ReadMe.txt for details.
   
================================================================================*/
 
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>
#include <xs>
#include <zp50_class_human>
#include <zp50_class_zombie>
#define LIBRARY_NEMESIS "zp50_class_nemesis"
#include <zp50_class_nemesis>
#define LIBRARY_SURVIVOR "zp50_class_survivor"
#include <zp50_class_survivor>
#define LIBRARY_AMMOPACKS "zp50_ammopacks"
#include <zp50_ammopacks>
 
 
new const hud_tag[] = ""
 
new const mode_names[][] =
{
    "", // No mode Started
    "Normál FertĹ‘zĂ©s",        // Normal Infection, single round
    "Nemesis mĂłd",           // Nemesis Mode (zombie boss)
    "TĂşlĂ©lĹ‘ mĂłd",      // Survivor Mode (human boss)
    "Raj mĂłd",           // Swarm round (no infections)
    "Többszörös FertĹ‘zĂ©s",      // Multiple Infection (like single round, but, more than 1 zombie)
    "Pestis mĂłd",            // Plague round (nemesis & zombies vs. survivors & humans)
    "Ismeretlen mĂłd",        // An unofficial mode (edited/created/modified by user)
    "Armageddon"        // An unofficial mode (edited/created/modified by user)
}
new const rgb_hud_colors[sizeof(mode_names)][3] =
{
//  R   G   B
         {29,   69,     139},       // No mode Started
    {29,    69,     139},       // Normál Mód
    {255,   42,     0},     // Nemesis Mód
    {0,     85,     255},       // Túlélő Mód
    {42,    255,    170},       // Raj Mód
    {0,     85,     255},       // Többszörös Fertőzés
    {170,   127,    255},       // Pestis Mód
    {0,     200,    250},       // Ismeretlen Mód
    {42,    85,     255}        // Armageddon
}
 
 
 
 
// X Hudmessage Position ( --- )
const Float:HUD_MODE_X = 0.0
 
// Y Hudmessage Position ( ||| )
const Float:HUD_MODE_Y = 0.2
 
// Time at which the Hudmessage is displayed. (when user is puted into the Server)
const Float:START_TIME = 3.0
 
const Float:HUD_SPECT_X = 0.4
const Float:HUD_SPECT_Y = 0.9
const Float:HUD_STATS_X = 0.4
const Float:HUD_STATS_Y = 0.9
 
const HUD_STATS_ZOMBIE_R = 255
const HUD_STATS_ZOMBIE_G = 127
const HUD_STATS_ZOMBIE_B = 170
 
const HUD_STATS_HUMAN_R = 0
const HUD_STATS_HUMAN_G = 200
const HUD_STATS_HUMAN_B = 250
 
const HUD_STATS_SPEC_R = 170
const HUD_STATS_SPEC_G = 85
const HUD_STATS_SPEC_B = 255
 
#define TASK_SHOWHUD 100
#define ID_SHOWHUD (taskid - TASK_SHOWHUD)
 
const PEV_SPEC_TARGET = pev_iuser2
 
new g_MsgSync
 
// Variables
new g_Mode
 
// Cvar pointers
new cvar_enable, cvar_central
 
public plugin_init()
{
    register_plugin("[ZP] HUD Information", ZP_VERSION_STRING, "ZP Dev Team")
   
    g_MsgSync = CreateHudSyncObj()
    register_event("HLTV", "event_RoundStart", "a", "1=0", "2=0")
    cvar_enable = register_cvar("zp_display_mode", "1")
    register_cvar("zp_addon_dtcm", "v0.1.6 by meTaLiCroSS", FCVAR_SERVER|FCVAR_SPONLY)
    if(cvar_exists("zp_on"))
    cvar_central = get_cvar_pointer("zp_on")
 
    // If Zombie Plague is not running (bugfix)
    if(!get_pcvar_num(cvar_central))
    pause("a")
}
 
public plugin_natives()
{
    set_module_filter("module_filter")
    set_native_filter("native_filter")
}
public module_filter(const module[])
{
    if (equal(module, LIBRARY_NEMESIS) || equal(module, LIBRARY_SURVIVOR) || equal(module, LIBRARY_AMMOPACKS))
        return PLUGIN_HANDLED;
   
    return PLUGIN_CONTINUE;
}
public native_filter(const name[], index, trap)
{
    if (!trap)
        return PLUGIN_HANDLED;
   
    return PLUGIN_CONTINUE;
}
 
public client_putinserver(id)
{
    if (!is_user_bot(id))
    {
        // Set the custom HUD display task
        set_task(1.0, "ShowHUD", id+TASK_SHOWHUD, _, _, "b")
    }
    set_task(START_TIME, "mode_hud", id, _, _, "b")
}
public event_RoundStart()
{
    // Update var (no mode started / in delay)
    g_Mode = 0
}
 
public client_disconnect(id)
{
    remove_task(id+TASK_SHOWHUD)
}
 
// Show HUD Task
public ShowHUD(taskid)
{
    new id = ID_SHOWHUD
   
    // Player dead?
    if (!is_user_alive(id))
    {
        // Get spectating target
        id = pev(id, PEV_SPEC_TARGET)
       
        // Target not alive
        if (!is_user_alive(id))
            return;
    }
   
    // Format classname
    static class_name[32], transkey[64], healthstring[ 16 ];
    new red, green, blue
   
    if (zp_core_is_zombie(id)) // zombies
    {
        red = HUD_STATS_ZOMBIE_R
        green = HUD_STATS_ZOMBIE_G
        blue = HUD_STATS_ZOMBIE_B
       
        // Nemesis Class loaded?
        if (LibraryExists(LIBRARY_NEMESIS, LibType_Library) && zp_class_nemesis_get(id))
            formatex(class_name, charsmax(class_name), "%L", ID_SHOWHUD, "CLASS_NEMESIS")
        else
        {
            zp_class_zombie_get_name(zp_class_zombie_get_current(id), class_name, charsmax(class_name))
           
            // ML support for class name
            formatex(transkey, charsmax(transkey), "ZOMBIENAME %s", class_name)
            if (GetLangTransKey(transkey) != TransKey_Bad) formatex(class_name, charsmax(class_name), "%L", ID_SHOWHUD, transkey)
        }
    }
    else // humans
    {
        red = HUD_STATS_HUMAN_R
        green = HUD_STATS_HUMAN_G
        blue = HUD_STATS_HUMAN_B
       
        // Survivor Class loaded?
        if (LibraryExists(LIBRARY_NEMESIS, LibType_Library) && zp_class_survivor_get(id))
            formatex(class_name, charsmax(class_name), "%L", ID_SHOWHUD, "CLASS_SURVIVOR")
        else
        {
            zp_class_human_get_name(zp_class_human_get_current(id), class_name, charsmax(class_name))
           
            // ML support for class name
            formatex(transkey, charsmax(transkey), "HUMANNAME %s", class_name)
            if (GetLangTransKey(transkey) != TransKey_Bad) formatex(class_name, charsmax(class_name), "%L", ID_SHOWHUD, transkey)
        }
    }
   
    // Spectating someone else?
    if (id != ID_SHOWHUD)
    {
        new player_name[32]
        get_user_name(id, player_name, charsmax(player_name))
       
        // Show name, health, class, and money
        AddCommas( get_user_health( id ), healthstring, 15 );
        set_hudmessage(HUD_STATS_SPEC_R, HUD_STATS_SPEC_G, HUD_STATS_SPEC_B, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
       
        if (LibraryExists(LIBRARY_AMMOPACKS, LibType_Library))
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "NĂ©zve: %s^nÉlet: %s - TĂpus: %s - LĹ‘szer Csomag: %d", player_name, healthstring, class_name, zp_ammopacks_get(id))
        else
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "NĂ©zve: %s^nÉlet: %s - TĂpus: %s - PĂ©nz: $ %d", player_name, healthstring, class_name, cs_get_user_money(id))
    }
    else
    {
        // Show health, class
        AddCommas( get_user_health( id ), healthstring, 15 );
        set_hudmessage(red, green, blue, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1)
       
        if (LibraryExists(LIBRARY_AMMOPACKS, LibType_Library))
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Élet: %s - TĂpus: %s - LĹ‘szer Csomag: %d", healthstring, class_name, zp_ammopacks_get(ID_SHOWHUD))
        else
            ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync, "Élet: %s - TĂpus: %s", healthstring, class_name)
    }
}
AddCommas( iNum , szOutput[] , iLen )
{
static szTmp[ 15 ] , iOutputPos , iNumPos , iNumLen;
szTmp[0]='^0',iOutputPos=iNumPos=iNumLen=0;
if ( iNum < 0 )
{
szOutput[ iOutputPos++ ] = '-';
iNum = abs( iNum );
}
iNumLen = num_to_str( iNum , szTmp , charsmax( szTmp ) );
if ( iNumLen <= 3 )
iOutputPos += copy( szOutput[ iOutputPos ] , iLen , szTmp );
else
{
while ( ( iNumPos < iNumLen ) && ( iOutputPos < iLen ) )
{
szOutput[ iOutputPos++ ] = szTmp[ iNumPos++ ];
if( ( iNumLen - iNumPos ) && !( ( iNumLen - iNumPos ) % 3 ) )
szOutput[ iOutputPos++ ] = ',';
}
szOutput[ iOutputPos ] = EOS;
}
return iOutputPos;
}
public mode_hud(id)
{
new ido[9]
new timeleft = get_timeleft();
new perc = 0;
while(timeleft >= 60)
{
perc++;
timeleft=timeleft-60;
}
get_time("%H:%M:%S",ido,8)
new nmap[32]
get_cvar_string("amx_nextmap", nmap, sizeof(nmap) -1)
// If the Cvar isn't enabled
if(!get_pcvar_num(cvar_enable))
return;
 
// Hud Options
set_hudmessage(rgb_hud_colors[g_Mode][0], rgb_hud_colors[g_Mode][1], rgb_hud_colors[g_Mode][2], HUD_MODE_X, HUD_MODE_Y, 0, 6.0, 12.0)
 
// Now the hud appears
show_hudmessage(id, "%s%s^n^nKövetkező Pálya: %s^nHátralévő idő: %d:%d^nJelenlegi Idő: %s", (g_Mode == 0 ? "" : hud_tag), mode_names[g_Mode], nmap,perc,timeleft,ido)
}
public zp_round_started(mode, id)
{
    // Update var with Mode num
    g_Mode = mode
 
    // An unofficial mode
    if(!(1 <= mode < (sizeof(mode_names) - 1)))
        g_Mode = sizeof(mode_names) - 1
}