EQ2Interface.com
Search Downloads


Go Back   EQ2Interface > General Discussion > Chit-Chat

Reply
Thread Tools Search this Thread Display Modes
  #1  
Unread 04-04-2009, 03:51 PM
Drumstix42's Avatar
Drumstix42 Drumstix42 is offline
A Griffon
Featured
 
Join Date: Oct 2004
Server: Antonia Bayle
Posts: 3,287
Default 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
$mission_total = 19;
$missions = array(
	0	=>	array( zone => "Befallen: Necrotic Asylum", quest => "Destroy the Dread Exarch!" ),
	1	=>	array( zone => "Befallen: Cavern of the Afflicted", quest => "Abating the Evil" ),
	2	=>	array( zone => "Befallen: Halls of the Forsaken", quest	=> "Residual Haunting" ),
	3	=>	array( zone => "The Ruins of Guk: The Lower Corridors", quest => "Freeing the Froglok King" ),
	4	=>	array( zone => "The Ruins of Guk: Ykesha's Outer Stronghold", quest => "The Will of the Warlord" ),
	5	=>	array( zone => "The Ruins of Guk: Halls of the Fallen", quest => "The Will of the Warlord" ),
	6	=>	array( zone => "Miragul's Phylactery: The Anathema", quest => "From Within the Phylactery" ),
	7	=>	array( zone => "Miragul's Phylactery: The Crucible", quest => "The Trials of Miragul" ),
	8	=>	array( zone => "Miragul's Phylactery: Scion of Ice", quest => "Rattling the Pillars" ),
	9	=>	array( zone => "Evernight Abbey", quest => "The Ydalian Anlace" ),
	10	=>	array( zone => "Mistmyr Manor", quest => "Xanne's Carcanet" ),
	11	=>	array( zone => "Ravenscale Repository", quest => "Pillaging the Repository" ),
	12	=>	array( zone => "Deep Forge", quest => "Firing the Firelord" ),
	13	=>	array( zone => "Najena's Hollow Tower", quest => "Creamating the Creation" ),
	14	=>	array( zone => "Nu'roga", quest => "Teaching the Drogans a Lesson" ),
	15	=>	array( zone => "Veksar: The Sunken Theater", quest => "A Night in the Theatre" ),
	16	=>	array( zone => "Obelisk of Ahkzul", quest => "Nothing Short of Perfect Execution" ),
	17	=>	array( zone => "Anchor of Bazzul", quest => "Execution of Executor Zynos" ),
	18	=>	array( zone => "Emperor Atrebe's Laboratory: The Fabled City of Kor-sha", quest => "Removing the Heads" )
);

// edit these values below according to your server's timezone and DD cycle time
// see this page for timzones: http://us.php.net/timezones
date_default_timezone_set('America/Los_Angeles'); // set to westcoast time (Blackburrow's native timezone)
$start_time = strtotime("2009-03-24 03:00:00"); // seconds since January 1 1970 00:00:00 UTC (set to 3am -- when the DD cycles on Blackburrow)
$current_time = strtotime(date("Y-m-d h:i:s")); // seconds since January 1 1970 00:00:00 UTC (get local time in timezone set above)

$start_time = floor( $start_time / (24*60*60) ); // convert seconds to days, round down
$current_time = floor( $current_time / (24*60*60) ); // convert seconds to days, round down

$check_time = $current_time - $start_time; // find difference

$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)
$missions[$check_time%$mission_total][zone] -- returns the current misison's zone (ie: Deep Forge)
$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.
__________________
"I'm afraid you're guilty of thought-crime. Don't bother getting the door, we'll let ourselves in..."
<Donate to DrumsUI> < [DrumsUI] Updater > < [DrumsUI] Full Interface> < Drumstix42 on Twitch.tv
>
Reply With Quote
  #2  
Unread 04-05-2009, 09:12 AM
sorinth sorinth is offline
A Griffon
 
Join Date: Jun 2006
Server: Najena
Posts: 160
Default

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.
Reply With Quote
  #3  
Unread 04-05-2009, 09:41 AM
gm9 gm9 is offline
gm10-1
Premium Member
EQ2Interface Super Mod
Featured
 
Join Date: Feb 2006
Posts: 6,479
Default

Quote:
Originally Posted by sorinth View Post
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.
No, what his code is doing is cycling through those 19 zones/quests over and over again starting from a specific start date. Look at the last two lines.
__________________
P R O F I T U I ∙ R E B O R N [Auto-Updater] | [Portal] | [F.A.Q.] | [Support Forums]
~ Retired ~
If it does not work, you likely installed it incorrectly. Always try a clean install before reporting bugs.
Reply With Quote
  #4  
Unread 04-05-2009, 10:11 AM
sorinth sorinth is offline
A Griffon
 
Join Date: Jun 2006
Server: Najena
Posts: 160
Default

Quote:
Originally Posted by gm9 View Post
No, what his code is doing is cycling through those 19 zones/quests over and over again starting from a specific start date. Look at the last two lines.
yea i see that but what happens when current_time (i am assuming converted to days) is greater than 18? so, it will do the table lookup on 19. Maybe I am just thinking too much into it...
Reply With Quote
  #5  
Unread 04-05-2009, 10:20 AM
gm9 gm9 is offline
gm10-1
Premium Member
EQ2Interface Super Mod
Featured
 
Join Date: Feb 2006
Posts: 6,479
Default

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...
__________________
P R O F I T U I ∙ R E B O R N [Auto-Updater] | [Portal] | [F.A.Q.] | [Support Forums]
~ Retired ~
If it does not work, you likely installed it incorrectly. Always try a clean install before reporting bugs.

Last edited by gm9 : 04-05-2009 at 10:24 AM.
Reply With Quote
  #6  
Unread 04-05-2009, 10:32 AM
sorinth sorinth is offline
A Griffon
 
Join Date: Jun 2006
Server: Najena
Posts: 160
Default

$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!
Reply With Quote
  #7  
Unread 04-05-2009, 07:04 PM
Drumstix42's Avatar
Drumstix42 Drumstix42 is offline
A Griffon
Featured
 
Join Date: Oct 2004
Server: Antonia Bayle
Posts: 3,287
Default

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)
__________________
"I'm afraid you're guilty of thought-crime. Don't bother getting the door, we'll let ourselves in..."
<Donate to DrumsUI> < [DrumsUI] Updater > < [DrumsUI] Full Interface> < Drumstix42 on Twitch.tv
>
Reply With Quote
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 04:25 PM.


Our Network
EQInterface | EQ2Interface | WoWInterface | LoTROInterface | ESOUI | MMOUI