Raised This Month: $ Target: $400
 0% 

Festival Countdown


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sb123
Senior Member
Join Date: Jan 2007
Old 11-07-2023 , 08:36   Festival Countdown
Reply With Quote #1

How to display what holiday is today on festivals day,And add various holiday blessings in ini
At present, this plugin can only count down the next festivals and will not display what festivals it is today on the day of the festivals
Also, this plugin cannot count down to January 1st of the new year. Can someone fix this issue
Attached Files
File Type: ini count_vault.ini (35 Bytes, 43 views)
File Type: sma Get Plugin or Get Source (DaysEvent.sma - 94 views - 5.5 KB)
__________________
sb123 is offline
Send a message via ICQ to sb123 Send a message via MSN to sb123 Send a message via Yahoo to sb123
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 11-25-2023 , 21:12   Re: Festival Countdown
Reply With Quote #2

If you know how to work with json you can do something like this
loop until you skip all previous months and see if theres and holidays this month we're in. if not loop again and find the closes holiday
Code:
{
  "1": {
    "1": "New Year's Day"
  },

  "7": {
    "4": "Independence Day"
  },

  "12": {
    "24": "Christmas Eve",
    "25": "Christmas Day",
    "31": "New Year's Eve"
  }
}
__________________
bigdaddy424 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-26-2023 , 00:23   Re: Festival Countdown
Reply With Quote #3

Can you be specific in what exactly you want?

"Christmas is 3 days away"

and then on Christmas

"Today is Christmas"

?
__________________
Bugsy is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 11-26-2023 , 00:30   Re: Festival Countdown
Reply With Quote #4


PHP Code:
#include <amxmodx>
#include <json>

new next_holiday[32]

new 
JSON:object
new JSON:month

new this_year[6], this_month[4], this_day[4]

public 
plugin_cfg()
{
    
object json_parse("holidays.json", .is_file=true)

    if (!
json_is_object(object))
        
set_fail_state("Invalid JSON Object")

    
get_time("%Y"this_yearcharsmax(this_year))
    
get_time("%m"this_monthcharsmax(this_month))
    
get_time("%d"this_daycharsmax(this_day))

    new 
int_this_month str_to_num(this_month)
    for (new 
int_this_month<= 12i++)
    {
        
month json_object_get_value(objectfmt("%d"i))
        if (
json_is_object(month))
        {
            for (new 
1<= 31j++)
            {
                if (
int_this_month || str_to_num(this_day))
                {
                    
json_object_get_string(monthfmt("%d"j), next_holidaycharsmax(next_holiday))
                    if (
next_holiday[0])
                    {
                        
server_print("%d days until %s"makejd(str_to_num(this_year), ij) - makejd(str_to_num(this_year), int_this_monthstr_to_num(this_day)), next_holiday)
                        break
                    }
                }
            }

            
json_object_clear(month)
        }
    }

    if (
next_holiday[0] == EOS)
        
server_print("No holiday found")
}

// https://stackoverflow.com/a/73846054

#define BASEYEAR 1601      /* *not* arbitrary; see explanation in text */

public makejd(yearmonthday)
{
    new 
jdnum 0;
    
jdnum += (year BASEYEAR) * 365;
    
jdnum += (year BASEYEAR) / 4;
    
jdnum -= (year BASEYEAR) / 100;
    
jdnum += (year BASEYEAR) / 400;
    
jdnum += monthcount(month 1year);
    
jdnum += day;
    return 
jdnum;
}

                     
/* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */
new monthlengths[] = {0312831303130313130313031};

/* return total days from January up to the end of the given month */
public monthcount(monthyear)
{
    new 
0;
    for(new 
1<= monthi++)
    
+= monthlengths[i];
    if(
isleap(year) && month >= 2)
        
r++;
    return 
r;
}

