| closedGetting the DAY of the week... |
| Started by =|[76AD]|= TatsuSaisei on 08-15-2006, 01:38 PM |
Threads: 54
Joined: May 2005
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....n nI 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...n nso here it is... (this is NOT a complete plugin, just the bits of code that do the function)n n n
n n#define PLUGIN "Get Day of Week"n#define VERSION "1.0"n#define AUTHOR "=|[76AD]|= TatsuSaisei"n nnew theday[16] //variable to use in a condition statement, depending on what you want to do...n npublic plugin_init() {nregister_plugin(PLUGIN, VERSION, AUTHOR)n // Add your init code here.nset_task(60.0,"GetDOW",1,"",0,"b")n}n npublic GetDOW() n {n new xmonth,xdate,xyear,w,dayn date(xyear,xmonth,xdate)n switch(xmonth){n case 01:{n xmonth = 13n xyear = xyear - 1n }n case 02:{n xmonth = 14n xyear = xyear - 1n }n }n 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) + 2n day = w % 7n switch(day){n case 0:{n theday = "Saturday" n }n case 1:{n theday = "Sunday"n }n case 2:{n theday = "Monday"n }n case 3:{n theday = "Tuesday"n }n case 4:{n theday = "Wednesday"n }n case 5:{n theday = "Thursday"n }n case 6:{n theday = "Friday"n }n }n n return PLUGIN_CONTINUEn}nn nIt 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...n nso here is my gift to the developers who have helped me, and for the rest who are learning to code...Threads: 0
Joined: Aug 2006
nice i hope my plugin will work you all will love-it
Threads: 0
Joined: Nov 2005
Not to say this isn't nice, but I don't see the advantage of this over get_time? nnFrom Funcwiki: nget_time ( const format[],output[],len )nn%a abbreviated weekday name (Sun)n%A full weekday name (Sunday)n%b abbreviated month name (Dec)n%B full month name (December)n%c date and time (Dec 2 06:55:15 1979)n%d day of the month (02)n%H hour of the 24-hour day (06)n%I hour of the 12-hour day (06)n%j day of the year, from 001 (335)n%m month of the year, from 01 (12)n%M minutes after the hour (55)n%p AM/PM indicator (AM)n%S seconds after the minute (15)n%U Sunday week of the year, from 00 (48)n%w day of the week, from 0 for Sunday (6)n%W Monday week of the year, from 00 (47)n%x date (Dec 2 1979)n%X time (06:55:15)n%y year of the century, from 00 (79)n%Y year (1979)nn%w would allow you to determine the current day of the week, seems abit simpler :D
Threads: 103
Joined: May 2005
lol ive never seen those before.. guess i should start looking thru the wiki a bit more instead of just the include files & trying to find my way thru the hlsdk
Threads: 54
Joined: May 2005
Not to say this isn't nice, but I don't see the advantage of this over get_time? n nFrom Funcwiki: nget_time ( const format[],output[],len )n n%a abbreviated weekday name (Sun)n%A full weekday name (Sunday)n...n%w would allow you to determine the current day of the week, seems abit simpler :Dn nWell... at the time I did not have this information, until NOW.... yeah its a bit "much" now in the face of this, but it served its purpose at the time... and since there has never been full documentation of any magnitude, information was limited to what was on hand at the time...n nbut I thank you tremendously for bringing to light information that will save me alot of code...n nEDIT: The comment you refer to was posted 4 months ago... lol, and I had used this script for far longer... so that would explain why at the time, I used this to get what I needed... trying %A to get the name of the day of the week, was just something I would not have thought of immediately... loln nSo yeah, my code is now overkill...
Threads: 103
Joined: May 2005
hah aint it funny how that all worked out...nnnhappens alot to me hehe

