Blade Maker Posted November 12, 2009 Posted November 12, 2009 <?php session_start(); $user = $_SESSION['username']; //open my database $connect = mysql_connect('_______', '___', '____') or die('Couldn\'t connect!'); mysql_select_db('__________'); $query = mysql_query("SELECT * FROM `castle wars users` WHERE username = '$user'"); $username = mysql_fetch_array($query); echo 'Logged user has: '.$username['money'].' money'; //money amount to add for each round $add_money = 1; //time now, and round time in seconds (1h=60*60seconds=3600) $time_now = time(); $round = 3600; //time of last update+time needed must be smaller then time now to update if (($username['lastupdate']+$round) <= $time_now) { //see how many rounds (hours) were there from last update $nr_rounds = floor(($time_now-$username['lastupdate'])/$round); //calculate how much money user gained $all_money = $nr_rounds * $add_money; //calculate how many rounds in seconds (how many hours in seconds) $add_time = $nr_rounds * $round; //lets update users table mysql_query("UPDATE `castle wars users` SET lastupdate=lastupdate+'$add_time', money=money+'$all_money' WHERE id = '$username[id]'") or die(mysql_error()); //here you can refresh page (so you can see progress) or select user again using login } ?> OK now as soon as I log in I get so much money! How can I make so I get 1 dollar every 5 seconds. Quote
a_bertrand Posted November 13, 2009 Posted November 13, 2009 You have basically 2 solutions: 1) You store the last time somebody requested a page (or the last time you gave the money), and if it's over the period you want to give, then you will divide the time by the period, and give X times the money, and store the remaining unused time in the time field. (Not sure I'm really clear here :P) 2) Second solution (and honestly not the smartest one), you use a cron which add money every X min to your players. However this will use CPU and DB even for players inactive. Quote
Zero-Affect Posted November 13, 2009 Posted November 13, 2009 OK now as soon as I log in I get so much money! How can I make so I get 1 dollar every 5 seconds. please tell me your joking, if you updated every active users money every 5 seconds they are online you would use your sites bandwidth in no time. People are obsessed with that mafia wars... Think more of a longer time period with a larger amount of money would seem more logical. (1 * 60) * 15 900 money per 15 minutes seems more logical and less of a strain(i do know he said 1 buck every 5 seconds im just doing a example...) Quote
Blade Maker Posted November 13, 2009 Author Posted November 13, 2009 What is the easiest way to do this, is it possible for a number the increase by one every 1 minute without refreshing the page, preferably in php. Quote
Zero-Affect Posted November 14, 2009 Posted November 14, 2009 anything is possible but cron minute does run every minute anyways so... but best not to do it every minute like i said above 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.