AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   [REQUEST][Half-Life] HUD for timeleft, system clock w/ auto timezone (https://forums.alliedmods.net/showthread.php?t=346588)

tiltedShrimp 03-05-2024 14:08

[REQUEST][Half-Life] HUD for timeleft, system clock w/ auto timezone
 
1 Attachment(s)
Hey !
Im interested in a HUD which would display the time that's left until map change and system clock. After a bit of research on the forums I've managed to find a plugin which displays system time only, maybe it would be possible to edit it? I'll attach the said plugin.

Would it be possible to edit the following:
#1 add timeleft until map change just below the system clock
#2 make the HUD enabled by default upon entering the server
#3 if its a possibility, make the whole HUD/font a bit smaller so that its less intrusive

Thank you !

bigdaddy424 03-05-2024 16:15

Re: [REQUEST][HL] timeleft, system clock HUD
 
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)
    }



tiltedShrimp 03-05-2024 16:23

Re: [REQUEST][HL] timeleft, system clock HUD
 
1 Attachment(s)
Quote:

Originally Posted by bigdaddy424 (Post 2819029)
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:

tiltedShrimp 03-05-2024 17:17

Re: [REQUEST][HL] timeleft, system clock HUD
 
Quote:

Originally Posted by tiltedShrimp (Post 2819030)
Hey !
I appreciate your help bigdaddy424, then I try to compile the code, I get multiple errors, I'll attach a photo:

EDIT: the mistake was on my end for compiling errors, the plugin is EXACTLY what I was searching for and works like a charm, thank you so much bigdaddy424, you're a Legend !

bigdaddy424 03-05-2024 18:47

Re: [REQUEST][HL] timeleft, system clock HUD
 
to be honest all of my work i do does involve functions that are part of unofficial releases because i find it much simpler and sometimes people end up ignoring just because im not referencing 1.8.2

tiltedShrimp 03-05-2024 19:05

Re: [REQUEST][HL] timeleft, system clock HUD
 
Quote:

Originally Posted by bigdaddy424 (Post 2819038)
to be honest all of my work i do does involve functions that are part of unofficial releases because i find it much simpler and sometimes people end up ignoring just because im not referencing 1.8.2

Makes sense buddy 👍

tiltedShrimp 03-06-2024 11:52

Re: [REQUEST][HL] timeleft, system clock HUD
 
Update:
Reopening the thread. I discovered an issue with the plugin, the one provided by bigdaddy424. I've set the "const SERVER_TIMEZONE = " to "0" to correspond my local time since it says "server timezone", so I figured it would be correct to adjust it to my local time, but other, foreign players seem to get the same timezone, the plugin doesn't adjust for them automatically. Would it be possible to make it so the plugin automatically selects the appropriate timezone for everyone? Or maybe scan player's pc system time and display that for him?

tedaimlocks 03-06-2024 13:09

Re: [REQUEST][HL] timeleft, system clock HUD
 
the default timezone would be where the server location is hosted, and you could try to use geoip to get the players country and display their timezone

https://forums.alliedmods.net/showthread.php?t=257898

tiltedShrimp 03-06-2024 13:39

Re: [REQUEST][HL] timeleft, system clock HUD
 
Quote:

Originally Posted by tedaimlocks (Post 2819082)
the default timezone would be where the server location is hosted, and you could try to use geoip to get the players country and display their timezone

https://forums.alliedmods.net/showthread.php?t=257898

Hey tedaimlocks !
Thank you for your insight and suggestion, it really makes sense to utilize GeoIP in someway for the timezones to be set automatically, I already use a few plugins which utilizes GeoIP, for example, GHW Connect Messages, which pushes a message when someone connect to a server with they country that they are located at.

Sadly when it comes to coding or creating a plugin, my knowledge is seriously limited, Im only really capable of editing the simplest parameters within an already working plugin ... If you know a way to make it work, I'd really appreciate you landing me hand !

georgik57 03-07-2024 11:05

Re: [REQUEST][HL] timeleft, system clock HUD
 
something like this?
https://i.imgur.com/FF1MOoZ.png


All times are GMT -4. The time now is 08:25.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.