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

Solved How to Use get_time() or time() for specific hours?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
WhiteFang1319
Senior Member
Join Date: Jan 2017
Old 09-24-2017 , 09:52   How to Use get_time() or time() for specific hours?
Reply With Quote #1

Hello.
I want some code to run at specific hours only so I've been searching and found this: https://forums.alliedmods.net/showth...highlight=time

It does help me but I want to with hours with intervals like: 10-110 and then 130-140.
Also I want to change the conditions for days on some specific days. Any Help?

Last edited by WhiteFang1319; 09-27-2017 at 06:46. Reason: Solved.
WhiteFang1319 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-24-2017 , 09:59   Re: How to Use get_time() or time() for specific hours?
Reply With Quote #2

Check if the retrieved hour value is between those values you need, it's simple as that.

For days you can use date().
klippy is offline
WhiteFang1319
Senior Member
Join Date: Jan 2017
Old 09-25-2017 , 01:47   Re: How to Use get_time() or time() for specific hours?
Reply With Quote #3

I do get how to use between hours but I don't get how to use it with hours + minutes like 10:20-11:40. In my post it replaced by an emoji. Since I'm a beginner I don't know much. Also can you help me so that it calculates Saturdays and Sundays and changes the execution?
WhiteFang1319 is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 09-25-2017 , 09:05   Re: How to Use get_time() or time() for specific hours?
Reply With Quote #4

Based onto http://www.cplusplus.com/reference/ctime/strftime/
Spoiler
__________________

Last edited by Relaxing; 09-25-2017 at 09:08. Reason: 'min' native
Relaxing is offline
WhiteFang1319
Senior Member
Join Date: Jan 2017
Old 09-27-2017 , 02:18   Re: How to Use get_time() or time() for specific hours?
Reply With Quote #5

Thank you. I was able to make the code run at a specific time by doing like this:
Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "AUTHOR"


public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_clcmd("say /time", "timetest")
	
	// Add your code here...
}

public timetest(id)
{
	new sysdate[20]
	get_time("%A", sysdate, charsmax(sysdate) - 1) 
	new hour, iMin; time(hour, iMin); 
	server_print("Current day of week: [%s], Clock: [%d:%d]", sysdate, hour, iMin); 
	client_print(id, print_chat, "Current day of Week: [%s], Clock: [%d:%d]", sysdate, hour, iMin);
	
	if(hour == 12 && iMin << 59)
	{
		server_cmd("sv_restart 1")
	}
	
	else
	{
		client_print(id, print_chat, "You cannot start the game mode at this time");
	}
	
}
I still don't get how to make it work differently on some specific days: Saturdays and Sundays. Perhaps I should explain it better. In my server we have a custom game mode which we play for specific hours but sometimes admins start it by mistake so I wanted to add this feature. For these 2 days I want the time check to be removed. Any help?
WhiteFang1319 is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 09-27-2017 , 03:31   Re: How to Use get_time() or time() for specific hours?
Reply With Quote #6

