Raised This Month: $ Target: $400
 0% 

/time countdown


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-28-2022 , 22:36   Re: /time countdown
Reply With Quote #2

Here is a quick version. Note that the days might be a bit off and the month in some rare cases could be one off due to having to assume each month is only 30 days. Doing it correctly I think it more complicated.

The countdown_target cvar needs to the the unix timestamp of the target date/time. You can convert a date/time to a unix timestamp on several websites online.

PHP Code:
#include <amxmodx>

new g_pCvarTargetTime

public plugin_init()
{
    
register_plugin("Countdown Time Display""0.1""Me");
    
register_clcmd("say /countdown""cmdCountdown");
    
g_pCvarTargetTime register_cvar("countdown_target""1671954140")
}

public 
cmdCountdown(id)
{
    new 
iSecondsiMinutesiHoursiDaysiMonthsiYears;
    new 
szMessage[128], len;
    
    
iSeconds get_pcvar_num(g_pCvarTargetTime) - get_systime();

    if( 
iSeconds )
    {
        
iYears iSeconds 31536000
        iMonths 
iSeconds 31536000 2592000;
        
iDays iSeconds 2592000 86400;
        
iHours iSeconds 86400 3600;
        
iMinutes iSeconds 3600 60;
        
iSeconds iSeconds 60;

        if( 
iYears )
        {
            
len += formatex(szMessage[len], charsmax(szMessage) - len"%dy "iYears)
        }

        if( 
iMonths )
        {
            
len += formatex(szMessage[len], charsmax(szMessage) - len"%dm "iMonths)
        }
        
        if( 
iDays )
        {
            
len += formatex(szMessage[len], charsmax(szMessage) - len"%dd "iDays)
        }
        
        if( 
iHours )
        {
            
len += formatex(szMessage[len], charsmax(szMessage) - len"%dh "iHours)
        }
        
        if( 
iMinutes )
        {
            
len += formatex(szMessage[len], charsmax(szMessage) - len"%dm "iMinutes)
        }
        
        if( 
iSeconds )
        {
            
len += formatex(szMessage[len], charsmax(szMessage) - len"%ds"iSeconds)
        }

        
client_print(idprint_chatszMessage);
    }
    else
    {
        
client_print(idprint_chat"The countdown has expired.");
    }

    return 
PLUGIN_HANDLED

__________________

Last edited by fysiks; 10-28-2022 at 22:40.
fysiks is offline
 



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 10:32.


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