seany123 Posted September 7, 2008 Author Share Posted September 7, 2008 I am going to be using 4 Cron jobs like this for 4 different values, energy, awake, nerve, hp (maybe more in future) Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-636014 Share on other sites More sharing options...
DarkWater Posted September 7, 2008 Share Posted September 7, 2008 I am going to be using 4 Cron jobs like this for 4 different values, energy, awake, nerve, hp (maybe more in future) Why not do it all in one script? Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-636021 Share on other sites More sharing options...
cooldude832 Posted September 7, 2008 Share Posted September 7, 2008 I am going to be using 4 Cron jobs like this for 4 different values, energy, awake, nerve, hp (maybe more in future) Why not do it all in one script? And in 1 query Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-636024 Share on other sites More sharing options...
seany123 Posted September 7, 2008 Author Share Posted September 7, 2008 well they are all in the same cron script. Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-636045 Share on other sites More sharing options...
seany123 Posted September 12, 2008 Author Share Posted September 12, 2008 the way im using this code is when someone goes to the home page it updates the databse using the cron... that means that if just 1 person goes to home, it will only update his database but no1 elses... im wanting it so if anyone goes on the home page then it will update everyones database. Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-640192 Share on other sites More sharing options...
seany123 Posted September 13, 2008 Author Share Posted September 13, 2008 is it possible? Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-640209 Share on other sites More sharing options...
seany123 Posted September 13, 2008 Author Share Posted September 13, 2008 Also just so everyone knows Im using: adodb php libary Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-640227 Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 the way im using this code is when someone goes to the home page it updates the databse using the cron... that means that if just 1 person goes to home, it will only update his database but no1 elses... im wanting it so if anyone goes on the home page then it will update everyones database. What? Cron does its thing automatically, so no one needs to visit any pages... Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-640229 Share on other sites More sharing options...
seany123 Posted September 13, 2008 Author Share Posted September 13, 2008 with that code you gave... will it update everyone elses database too? Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-640244 Share on other sites More sharing options...
seany123 Posted September 13, 2008 Author Share Posted September 13, 2008 would it update all players database? Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-640458 Share on other sites More sharing options...
seany123 Posted September 13, 2008 Author Share Posted September 13, 2008 okay to make things easier... on my home page i have a include(autocron.php); This is my Autocron.php: <?php $query = $db->execute("select * from `cron`"); while($row = $query->fetchrow()) { $cron[$row['name']] = $row['value']; } $now = time(); $diff = ($now - $cron['reset_last']); if($diff >= $cron['reset_time']) { include("cron/reset.php"); $db->execute("update `cron` set `value`=? where `name`=?", array($now, "reset_last")); } $diff = ($now - $cron['revive_last']); if($diff >= $cron['revive_time']) { include("cron/revive.php"); $db->execute("update `cron` set `value`=? where `name`=?", array($now, "revive_last")); } ?> This is my Revive.php <?php if(!defined('IN_GAME')) die('HACK'); $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $energy = $row['energy'] + ($row['maxenergy'] * .20); $energy = ($energy > $row['maxenergy']) ? $row['maxenergy'] : $energy; $query = sprintf('UPDATE players SET energy = %d WHERE id = %d', $energy, $row['id']); mysql_query($query) or die(mysql_error()); } $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $nerve = $row['nerve'] + ($row['maxnerve'] * .20); $nerve = ($nerve > $row['maxnerve']) ? $row['maxnerve'] : $nerve; $query = sprintf('UPDATE players SET nerve = %d WHERE id = %d', $nerve, $row['id']); mysql_query($query) or die(mysql_error()); } $query = "SELECT * FROM players"; $result = mysql_query($query) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $hp = $row['hp'] + ($row['maxhp'] * .25); $hp = ($hp > $row['maxhp']) ? $row['maxhp'] : $hp; $query = sprintf('UPDATE players SET hp = %d WHERE id = %d', $hp, $row['id']); mysql_query($query) or die(mysql_error()); } $awakeupdate = $player->awake + 5; $query = $db->execute("update `players` set `awake`=? where `id`=? and `awake`<`maxawake`", array($awakeupdate, $player->id)); ?> Okay so with the revive code (above) when someone goes to the homepage and it runs the autocron.php, which runs revive.php Will it update EVERYONES databases or just that person? if it only updates the 1 person, what code could be used to make it update everyones? Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-640661 Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 That's not cron... Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-640675 Share on other sites More sharing options...
seany123 Posted September 13, 2008 Author Share Posted September 13, 2008 it does the same thing as a cron and is as close to being a cron as my host allows. Quote Link to comment https://forums.phpfreaks.com/topic/123071-help-with-crons/page/2/#findComment-640689 Share on other sites More sharing options...
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.