public 
isleap(year)
{
    return 
year == && (year 100 != || year 400 == 0);

__________________
bigdaddy424 is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 11-26-2023 , 01:06   Re: Festival Countdown
Reply With Quote #5

heres a shorter way using dot_not
PHP Code:
new int_this_month str_to_num(this_month)
for (new 
int_this_month<= 12i++)
{
    for (new 
1<= 31j++)
    {
        if (
int_this_month || str_to_num(this_day))
        {
            
json_object_get_string(objectfmt("%d.%d"ij), next_holidaycharsmax(next_holiday), .dot_not=true)
            if (
next_holiday[0])
            {
                
server_print("%d days until %s"makejd(str_to_num(this_year), ij) - makejd(str_to_num(this_year), int_this_monthstr_to_num(this_day)), next_holiday)
                break
            }
        }
    }

__________________
bigdaddy424 is offline
sb123
Senior Member
Join Date: Jan 2007
Old 11-26-2023 , 10:24   Re: Festival Countdown
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
Can you be specific in what exactly you want?

"Christmas is 3 days away"

and then on Christmas

"Today is Christmas"

?
Yes, that's it.Can you fix it in the code I uploaded
Also, this plugin cannot count down to January 1st of the new year
__________________
sb123 is offline
Send a message via ICQ to sb123 Send a message via MSN to sb123 Send a message via Yahoo to sb123
sb123
Senior Member
Join Date: Jan 2007
Old 11-26-2023 , 10:30   Re: Festival Countdown
Reply With Quote #7

Quote:
Originally Posted by bigdaddy424 View Post

PHP Code:
#include <amxmodx>
#include <json>

new next_holiday[32]

new 
JSON:object
new JSON:month

new this_year[6], this_month[4], this_day[4]

public 
plugin_cfg()
{
    
object json_parse("holidays.json", .is_file=true)

    if (!
json_is_object(object))
        
set_fail_state("Invalid JSON Object")

    
get_time("%Y"this_yearcharsmax(this_year))
    
get_time("%m"this_monthcharsmax(this_month))
    
get_time("%d"this_daycharsmax(this_day))

    new 
int_this_month str_to_num(this_month)
    for (new 
int_this_month<= 12i++)
    {
        
month json_object_get_value(objectfmt("%d"i))
        if (
json_is_object(month))
        {
            for (new 
1<= 31j++)
            {
                if (
int_this_month || str_to_num(this_day))
                {
                    
json_object_get_string(monthfmt("%d"j), next_holidaycharsmax(next_holiday))
                    if (
next_holiday[0])
                    {
                        
server_print("%d days until %s"makejd(str_to_num(this_year), ij) - makejd(str_to_num(this_year), int_this_monthstr_to_num(this_day)), next_holiday)
                        break
                    }
                }
            }

            
json_object_clear(month)
        }
    }

    if (
next_holiday[0] == EOS)
        
server_print("No holiday found")
}

// https://stackoverflow.com/a/73846054

#define BASEYEAR 1601      /* *not* arbitrary; see explanation in text */

public makejd(yearmonthday)
{
    new 
jdnum 0;
    
jdnum += (year BASEYEAR) * 365;
    
jdnum += (year BASEYEAR) / 4;
    
jdnum -= (year BASEYEAR) / 100;
    
jdnum += (year BASEYEAR) / 400;
    
jdnum += monthcount(month 1year);
    
jdnum += day;
    return 
jdnum;
}

                     
/* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */
new monthlengths[] = {0312831303130313130313031};

/* return total days from January up to the end of the given month */
public monthcount(monthyear)
{
    new 
0;
    for(new 
1<= monthi++)
    
+= monthlengths[i];
    if(
isleap(year) && month >= 2)
        
r++;
    return 
r;
}

public 
isleap(year)
{
    return 
year == && (year 100 != || year 400 == 0);

Thank you very much for your help. I am using version 1.8.2 without using JSON. I still hope to add some judgment in the original code
__________________
sb123 is offline
Send a message via ICQ to sb123 Send a message via MSN to sb123 Send a message via Yahoo to sb123
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 11-26-2023 , 15:22   Re: Festival Countdown
Reply With Quote #8

I guess this will work on 1.8.2
Only thing holding it back was fmt() which only works on the newer version but quickly replaced it with formatex()

PHP Code:
#include <amxmodx>
#include <json>

new next_holiday[32]

new 
JSON:object

new this_year[6], this_month[4], this_day[4], days_until[64]
new 
hud_day[64], hud_hour[64]

public 
plugin_cfg()
{
    
refreshHolidays()

    
set_task(60.0"refreshHolidays", .flags="b")
    
set_task(1.0"refreshHud", .flags="b")
}

public 
refreshHolidays()
{
    
object json_parse("holidays.json", .is_file=true// cstrike/holidays.json

    
if (!json_is_object(object))
        
server_print("Invalid JSON Object")

    
get_time("%Y"this_yearcharsmax(this_year))
    
get_time("%m"this_monthcharsmax(this_month))
    
get_time("%d"this_daycharsmax(this_day))

    new 
temp[8], int_this_month str_to_num(this_month)
    for (new 
int_this_month<= 12i++)
    {
        for (new 
1<= 31j++)
        {
            if (
int_this_month || str_to_num(this_day))
            {
                
formatex(tempcharsmax(temp), "%d.%d"ij)
                
json_object_get_string(objecttempnext_holidaycharsmax(next_holiday), .dot_not=true)
                if (
next_holiday[0])
                {
                    
formatex(days_untilcharsmax(days_until), "^n%d days until %s"makejd(str_to_num(this_year), ij) - makejd(str_to_num(this_year), int_this_monthstr_to_num(this_day)), next_holiday)
                    break
                }
            }
        }
    }
    
json_free(object)

    if (
next_holiday[0] == EOS)
        
days_until[0] = EOS
}

public 
refreshHud()
{
    
// https://www.tutorialspoint.com/c_standard_library/c_function_strftime.htm
    
get_time("%A of %B %m"hud_daycharsmax(hud_day))
    
get_time("%I:%M %p"hud_hourcharsmax(hud_hour))

    new 
hourtime_of_day[16]
    
time(hour)

    switch (
hour)
    {
        case 
.. 11copy(time_of_daycharsmax(time_of_day), "Morning")
        case 
12 .. 17copy(time_of_daycharsmax(time_of_day), "Afternoon")
        case 
18 .. 23copy(time_of_daycharsmax(time_of_day), "Evening")
    }

    switch (
hour)
    {
        case 
0copy(time_of_daycharsmax(time_of_day), "Midnight")
        case 
6copy(time_of_daycharsmax(time_of_day), "Dawn")
        case 
12copy(time_of_daycharsmax(time_of_day), "Noon")
        case 
17copy(time_of_daycharsmax(time_of_day), "Dusk")
    }

    
set_hudmessage(2552552550.10.1, .holdtime=1.0)
    
show_hudmessage(0"%s^n%s of %s%s"hud_daytime_of_dayhud_hourdays_until)
}

// https://stackoverflow.com/a/73846054

#define BASEYEAR 1601      /* *not* arbitrary; see explanation in text */

public makejd(yearmonthday)
{
    new 
jdnum 0;
    
jdnum += (year BASEYEAR) * 365;
    
jdnum += (year BASEYEAR) / 4;
    
jdnum -= (year BASEYEAR) / 100;
    
jdnum += (year BASEYEAR) / 400;
    
jdnum += monthcount(month 1year);
    
jdnum += day;
    return 
jdnum;
}

                     
/* Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec */
new monthlengths[] = {0312831303130313130313031};

/* return total days from January up to the end of the given month */
public monthcount(monthyear)
{
    new 
0;
    for(new 
1<= monthi++)
    
+= monthlengths[i];
    if(
isleap(year) && month >= 2)
        
r++;
    return 
r;
}

public 
isleap(year)
{
    return 
year == && (year 100 != || year 400 == 0);

__________________
bigdaddy424 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-26-2023 , 15:23   Re: Festival Countdown
Reply With Quote #9

Hardly tested. Just keep the holiday array in date order.
PHP Code:

#include <amxmodx>

new const Version[] = "0.1";

enum _:HolidayParts
{
    
hpMonth,
    
hpDay,
    
hpHoliday32 ]
}
new const 
Holidays[][ HolidayParts ] = 
{
    { 
"New Years Day" },
    { 
"Cinco de mayo" },
    { 
"Independance Day" },
    { 
12 24 "Christmas Eve" },
    { 
12 25 "Christmas Day" },
    { 
12 31"New Years Eve" }
};
    
const 
DaySeconds 86400;

public 
plugin_init() 
{
    
register_plugin"Next Holiday" Version "bugsy" );

    
set_task1.0 "GetNextHoliday" , .flags="b" );
}

public 
GetNextHoliday()
{
    new 
szMonth] , iMonth szDay] , iDay szYear] , iHolidayIndex = -1;
        
    
format_timeszMonth charsmaxszMonth ) , "%m" );
    
