=|[76AD]|= TatsuSaisei
08-15-2006, 02:38 PM
I was not sure where to put this so I plopped it here.... back a few months ago I was writing a plugin for my clan, and we needed certain actions to take place on certain days of the week. I could not find a way to simply get this info from the Server, or game engine, so I made a function that "calculated" the day of the week based off of the date, month and year....
I figured I have asked for so much, and have gotten alot of replies and help that it is time for me to give something back.... I know alot of people could make some nice things with a function like this...
so here it is... (this is NOT a complete plugin, just the bits of code that do the function)
#define PLUGIN "Get Day of Week"
#define VERSION "1.0"
#define AUTHOR "=|[76AD]|= TatsuSaisei"
new theday[16] //variable to use in a condition statement, depending on what you want to do...
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
// Add your init code here.
set_task(60.0,"GetDOW",1,"",0,"b")
}
public GetDOW()
{
new xmonth,xdate,xyear,w,day
date(xyear,xmonth,xdate)
switch(xmonth){
case 01:{
xmonth = 13
xyear = xyear - 1
}
case 02:{
xmonth = 14
xyear = xyear - 1
}
}
w = xdate + (2 * xmonth) + floatround(0.6 * (xmonth + 1), floatround_floor) + xyear + floatround(float(xyear)/4.0, floatround_floor) - floatround(float(xyear)/100.0, floatround_floor) + floatround(float(xyear)/400.0, floatround_floor) + 2
day = w % 7
switch(day){
case 0:{
theday = "Saturday"
}
case 1:{
theday = "Sunday"
}
case 2:{
theday = "Monday"
}
case 3:{
theday = "Tuesday"
}
case 4:{
theday = "Wednesday"
}
case 5:{
theday = "Thursday"
}
case 6:{
theday = "Friday"
}
}
return PLUGIN_CONTINUE
}
It works and works well... and is easy to incorporate into anything... I am actually in the process of writing a plugin to force a server to "quit" in an effort to automatically "reboot" or restart the server, knowing my provider and many others use a script that restarts a server when it crashes or is shut off...
so here is my gift to the developers who have helped me, and for the rest who are learning to code...
I figured I have asked for so much, and have gotten alot of replies and help that it is time for me to give something back.... I know alot of people could make some nice things with a function like this...
so here it is... (this is NOT a complete plugin, just the bits of code that do the function)
#define PLUGIN "Get Day of Week"
#define VERSION "1.0"
#define AUTHOR "=|[76AD]|= TatsuSaisei"
new theday[16] //variable to use in a condition statement, depending on what you want to do...
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
// Add your init code here.
set_task(60.0,"GetDOW",1,"",0,"b")
}
public GetDOW()
{
new xmonth,xdate,xyear,w,day
date(xyear,xmonth,xdate)
switch(xmonth){
case 01:{
xmonth = 13
xyear = xyear - 1
}
case 02:{
xmonth = 14
xyear = xyear - 1
}
}
w = xdate + (2 * xmonth) + floatround(0.6 * (xmonth + 1), floatround_floor) + xyear + floatround(float(xyear)/4.0, floatround_floor) - floatround(float(xyear)/100.0, floatround_floor) + floatround(float(xyear)/400.0, floatround_floor) + 2
day = w % 7
switch(day){
case 0:{
theday = "Saturday"
}
case 1:{
theday = "Sunday"
}
case 2:{
theday = "Monday"
}
case 3:{
theday = "Tuesday"
}
case 4:{
theday = "Wednesday"
}
case 5:{
theday = "Thursday"
}
case 6:{
theday = "Friday"
}
}
return PLUGIN_CONTINUE
}
It works and works well... and is easy to incorporate into anything... I am actually in the process of writing a plugin to force a server to "quit" in an effort to automatically "reboot" or restart the server, knowing my provider and many others use a script that restarts a server when it crashes or is shut off...
so here is my gift to the developers who have helped me, and for the rest who are learning to code...