Raised This Month: $ Target: $400
 0% 

Scripting help. How to check eg. February 14.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
The Inhabitant Of Heavens
Member
Join Date: Aug 2011
Old 11-16-2011 , 13:57   Re: Scripting help. How to check eg. February 14.
Reply With Quote #8

Code:
#include <amxmodx>

public plugin_init()
	time() 

time()
{
	new timestamp = TimeToUnix(2011, 12, 31, 11, 59, 0)
	
	if(get_systime() > timestamp) 
		client_print ( 0 , print_chat, ".......") 
}


stock const YearSeconds[2] = 
{ 
	31536000,	//Normal year
	31622400 	//Leap year
};

stock const MonthSeconds[12] = 
{ 
	2678400, //January	31 
	2419200, //February	28
	2678400, //March	31
	2592000, //April	30
	2678400, //May		31
	2592000, //June		30
	2678400, //July		31
	2678400, //August	31
	2592000, //September	30
	2678400, //October	31
	2592000, //November	30
	2678400  //December	31
};

stock const DaySeconds = 86400;
stock const HourSeconds = 3600;
stock const MinuteSeconds = 60;

stock UnixToTime(iTimeStamp , &iYear , &iMonth , &iDay , &iHour , &iMinute , &iSecond)
{
	new iTemp;
	
	iYear = 1970;
	iMonth = 1;
	iDay = 1;
	iHour = 0;

	while (iTimeStamp > 0)
	{
		iTemp = IsLeapYear(iYear);

		if ((iTimeStamp - YearSeconds[iTemp]) >= 0)
		{
			iTimeStamp -= YearSeconds[iTemp];
			iYear++;
		}
		else
		{
			break;
		}
	}

	while (iTimeStamp > 0)
	{
		iTemp = SecondsInMonth(iYear , iMonth);

		if ((iTimeStamp - iTemp) >= 0) 
		{
			iTimeStamp -= iTemp;
			iMonth++;
		}
		else
		{
			break;
		}
	}

	while (iTimeStamp > 0)
	{
		if ((iTimeStamp - DaySeconds) >= 0)
		{
			iTimeStamp -= DaySeconds;
			iDay++;
		}
		else
		{
			break;
		}
	}
	
	while (iTimeStamp > 0)
	{
		if ((iTimeStamp - HourSeconds) >= 0)
		{
			iTimeStamp -= HourSeconds;
			iHour++;
		}
		else
		{
			break;
		}
	}
	
	iMinute = (iTimeStamp / 60);
	iSecond = (iTimeStamp % 60);
}

stock TimeToUnix(const iYear , const iMonth , const iDay , const iHour , const iMinute , const iSecond)
{
	new i;
	new iTimeStamp;

	for (i = 1970 ; i < iYear ; i++)
		iTimeStamp += YearSeconds[IsLeapYear(i)];

	for (i = 1 ; i < iMonth ; i++)
		iTimeStamp += SecondsInMonth(iYear , i);

	iTimeStamp += ((iDay - 1) * DaySeconds);
	iTimeStamp += (iHour * HourSeconds);
	iTimeStamp += (iMinute * MinuteSeconds);
	iTimeStamp += iSecond;

	return iTimeStamp;
}

stock SecondsInMonth(const iYear , const iMonth) 
{
	return ((IsLeapYear(iYear) && (iMonth == 2)) ? (MonthSeconds[iMonth - 1] + DaySeconds) : MonthSeconds[iMonth - 1]);
}

stock IsLeapYear(const iYear) 
{
	return (((iYear % 4) == 0) && (((iYear % 100) != 0) || ((iYear % 400) == 0)));
}

Last edited by The Inhabitant Of Heavens; 11-16-2011 at 13:58.
The Inhabitant Of Heavens is offline
 



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 08:24.


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