DAMINK Posted October 1, 2014 Posted October 1, 2014 Im after a simple mod really. Once a day at a random time a page becomes accessible and a message like the hospital one comes up. Once the event has finished the page is no longer available until the next day. Quote
NonStopCoding Posted October 1, 2014 Posted October 1, 2014 has this page already been created that you want to block? Quote
DAMINK Posted October 4, 2014 Author Posted October 4, 2014 Oops i did not reply to you in the forums NSC. (i did in pm so im not totally rude) Ok yes this page i speak of has already been created. You created it NSC lolz. Although for what i am wanting i did not see that mattered. I simply want this page to be accessible only once a day at a random time. So im thinking i will just make another table or column and have that set to 1 for example and then once its set to 0 everything happens. Able to be set to 0 only once a day and have that time randomized. Sounds simple enough so i will try that. Although i assume there is better ways, its about the only way i can think to do it. Quote
NonStopCoding Posted October 5, 2014 Posted October 5, 2014 (edited) you could add a new table to the serverconfig which is already being pulled in the header then just add something like ALTER TABLE `serverconfig` ADD `locked` int(2) not null default 1; <?php if($worked['locked'] == 1) { echo Message('This page is blocked right now'); include_once(__DIR__.'/footer.php'); exit; } ?> i am pretty stumped on how to get him to spawn at a random time everyday Edited October 5, 2014 by NonStopCoding Quote
G7470 Posted October 5, 2014 Posted October 5, 2014 (edited) Another way to do this would involve a number of steps to attempt to achieve "randomization". First off, initially following [MENTION=70347]NonStopCoding[/MENTION]'s initial thought, expand that by allowing a unix timestamp into the "locked" field instead with a 0 default. ALTER TABLE `serverconfig` ADD `lockedtil` int(11) not null default 0; Then, on your daily cron, add something like this: $randtime = rand(time(), (time() + (23 * 60 * 60))); // random time from now until 23 hours from now (could change this accordingly) $res = mysql_query("UPDATE `serverconfig` SET `lockedtil` = '".$randtime."'"); Then, on the page that you would want to "hide" until that time is up: if($worked['lockedtil'] > time()) { echo Message('This page is blocked right now'); include_once(__DIR__.'/footer.php'); exit; } This would not be truly random (as the rand() function is only pseudo-random), but this is probably the closest that you would come to true randomization without much more code to do so. EDIT: Be aware that until the cron is run for the first time with the changes in to update "lockedtil" to a future time, the page will always be available. ~G7470 Edited October 5, 2014 by G7470 Quote
SRB Posted October 5, 2014 Posted October 5, 2014 (edited) This would not be truly random (as the rand() function is only pseudo-random), but this is probably the closest that you would come to true randomization without much more code to do so. Yeah, I totally know what you mean about rand() being the best options without far more code. If only there was something faster and more random available without re-writing the interwebz! Edited October 5, 2014 by Guest Quote
G7470 Posted October 5, 2014 Posted October 5, 2014 Yeah, I totally know what you mean about rand() being the best options without far more code. If only there was something faster and more random available without re-writing the interwebz! Not sure if you changed your post, but this link was initially shown on the email notification I got of your post, which disproved php.net's claim of mt_rand(): http://en.code-bude.net/2013/01/06/php-rand-vs-mt_rand-what-is-more-accurate-what-is-faster/ ~G7470 Quote
SRB Posted October 5, 2014 Posted October 5, 2014 Yes, I posted that one first and it does state mt_ is indeed faster, just not the 4x claim. Regardless, the miliseconds involved are irrelevant in PHP as it's not that fast regardless, and the difference is negligible in real world usage. The fact remains that it is a better random function though. Here too. Quote
G7470 Posted October 5, 2014 Posted October 5, 2014 True true haha. I do see your point. :p ~G7470 Quote
KyleMassacre Posted October 5, 2014 Posted October 5, 2014 Depending on what your using, I got (since I'm mobile) mt_rand being 300,000 ms faster running a few iterations in just a little for loop. Regardless of what you would use here I don't think it really matters as Guest stated. But what I would do for a module like this is store the next time the module should become available, give the players a little window like 2 hours and let the module do it's thing. You can use something like a string for the date so it's human readable or just a timestamp, and using getdate() may be pretty simple to manipulate visually in your code of what you want or use time() and do some fancy math like time()+ (2*60*60) to get 2 hours ahead or reverse to get 2 hours before and see if your current timestamp falls within your allowance. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.