format_timeszDay charsmaxszDay ) , "%d" );
    
format_timeszYear charsmaxszYear ) , "%Y" );
    
    
iMonth str_to_numszMonth );
    
iDay str_to_numszDay );
    
    if ( ( 
iMonth >= HolidayssizeofHolidays ) - ][ hpMonth ] ) && ( iDay HolidayssizeofHolidays ) - ][ hpDay ] ) )
    {
        
iHolidayIndex 0;
    }
    else
    {
        for ( new 
sizeofHolidays ) ; i++ )
        {
            if ( 
iMonth <= Holidays][ hpMonth ] )
            {
                if ( 
iMonth == Holidays][ hpMonth ] )
                {
                    while ( ( 
sizeofHolidays ) ) && ( iDay Holidays][ hpDay ] ) )
                        
i++;
                }
                
                if ( ( 
iMonth == Holidays][ hpMonth ] ) && ( iDay == Holidays][ hpDay ] ) )
                {
                    
set_hudmessage255 255 255 0.25 0.25 0.0 1.0 );
                    
show_hudmessage,  "* Today is  %s/%s/%s - Happy %s!" szMonth szDay szYear ,  Holidays][ hpHoliday ] );
                    
iHolidayIndex 9999;
                }
                else
                {
                    
iHolidayIndex i;
                }
                
                break;
            }
        }
    }
    
    if ( 
iHolidayIndex != 9999 )
    {
        
GetDaysAwayiHolidayIndex );
    }
}

