Raised This Month: $ Target: $400
 0% 

get Day / Night


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ghost95v
Senior Member
Join Date: Apr 2014
Location: somewhere in universe
Old 12-25-2014 , 15:22   get Day / Night
Reply With Quote #1

Hello, im wondering if is this code good to get Night hours ? and does this can use to much CPU usage?

PHP Code:

public plugin_init()
{
    static 
Hour[64], bool:Night;

    
get_time("%H"Hour63);
    
    if (
Hour[0] == '0')
        
Night true;

    else
        
Night false
__________________
ghost95v is offline
Send a message via Skype™ to ghost95v
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-25-2014 , 15:29   Re: get Day / Night
Reply With Quote #2

How this could cause CPU usage ? plugin_init is called one time and also you don't need to use static. Also the array size is too big, 6 is enough for a full time string. Also your code won't work 100%, because you are not sure that plugin_init will get called(by map change, server (re)start) exactly at 00:00
__________________

Last edited by HamletEagle; 12-25-2014 at 15:31.
HamletEagle is offline
ghost95v
Senior Member
Join Date: Apr 2014
Location: somewhere in universe
Old 12-25-2014 , 15:45   Re: get Day / Night
Reply With Quote #3

1- thank you for the advice.
2- the code works great, ( tested aloot ), sure it will be called always after a map change if the time contains 00: xx / 01: xx / 02: xx etc....
3- cant understand why array size enought for that ?
__________________

Last edited by ghost95v; 12-25-2014 at 15:52.
ghost95v is offline
Send a message via Skype™ to ghost95v
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 12-26-2014 , 05:13   Re: get Day / Night
Reply With Quote #4

Sorry, I assumed that you only want "00x" hour. If I remember well %H give you only the hour without minutes so it will be a string like ab. 64 cells are too much for such little string.
__________________
HamletEagle is offline
ghost95v
Senior Member
Join Date: Apr 2014
Location: somewhere in universe
Old 12-26-2014 , 07:21   Re: get Day / Night
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
Sorry, I assumed that you only want "00x" hour. If I remember well %H give you only the hour without minutes so it will be a string like ab. 64 cells are too much for such little string.
Yes... and for the array size your'e right, its enought only "6", size 63 can be useful only if we do this below

PHP Code:
get_time("!g%m/%d/%Y - %H:%M:%S"Hour63
__________________
ghost95v is offline
Send a message via Skype™ to ghost95v
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-26-2014 , 07:15   Re: get Day / Night
Reply With Quote #6

You might want to use this function instead:
PHP Code:
time(&hour=0, &minute=0, &second=0); 
so you would have number of hours as an integer instead of a string, so comparing it to other values would be easier.
PHP Code:
new iHours;
time(iHours);
// iHours now contains number of hours!
// ...
if(iHours >= 22 && iHours 7)
{
    
// Nighttime is from 10 PM to 7 AM

klippy 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 15:22.


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