PHP Code:
if(equal(sysdate"Saturday") || equal(sysdate"Sunday")) {
    
//Your code

__________________
Airkish is offline
WhiteFang1319
Senior Member
Join Date: Jan 2017
Old 09-27-2017 , 06:46   Re: How to Use get_time() or time() for specific hours?
Reply With Quote #7

Quote:
Originally Posted by Airkish View Post
PHP Code:
if(equal(sysdate"Saturday") || equal(sysdate"Sunday")) {
    
//Your code

Thank you. It works now.
WhiteFang1319 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-27-2017 , 17:09   Re: How to Use get_time() or time() for specific hours?
Reply With Quote #8

You don't actually need iMin << 59.
It doesn't do what you think as proven below, you probably meant to use < or <=.
But you don't need it at all actually. As long as the hour is 12 it doesn't matter what the minute is. It will always be between 0 and 59 so there's no point to even check it.

Code:
if(hour == 12 && iMin << 59)
->
Code:
if(hour == 12)


<< is used to shift bits to the left in binary operations.
If you use the code in the current state it won't run at 12:00 and at 122.
Code:
iMin(00) << 59 = 0
iMin(01) << 59 = 134217728
iMin(02) << 59 = 268435456
iMin(03) << 59 = 402653184
iMin(04) << 59 = 536870912
iMin(05) << 59 = 671088640
iMin(06) << 59 = 805306368
iMin(07) << 59 = 939524096
iMin(08) << 59 = 1073741824
iMin(09) << 59 = 1207959552
iMin(10) << 59 = 1342177280
iMin(11) << 59 = 1476395008
iMin(12) << 59 = 1610612736
iMin(13) << 59 = 1744830464
iMin(14) << 59 = 1879048192
iMin(15) << 59 = 2013265920
iMin(16) << 59 = -2147483648
iMin(17) << 59 = -2013265920
iMin(18) << 59 = -1879048192
iMin(19) << 59 = -1744830464
iMin(20) << 59 = -1610612736
iMin(21) << 59 = -1476395008
iMin(22) << 59 = -1342177280
iMin(23) << 59 = -1207959552
iMin(24) << 59 = -1073741824
iMin(25) << 59 = -939524096
iMin(26) << 59 = -805306368
iMin(27) << 59 = -671088640
iMin(28) << 59 = -536870912
iMin(29) << 59 = -402653184
iMin(30) << 59 = -268435456
iMin(31) << 59 = -134217728
iMin(32) << 59 = 0
iMin(33) << 59 = 134217728
iMin(34) << 59 = 268435456
iMin(35) << 59 = 402653184
iMin(36) << 59 = 536870912
iMin(37) << 59 = 671088640
iMin(38) << 59 = 805306368
iMin(39) << 59 = 939524096
iMin(40) << 59 = 1073741824
iMin(41) << 59 = 1207959552
iMin(42) << 59 = 1342177280
iMin(43) << 59 = 1476395008
iMin(44) << 59 = 1610612736
iMin(45) << 59 = 1744830464
iMin(46) << 59 = 1879048192
iMin(47) << 59 = 2013265920
iMin(48) << 59 = -2147483648
iMin(49) << 59 = -2013265920
iMin(50) << 59 = -1879048192
iMin(51) << 59 = -1744830464
iMin(52) << 59 = -1610612736
iMin(53) << 59 = -1476395008
iMin(54) << 59 = -1342177280
iMin(55) << 59 = -1207959552
iMin(56) << 59 = -1073741824
iMin(57) << 59 = -939524096
iMin(58) << 59 = -805306368
iMin(59) << 59 = -671088640

Last edited by Black Rose; 09-27-2017 at 17:11.
Black Rose is offline
WhiteFang1319
Senior Member
Join Date: Jan 2017
Old 09-28-2017 , 09:32   Re: How to Use get_time() or time() for specific hours?
Reply With Quote #9

Quote:
Originally Posted by Black Rose View Post
You don't actually need iMin << 59.
It doesn't do what you think as proven below, you probably meant to use < or <=.
But you don't need it at all actually. As long as the hour is 12 it doesn't matter what the minute is. It will always be between 0 and 59 so there's no point to even check it.

Code:
if(hour == 12 && iMin << 59)
->
Code:
if(hour == 12)


<< is used to shift bits to the left in binary operations.
If you use the code in the current state it won't run at 12:00 and at 122.
Code:
iMin(00) << 59 = 0
iMin(01) << 59 = 134217728
iMin(02) << 59 = 268435456
iMin(03) << 59 = 402653184
iMin(04) << 59 = 536870912
iMin(05) << 59 = 671088640
iMin(06) << 59 = 805306368
iMin(07) << 59 = 939524096
iMin(08) << 59 = 1073741824
iMin(09) << 59 = 1207959552
iMin(10) << 59 = 1342177280
iMin(11) << 59 = 1476395008
iMin(12) << 59 = 1610612736
iMin(13) << 59 = 1744830464
iMin(14) << 59 = 1879048192
iMin(15) << 59 = 2013265920
iMin(16) << 59 = -2147483648
iMin(17) << 59 = -2013265920
iMin(18) << 59 = -1879048192
iMin(19) << 59 = -1744830464
iMin(20) << 59 = -1610612736
iMin(21) << 59 = -1476395008
iMin(22) << 59 = -1342177280
iMin(23) << 59 = -1207959552
iMin(24) << 59 = -1073741824
iMin(25) << 59 = -939524096
iMin(26) << 59 = -805306368
iMin(27) << 59 = -671088640
iMin(28) << 59 = -536870912
iMin(29) << 59 = -402653184
iMin(30) << 59 = -268435456
iMin(31) << 59 = -134217728
iMin(32) << 59 = 0
iMin(33) << 59 = 134217728
iMin(34) << 59 = 268435456
iMin(35) << 59 = 402653184
iMin(36) << 59 = 536870912
iMin(37) << 59 = 671088640
iMin(38) << 59 = 805306368
iMin(39) << 59 = 939524096
iMin(40) << 59 = 1073741824
iMin(41) << 59 = 1207959552
iMin(42) << 59 = 1342177280
iMin(43) << 59 = 1476395008
iMin(44) << 59 = 1610612736
iMin(45) << 59 = 1744830464
iMin(46) << 59 = 1879048192
iMin(47) << 59 = 2013265920
iMin(48) << 59 = -2147483648
iMin(49) << 59 = -2013265920
iMin(50) << 59 = -1879048192
iMin(51) << 59 = -1744830464
iMin(52) << 59 = -1610612736
iMin(53) << 59 = -1476395008
iMin(54) << 59 = -1342177280
iMin(55) << 59 = -1207959552
iMin(56) << 59 = -1073741824
iMin(57) << 59 = -939524096
iMin(58) << 59 = -805306368
iMin(59) << 59 = -671088640
Oh. Thank you.
WhiteFang1319 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 21:28.


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