AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Simple doubt about getting time. (https://forums.alliedmods.net/showthread.php?t=93261)

I need some help 05-26-2009 16:50

Simple doubt about getting time.
 
Im trying to do an "happy hour" plugin. I mean, it just activates after 12AM, and stops at 6AM.

The only thing I don't know to do is to handle with time.

Thanks in advance

padilha007 05-26-2009 18:21

Re: Simple doubt about getting time.
 
http://forums.alliedmods.net/showthr...ighlight=clock

Bugsy 05-26-2009 22:54

Re: Simple doubt about getting time.
 
The time is 24hr time so 12am is 0.

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Happy Hour"
#define VERSION "1.0"
#define AUTHOR "bugsy"

new boolg_bHappyHour;
new 
g_pHappyHourStart;
new 
g_pHappyHourEnd;
new 
g_pHappyHourInterval;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
g_pHappyHourStart register_cvar"hh_start" "0" );
    
g_pHappyHourEnd register_cvar"hh_end" "6" );
    
g_pHappyHourInterval register_cvar"hh_interval" "15.0" );
}

public 
plugin_cfg()
{
    
set_taskget_pcvar_floatg_pHappyHourInterval ) , "CheckTime" 1921 _,_,"b");
}

public 
CheckTime()
{
    static 
iHouriEnd;

    
iEnd get_pcvar_numg_pHappyHourEnd );
    
timeiHour ,_,_);
    
    if ( !
g_bHappyHour && ( get_pcvar_numg_pHappyHourStart ) <= iHour iEnd ) )
    {
        
g_bHappyHour true;
        
        
//Enable your happy hour code here
    
}
    else if ( 
g_bHappyHour && ( iHour >= iEnd ) )
    {
        
g_bHappyHour false;
        
        
//Disable your happy hour code here
    
}



I need some help 05-27-2009 08:24

Re: Simple doubt about getting time.
 
Oh thanks for answering. I tried this before but I haven't seen if it is working...
PHP Code:

    static currenttime[10]
    
get_time("%H"currenttime9)
    static 
secondarytime
    secondarytime 
str_to_num(currenttime)
    if(
secondarytime == 24 || secondarytime 10)
    {
        
g_happy true
    
}
    else
    {
        
g_happy false
    


Do you think that the == 24 is wrong?

Bugsy 05-27-2009 10:44

Re: Simple doubt about getting time.
 
Quote:

Originally Posted by I need some help (Post 835698)
Oh thanks for answering. I tried this before but I haven't seen if it is working...
PHP Code:

    static currenttime[10]
    
get_time("%H"currenttime9)
    static 
secondarytime
    secondarytime 
str_to_num(currenttime)
    if(
secondarytime == 24 || secondarytime 10)
    {
        
g_happy true
    
}
    else
    {
        
g_happy false
    


Do you think that the == 24 is wrong?

Yes it is wrong because the hour value will never be 24 on a 24 hour clock. The hour range goes from 0 to 23 then back to 0.

0 = 12AM
12 = 12pm
23 = 11pm
23:59:59 = the highest time then back to 0:0:0


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

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