GetDaysAwayiHolidayIndex )
{
    new 
szMonth]  , szDay]  , szYear] , iYear;
    new 
szTodayDate11 ] , szHolidayDate11 ];
    new 
iTodayTS iHolidayTS;
    
    
format_timeszMonth charsmaxszMonth ) , "%m" );
    
format_timeszDay charsmaxszDay ) , "%d" );
    
format_timeszYear charsmaxszYear ) , "%Y" );
    
iYear str_to_numszYear );
    
    if ( 
str_to_numszMonth ) >  HolidaysiHolidayIndex ][ hpMonth ] )
        
iYear++;
        
    
formatexszTodayDate charsmaxszTodayDate ) , "%s/%s/%s" szMonth szDay szYear );
    
formatexszHolidayDate charsmaxszHolidayDate ) , "%d/%d/%d" HolidaysiHolidayIndex ][ hpMonth ] , HolidaysiHolidayIndex ][ hpDay ] , iYear );
    
    
iTodayTS parse_timeszTodayDate "%m/%d/%Y" );
    
iHolidayTS parse_timeszHolidayDate "%m/%d/%Y" );
    
    
set_hudmessage255 ,255 255 0.25 0.25 0.0 1.0 );
    
show_hudmessage,  "* Today is  %s/%s/%s - %s is %d days away" szMonth szDay szYear ,  HolidaysiHolidayIndex ][ hpHoliday ] , ((iHolidayTS-iTodayTS) / DaySeconds) , ((iHolidayTS-iTodayTS) / DaySeconds) > "s" ""  );

__________________

Last edited by Bugsy; 11-26-2023 at 15:28.
Bugsy is offline
sb123
Senior Member
Join Date: Jan 2007
Old 11-27-2023 , 03:06   Re: Festival Countdown
Reply With Quote #10

Quote:
Originally Posted by Bugsy View Post
Hardly tested. Just keep the holiday array in date order.
PHP Code:

#include <amxmodx>

new const Version[] = "0.1";

enum _:HolidayParts
{
    
hpMonth,
    
hpDay,
    
hpHoliday32 ]
}
new const 
Holidays[][ HolidayParts ] = 
{
    { 
"New Years Day" },
    { 
"Cinco de mayo" },
    { 
"Independance Day" },
    { 
12 24 "Christmas Eve" },
    { 
12 25 "Christmas Day" },
    { 
12 31"New Years Eve" }
};
    
