Thauwa Posted May 15, 2009 Share Posted May 15, 2009 Is this possible? I have an making a game. What I have seen in manyn online games is that resources are added every minute to the stock. So, any suggestions as to how I could do this? Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/ Share on other sites More sharing options...
jackpf Posted May 15, 2009 Share Posted May 15, 2009 Cron job Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-834620 Share on other sites More sharing options...
nadeemshafi9 Posted May 15, 2009 Share Posted May 15, 2009 cronjob - good option ajax - ok option gives you direct controle throgh a browser process - dosent need to be cronned will run as a demon this can be done in the cronjob or started manualy to run forver will be good on saving resources create a file call it resourcesadd.php then sudo php resourcesadd.php in cmd execute it on the server and then just leave it running while(1){ sleep((1000*60)); //add resources } you can use a web site page to start and kiill this process or start and kill a cron job Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-834624 Share on other sites More sharing options...
MiCR0 Posted May 15, 2009 Share Posted May 15, 2009 nah best way to do that is the following on every user. Time of last update get Time Now, work out how many mins have passed from last update. If greater then 1 min change last update to time now. Give what ever resources * mins passed. Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-834634 Share on other sites More sharing options...
Axeia Posted May 15, 2009 Share Posted May 15, 2009 Both ajax and on page request (basically the same thing) would require at least one player at all times. Even worse on page request you'd need to have one person visiting a page every minute. So yeah, cronjob Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-834648 Share on other sites More sharing options...
nadeemshafi9 Posted May 15, 2009 Share Posted May 15, 2009 Both ajax and on page request (basically the same thing) would require at least one player at all times. Even worse on page request you'd need to have one person visiting a page every minute. So yeah, cronjob i was thinking you could have an admin page that you just leave running on some admins computer with repeated ajax calls to the required script, or he coudl write a demon, cronjob is all good thogh Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-834656 Share on other sites More sharing options...
jackpf Posted May 15, 2009 Share Posted May 15, 2009 But you don't actually need someone to have more gold unless someone is using the game/application or whatever. Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-834662 Share on other sites More sharing options...
Adam Posted May 15, 2009 Share Posted May 15, 2009 Too many potential problems with depending on a user though. I think an automated process is definitely the way to go... Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-834664 Share on other sites More sharing options...
Thauwa Posted May 15, 2009 Author Share Posted May 15, 2009 YEah. Thanks guys for all the help, from what you all said, cron job is my solution. But now I have an idea of what to do. What I really need is to have the an constant income of gold, so that many users would not get fed up of the game, and earn other resources manually. So, cron job, here I come! P.S. Please post of more ideas, I will post back! I think my question was good, for what was on my mind was posted here. Another question. Can a php page be viewed with its codes, and the mysql passwords stolen? Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-834673 Share on other sites More sharing options...
jackpf Posted May 15, 2009 Share Posted May 15, 2009 Only if PHP stops working for some reason. Which I have never heard of. Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-834675 Share on other sites More sharing options...
Adam Posted May 15, 2009 Share Posted May 15, 2009 To avoid any problems like that store sensitive information within a private, non-public folder. Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-834676 Share on other sites More sharing options...
Thauwa Posted May 15, 2009 Author Share Posted May 15, 2009 Well. That's a relief. lol Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-834685 Share on other sites More sharing options...
Thauwa Posted May 16, 2009 Author Share Posted May 16, 2009 And, has anyone an idea on how to put a thing like what is at the bottom of this page? Powered by SMF 2.0 RC1 | SMF © 2006–2009, Simple Machines LLC XHTML RSS WAP2 Even I use SMF, but I have developed my own software (online), and want to put something like that, a one which can't be deleted. Does anyone have any suggestions? ??? Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-835115 Share on other sites More sharing options...
Andy-H Posted May 16, 2009 Share Posted May 16, 2009 I dont think you need a cron job for this, you can simply use mysql / php in a function script included on every page... function addGold($gold, $timer = 60) { $query = "SELECT lastGold, curGold FROM userTable WHERE userField = '" . mysql_real_escape_string($_SESSION['userSess']) . "' LIMIT 1"; $result = musql_query($query)or trigger_error("Mysql Error, could not get userdata gold."); $row = mysql_fetch_row($result); $lastGold = $row[0] - time(); $curGold = $row[1]; $toAdd = 0; while ($lastGold > $timer) { $lastGold -= $timer; $toAdd += $gold; } $curGold += $toAdd; mysql_query("UPDATE userTable SET lastGold = " . time() + $lastGold. ", curGold = " . intVal($curGold) . " WHERE userField = '" . mysql_real_escape_string($_SESSION['userSess']) . "' LIMIT 1")or trigger_error("Mysql Error, Could not add gold."); return $toAdd; } Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-835125 Share on other sites More sharing options...
Thauwa Posted May 16, 2009 Author Share Posted May 16, 2009 thanks. I will try it. Quote Link to comment https://forums.phpfreaks.com/topic/158243-adding-gold-every-minute/#findComment-835168 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.