AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
|
11-29-2023
, 20:35
Re: Festival Countdown
|
#13
|
Quote:
Originally Posted by sb123
Bugsy Hello! Sorry to bother you again
This plugin has a bug
The problem with the plugin now is that if all the November holidays have already been displayed, if I don't delete the November holidays from the ini, it will result in the inability to display the December holidays. Only empty holidays and 0 days will be displayed
Today is %s Year %s Month %s Day %s^n%s %s:%s^n is 0 day away
How to keep all the festivals that have been counted down before without deleting them. Because if there are previous festivals in ini now, the next festival will not be displayed
Please fix this issue. Thank you
|
The issue is fixed and I validated many scenarios, this version should be good
PHP Code:
#include <amxmodx> #include <amxmisc>
new const Version[] = "0.3";
const MaxFestivals = 10; const MaxFestivalNameLength = 32; const DaySeconds = 86400;
enum _:TimePeriodParts { tpStart, tpEnd, tpDescription[ 16 ] } new const TimePeriods[][ TimePeriodParts ] = { { 0 , 5 , "Dawn" }, { 6 , 7 , "Morning" }, { 8 , 11 , "Ante meridiem" }, { 12 , 12 , "Noon" }, {13 , 17 , "Afternoon" }, { 18 , 18 , "Dusk" }, { 19 , 22 , "Evening" }, { 23 , 23 , "Midnight" } }; enum _:FestivalParts { fpMonth, fpDay, fpFestival[ MaxFestivalNameLength + 1] } new Festivals[ MaxFestivals ][ FestivalParts ];
new g_LoadedFestivals;
public plugin_init() { register_plugin( "Next Festival" , Version , "bugsy" );
g_LoadedFestivals = LoadFestivals(); set_task( 1.0 , "GetNextFestival" , .flags="b" ); }
public GetNextFestival() { new szMonth[ 3 ] , iMonth , szDay[ 3 ] , iDay , szYear[ 5 ] , szHour[ 3 ] , iHour , szMinute[ 3 ] , szWeekDay[ 10 ] , iFestivalIndex = -1 , bool:bIsToday; format_time( szMonth , charsmax( szMonth ) , "%m" ); format_time( szDay , charsmax( szDay ) , "%d" ); format_time( szYear , charsmax( szYear ) , "%Y" ); format_time( szHour , charsmax( szHour ) , "%H" ); format_time( szMinute , charsmax( szMinute ) , "%M" ); format_time( szWeekDay , charsmax( szWeekDay ) , "%A" ); iMonth = str_to_num( szMonth ); iDay = str_to_num( szDay ); iHour = str_to_num( szHour ); //Check if current month/day are beyond the last festival month/day in the list, meaning the first in the list is considered next. if ( ( iMonth >= Festivals[ g_LoadedFestivals - 1 ][ fpMonth ] ) && ( iDay > Festivals[ g_LoadedFestivals - 1 ][ fpDay ] ) ) { iFestivalIndex = 0; } else { for ( new i = 0 ; i < g_LoadedFestivals ; i++ ) { if ( ( iMonth == Festivals[ i ][ fpMonth ] ) && ( iDay == Festivals[ i ][ fpDay ] ) ) { //Festival is today iFestivalIndex = i; bIsToday = true; break; } else if ( ( ( Festivals[ i ][ fpMonth ] == iMonth) && ( Festivals[ i ][ fpDay ] > iDay ) ) || ( Festivals[ i ][ fpMonth ] > iMonth ) ) { //Festival is in current month on future day OR in future month iFestivalIndex = i; break; } } }
if ( iFestivalIndex == -1 ) set_fail_state( "An unhandled exception has occurred" ); if ( bIsToday ) { set_hudmessage( 255 , 255 , 255 , 0.25 , 0.25 , 0 , 0.0 , 1.0 ); show_hudmessage( 0 , "Today is %s Year %s Month %s Day %s^n%s %s:%s^nToday is %s" , szYear , szMonth , szDay , szWeekDay , TimePeriods[ GetTimePeriod( iHour ) ] , szHour , szMinute , Festivals[ iFestivalIndex ][ fpFestival ] ); } else { PrintDaysAway( iFestivalIndex ); } }
PrintDaysAway( iFestivalIndex ) { new szMonth[ 3 ] , szDay[ 3 ] , szYear[ 5 ] , iYear , szHour[ 3 ] , iHour , szMinute[ 3 ] , szWeekDay[ 10 ]; new szTodayDate[ 11 ] , szFestivalDate[ 11 ]; new iTodayTS , iFestivalTS; format_time( szMonth , charsmax( szMonth ) , "%m" ); format_time( szDay , charsmax( szDay ) , "%d" ); format_time( szYear , charsmax( szYear ) , "%Y" ); format_time( szHour , charsmax( szHour ) , "%H" ); format_time( szMinute , charsmax( szMinute ) , "%M" ); format_time( szWeekDay , charsmax( szWeekDay ) , "%A" ); iYear = str_to_num( szYear ); iHour = str_to_num( szHour ); if ( str_to_num( szMonth ) > Festivals[ iFestivalIndex ][ fpMonth ] ) iYear++; formatex( szTodayDate , charsmax( szTodayDate ) , "%s/%s/%s" , szMonth , szDay , szYear ); formatex( szFestivalDate , charsmax( szFestivalDate ) , "%d/%d/%d" , Festivals[ iFestivalIndex ][ fpMonth ] , Festivals[ iFestivalIndex ][ fpDay ] , iYear ); iTodayTS = parse_time( szTodayDate , "%m/%d/%Y" ); iFestivalTS = parse_time( szFestivalDate , "%m/%d/%Y" ); set_hudmessage( 255 ,255 , 255 , 0.25 , 0.25 , 0 , 0.0 , 1.0 ); show_hudmessage( 0 , "Today is %s Year %s Month %s Day %s^n%s %s:%s^n%s is %d day%s away" , szYear , szMonth , szDay , szWeekDay , TimePeriods[ GetTimePeriod( iHour ) ] , szHour , szMinute , Festivals[ iFestivalIndex ][ fpFestival ] , ((iFestivalTS-iTodayTS) / DaySeconds) , ((iFestivalTS-iTodayTS) / DaySeconds) > 1 ? "s" : "" ); }
GetTimePeriod( iHour ) { new iTPIndex; for ( new i = 0 ; i < sizeof( TimePeriods ) ; i++ ) { if ( TimePeriods[ i ][ tpStart ] <= iHour <= TimePeriods[ i ][ tpEnd ] ) { iTPIndex = i; break; } } return iTPIndex; }
LoadFestivals() { new szFile[ 64 ] , iFile , szLine[ 41 ] , iDirLen , iFestivalIndex; new szMonth[ 3 ] , szDay[ 3 ] , szFestival[ sizeof( Festivals[][ fpFestival ] ) ]; copy( szFile[ ( iDirLen = get_configsdir( szFile , charsmax( szFile ) ) ) ] , charsmax( szFile ) - iDirLen , "/Festivals.ini" ); iFile = fopen( szFile , "r" ); while ( !feof( iFile ) && ( iFestivalIndex < sizeof( Festivals ) ) ) { if ( fgets( iFile , szLine , charsmax( szLine ) ) && ( szLine[ 0 ] != ';') ) { parse( szLine , szMonth , charsmax( szMonth ) , szDay , charsmax( szDay ) , szFestival , charsmax( szFestival ) ); Festivals[ iFestivalIndex ][ fpMonth ] = str_to_num( szMonth ); Festivals[ iFestivalIndex ][ fpDay ] = str_to_num( szDay ); copy( Festivals[ iFestivalIndex ][ fpFestival ] , charsmax( Festivals[][ fpFestival ] ) , szFestival ); iFestivalIndex++; } } return iFestivalIndex; }
__________________
Last edited by Bugsy; 11-29-2023 at 20:37.
|
|