const 
DaySeconds 86400;

public 
plugin_init() 
{
    
register_plugin"Next Holiday" Version "bugsy" );

    
set_task1.0 "GetNextHoliday" , .flags="b" );
}

public 
GetNextHoliday()
{
    new 
szMonth] , iMonth szDay] , iDay szYear] , iHolidayIndex = -1;
        
    
format_timeszMonth charsmaxszMonth ) , "%m" );
    
format_timeszDay charsmaxszDay ) , "%d" );
    
format_timeszYear charsmaxszYear ) , "%Y" );
    
    
iMonth str_to_numszMonth );
    
iDay str_to_numszDay );
    
    if ( ( 
iMonth >= HolidayssizeofHolidays ) - ][ hpMonth ] ) && ( iDay HolidayssizeofHolidays ) - ][ hpDay ] ) )
    {
        
iHolidayIndex 0;
    }
    else
    {
        for ( new 
sizeofHolidays ) ; i++ )
        {
            if ( 
iMonth <= Holidays][ hpMonth ] )
            {
                if ( 
iMonth == Holidays][ hpMonth ] )
                {
                    while ( ( 
sizeofHolidays ) ) && ( iDay Holidays][ hpDay ] ) )
                        
i++;
                }
                
                if ( ( 
iMonth == Holidays][ hpMonth ] ) && ( iDay == Holidays][ hpDay ] ) )
                {
                    
set_hudmessage255 255 255 0.25 0.25 0.0 1.0 );
                    
show_hudmessage,  "* Today is  %s/%s/%s - Happy %s!" szMonth szDay szYear ,  Holidays][ hpHoliday ] );
                    
iHolidayIndex 9999;
                }
                else
                {
                    
iHolidayIndex i;
                }
                
                break;
            }
        }
    }
    
    if ( 
iHolidayIndex != 9999 )
    {
        
GetDaysAwayiHolidayIndex );
    }
}

GetDaysAwayiHolidayIndex )
{
    new 
szMonth]  , szDay]  , szYear] , iYear;
    new 
szTodayDate11 ] , szHolidayDate11 ];
    new 
iTodayTS iHolidayTS;
    
    
format_timeszMonth charsmaxszMonth ) , "%m" );
    
format_timeszDay charsmaxszDay ) , "%d" );
    
format_timeszYear charsmaxszYear ) , "%Y" );
    
iYear str_to_numszYear );
    
    if ( 
str_to_numszMonth ) >  HolidaysiHolidayIndex ][ hpMonth ] )
        
iYear++;
        
    
formatexszTodayDate charsmaxszTodayDate ) , "%s/%s/%s" szMonth szDay szYear );
    
formatexszHolidayDate charsmaxszHolidayDate ) , "%d/%d/%d" HolidaysiHolidayIndex ][ hpMonth ] , HolidaysiHolidayIndex ][ hpDay ] , iYear );
    
    
iTodayTS parse_timeszTodayDate "%m/%d/%Y" );
    
iHolidayTS parse_timeszHolidayDate "%m/%d/%Y" );
    
    
set_hudmessage255 ,255 255 0.25 0.25 0.0 1.0 );
    
show_hudmessage,  "* Today is  %s/%s/%s - %s is %d days away" szMonth szDay szYear ,  HolidaysiHolidayIndex ][ hpHoliday ] , ((iHolidayTS-iTodayTS) / DaySeconds) , ((iHolidayTS-iTodayTS) / DaySeconds) > "s" ""  );

I tested the code and everything is normal. Can you read the holiday time and name from the ini configuration
Can you add today's day of the week and what time and minutes it is and time period

Time period
24-5 Dawn
6-7 Morning
8-11 Ante meridiem
12 Noon
13-17 Afternoon
18 Dusk
19-22 Evening
23 Midnight

Countdown to festivals
Today is 2023 Year 11 Month 26 Day Sunday^nAfternoon 140^nDistance Christmas days away

On the day of the festival
Today is 2023 Year 12 Month 25 Day Monday^nMorning 7:00^nToday is Happy Christmas
__________________
sb123 is offline
Send a message via ICQ to sb123 Send a message via MSN to sb123 Send a message via Yahoo to sb123
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:58.


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