![]() |
Daily Double block - snippet (PHP)
This snippet of code will return the Daily Double, set to change at the specified time in the specified timezone.
I play on Blackburrow, so my server's timezone is west coast time, and my server's DD cycles at 3am. I started out in Javascript, and decided that timezones were way too annoying to figure out. So, after a couple slight problems, I started over in PHP. I believe you'll need PHP5 support for the below code. Not positive. Code:
// 19 missions in all$missions[$check_time%$mission_total][quest] -- returns the current quest's name (ie: Firing the Firelord) I like to have the quest name and then link it to a search on say eq2.wikia.com. Enjoy. |
Interesting snippet... one quick question, what happens after 19 days? Now, unless I dont fully understand how the lookup works, it would seem that after 19 days it will get stuck at kor'sha. Since your table max's at 19, and then you do a lookup on the 20th day.
|
Quote:
|
Quote:
|
Not sure where you go wrong reading his code, but since I started responding I might as well give you a quick explanation: he's flooring the time divided by seconds, minutes and 24 hours, so yeah it's converted to full days. Then he's calculating the difference in days between his start date and the current date and putting the resulting difference in days into $check_time, on which he is then performing a modulus operation with respect to the 19 array elements to determine how many days we are into the current 19 day cycle. Mathematically the result of that can never be greater than 18. :)
PS: Disclaimer: I've got nothing to do with the code in the OP, hope Drums you don't mind that I'm explaining your code... |
$mission_zone = $missions[$check_time%$mission_total][zone]; // get the mission zone name (% is a modulus -- Modulus is the remainder after the division)
$mission_quest = $missions[$check_time%$mission_total][quest]; // get the mission quest name (% is a modulus -- Modulus is the remainder after the division) Well, check_time could be greater than 18, I was just unfamilir with how it would handle Mission_total (I told ya i been out of programming for a while). So, that would limit the max to 18 and yet allow for expandabiliy. Nicely done! and thanx for the quick tutorial! |
gm9 is correct. Mathematically the returned value for the mission # can never be greater than 18. The modulus operator is pretty cool and I personally only knew of it's existence in probably the past year or so and never knew a good reason to use it.
I realize now I could probably just use array_size or something, instead of having the hard-coded number 19, but oh well. And yes it allows easily to add/remove missions should it be necessary. It's simple division, between two numbers, but the % sign uses the remainder, so that the number can never be more than 18. 0%19 = 0 (0 is mission #1 starting at 0 in code) 10%19 = 10 18%19 = 18 (18 is mission #19 since we started at 0 in code) 19%19 = 0 (0 would be the first mission, starting the cycle over) |
| All times are GMT -5. The time now is 10:03 AM. |
vBulletin® - Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
© MMOUI