Raised This Month: $51 Target: $400
 12% 

[HELP] Hours , Minutes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thekiller123
Member
Join Date: Dec 2012
Old 08-10-2013 , 07:54   [HELP] Hours , Minutes
Reply With Quote #1

...

Last edited by thekiller123; 07-19-2015 at 14:42.
thekiller123 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-10-2013 , 08:49   Re: [HELP] Hours , Minutes
Reply With Quote #2

You have to consider 2 cases, when happy hours are crossing midnight and when they are not.

Try this :

PHP Code:
#include < amxmodx >

#pragma semicolon 1

#define PLUGIN ""
#define VERSION "0.0.1"

new g_pCvarHappyHourStartHour;
new 
g_pCvarHappyHourStopHour;

new 
bool:g_bHappyHour;

public 
plugin_init()
{
    
register_pluginPLUGINVERSION"ConnorMcLeod" );

    
g_pCvarHappyHourStartHour register_cvar("amx_happyhour_start""22");
    
g_pCvarHappyHourStopHour register_cvar("amx_happyhour_stop""8");

    
register_event("HLTV""Event_HLTV_New_Round""a""1=0""2=0");
    
register_logevent("Event_Round_End"2"1=Round_End");
}

public 
plugin_cfg()
{
    
server_cmd("amx_cvar add %s""amx_happyhour_start");
    
server_cmd("amx_cvar add %s""amx_happyhour_stop");
}

public 
Event_HLTV_New_Round()
{
    if( !
g_bHappyHour )
    {
        new 
hmstartHour max(get_pcvar_num(g_pCvarHappyHourStartHour), 0), stopHour max(get_pcvar_num(g_pCvarHappyHourStopHour), 0);
        if( 
startHour 24 )
        {
            
startHour 0;
        }
        if( 
stopHour 24 )
        {
            
stopHour 0;
        }

        if( 
stopHour == startHour )
        {
            
set_fail_state("Start and Stop hours are equal");
            return;
        }

        
time(hm);

        if( 
startHour stopHour )
        {
            if( 
startHour <= stopHour )
            {
                
StartHappyHour(stopHour);
            }
            else
            {
                
HappyHourWaitTime(hmstartHour);
            }
        }
        else
        {
            if( 
startHour <= || stopHour )
            {
                
StartHappyHour(stopHour);
            }
            else
            {
                
HappyHourWaitTime(hmstartHour);
            }
        }
    }
}

public 
Event_Round_End()
{
    if( 
g_bHappyHour )
    {
        new 
hmstartHour max(get_pcvar_num(g_pCvarHappyHourStartHour), 0), stopHour max(get_pcvar_num(g_pCvarHappyHourStopHour), 0);
        if( 
startHour 24 )
        {
            
startHour 0;
        }
        if( 
stopHour 24 )
        {
            
stopHour 0;
        }
        
        if( 
stopHour == startHour )
        {
            
set_fail_state("Start and Stop hours are equal");
            return;
        }
        
        
time(hm);
        
        if( 
startHour stopHour )
        {
            if( 
startHour || >= stopHour )
            {
                
StopHappyHour();
                
HappyHourWaitTime(hmstartHour);
            }
        }
        else
        {
            if( 
stopHour <= startHour)
            {
                
StopHappyHour();
                
HappyHourWaitTime(hmstartHour);
            }
        }
    }
}

StartHappyHourstopHour )
{
    
g_bHappyHour true;
    
client_print(0print_chat"Happy Hour started, gonna end at %s%d:00"stopHour "0" ""stopHour); 
}

StopHappyHour()
{
    
g_bHappyHour false;
    
client_print(0print_chat"Happy Hour has ended");
}

HappyHourWaitTime(hmstartHour)
{
    if( 
startHour )
    {
        
-= 24;
    }
    if( 
)
    {
        
+= 1;
        
60 m;
    }

    
startHour h;

    
client_print(0print_chat"Happy Hour gonna start in %d hour%s and %d minute%s at %s%d:00"h"s" ""m"s" ""startHour "0" ""startHour); 

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
thekiller123
Member
Join Date: Dec 2012
Old 08-10-2013 , 09:11   Re: [HELP] Hours , Minutes
Reply With Quote #3

thanks.

Last edited by thekiller123; 03-20-2015 at 18:25.
thekiller123 is offline
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 11:17.


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