View Single Post
tiltedShrimp
Member
Join Date: Feb 2024
Old 03-05-2024 , 16:23   Re: [REQUEST][HL] timeleft, system clock HUD
Reply With Quote #3

Quote:
Originally Posted by bigdaddy424 View Post
timeleft code by xpaw
timezones from ai
PHP Code:
#include <amxmodx>
#include <engine>
#include <nvault>

#define UPDATE_TIME    1.0
#define ENTITY_CLASS    "env_host_timeleft"

new g_szHostname64 ];
new 
g_pointerTimelimit;

const 
SERVER_TIMEZONE //GMT+1

enum TIMETABLE HOUR_DIFFTIMEZONE[38] }
new 
UTC_TimeDifferences[][TIMETABLE] =
{
    { -
12"Baker Island, Howland Island" },
    { -
11"Niue, American Samoa" },
    { -
10"Hawaii, French Polynesia" },
    { -
9"Alaska" },
    { -
8"Pacific Time Zone" },
    { -
7"Mountain Time Zone" },
    { -
6"Central Time Zone" },
    { -
5"Eastern Time Zone" },
    { -
4"Atlantic Time Zone" },
    { -
3"Argentina, Brazil" },
    { -
2"Fernando de Noronha, South Georgia" },
    { -
1"Cape Verde, Azores" },
    { 
0"Greenwich Mean Time" },
    { 
1"Central European Time" },
    { 
2"Eastern European Time" },
    { 
3"Moscow Time" },
    { 
4"Armenia, Azerbaijan" },
    { 
5"Pakistan, Maldives" },
    { 
6"Bangladesh, Bhutan" },
    { 
7"Indochina Time" },
    { 
8"China, Philippines" },
    { 
9"Japan, South Korea" },
    { 
10"Australia Eastern Time" },
    { 
11"Vanuatu, New Caledonia" },
    { 
12"New Zealand, Fiji" }
}


new 
vaultplayer_local_time[MAX_PLAYERS 1], bool:show_clock[MAX_PLAYERS 1]

public 
plugin_init()
{
    
register_plugin"Hostname Timeleft""1.0""xPaw" );

    
g_pointerTimelimit    get_cvar_pointer"mp_timelimit" );

    
// Give delay to load configs...
    
set_task2.5"checkTimeleft" );

    
register_clcmd("say timezone""clcmd_timezone")
    
register_clcmd("say clock""clcmd_clock")

    
vault nvault_open("timezone")
}

public 
plugin_end()
    
nvault_close(vault)

public 
checkTimeleft( ) {
    
register_thinkENTITY_CLASS"fwdThink_Updater" );
    
    
// initialize thinking entity...
    
new iEntityTimer create_entity"info_target" );
    
entity_set_stringiEntityTimerEV_SZ_classnameENTITY_CLASS );
    
entity_set_floatiEntityTimerEV_FL_nextthinkget_gametime() + UPDATE_TIME );
}

public 
fwdThink_UpdateriEntity ) {
    if( 
get_pcvar_floatg_pointerTimelimit ) ) {
        static 
iHoursiMinutesiSeconds;
        
        
iSeconds    get_timeleft( );
        
iMinutes    iSeconds 60;
        
iHours        iMinutes 60;
        
iSeconds    iSeconds iMinutes 60;
        
iMinutes    iMinutes iHours 60;
        
        
        if( 
iHours )
            
formatexg_szHostname63"^n(Timeleft %d:%02d:%02d)"iHoursiMinutesiSeconds );
        else 
formatexg_szHostname63"^n(Timeleft %d:%02d)"iMinutesiSeconds )
    } 
    else 
formatexg_szHostname63"^n(No time limit)");
    
entity_set_floatiEntityEV_FL_nextthinkget_gametime() + UPDATE_TIME );
}

public 
client_authorized(id, const authid[])
{
    
player_local_time[id] = nvault_get(vaultauthid)
    
set_task(1.0"update_time"id, .flags="b")
}

public 
client_putinserver(id)
    
show_clock[id] = true

public client_disconnected(id)
{
    new 
authid[32]
    
get_user_authid(idauthidcharsmax(authid))
    
nvault_set(vaultauthidfmt("%d"player_local_time[id]))
    
show_clock[id] = false
    remove_task
(id)
}

public 
clcmd_timezone(id)
{
    new 
menu menu_create("Select Timezone""menu_handler")
    for (new 
0sizeof(UTC_TimeDifferences); i++)
        
menu_additem(menufmt("%s%s \d%d"player_local_time[id] == UTC_TimeDifferences[i][HOUR_DIFF] ? "\y" "\w"UTC_TimeDifferences[i][TIMEZONE], UTC_TimeDifferences[i][HOUR_DIFF]))
    
menu_display(idmenu)
}

public 
menu_handler(idmenuitem)
{
    
menu_destroy(menu)
    
player_local_time[id] = UTC_TimeDifferences[item][HOUR_DIFF]
}

public 
clcmd_clock(id)
    
show_clock[id] = !show_clock[id]

public 
update_time(id)
{
    if (
show_clock[id])
    {
        static 
time_text[16], systime
        systime 
get_systime(id) + floatround((player_local_time[id] - SERVER_TIMEZONE) * 3600.0)
        
format_time(time_textcharsmax(time_text), "%I:%M:%S %p"systime)
        
set_hudmessage(.red=251, .green=126, .blue=20, .x=0.015, .y=0.175, .holdtime=1.0, .channel=2)
        
show_hudmessage(id"%s%s"time_textg_szHostname)
    }

Hey !
I appreciate your help bigdaddy424, then I try to compile the code, I get multiple errors, I'll attach a photo:
Attached Thumbnails
Click image for larger version

Name:	compiling error.jpg
Views:	39
Size:	89.2 KB
ID:	203600  
tiltedShrimp is offline