Raised This Month: $ Target: $400
 0% 

Simple doubt about getting time.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
I need some help
BANNED
Join Date: May 2009
Old 05-26-2009 , 16:50   Simple doubt about getting time.
Reply With Quote #1

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
I need some help is offline
padilha007
Senior Member
Join Date: Jul 2008
Old 05-26-2009 , 18:21   Re: Simple doubt about getting time.
Reply With Quote #2

http://forums.alliedmods.net/showthr...ighlight=clock
__________________

padilha007 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-26-2009 , 22:54   Re: Simple doubt about getting time.
Reply With Quote #3

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
    
}

__________________

Last edited by Bugsy; 05-27-2009 at 01:23.
Bugsy is offline
I need some help
BANNED
Join Date: May 2009
Old 05-27-2009 , 08:24   Re: Simple doubt about getting time.
Reply With Quote #4

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?
I need some help is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-27-2009 , 10:44   Re: Simple doubt about getting time.
Reply With Quote #5

Quote:
Originally Posted by I need some help View Post
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
__________________
Bugsy 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 01:25.


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