Dezmo Posted February 19, 2014 Share Posted February 19, 2014 Hey im trying to make a small little game for my self at the moment, to test my self a little, the game i creating is based a little on the game http://ogame.org, im trying to find out how i can make the ressources auto increase on each member created on my site as the site ogame has, i dont need the javescript so you can see it auto increase, but just need to refresh it and then i can see that it has gone up, in my game im using Gold, Silver and Copper as ressources atm, and im not sure how to make the number in my database auto increase while the user have logged out, i was thinking about using some kind of function that would increse copper with 1 for each sec there goes with a timestamp or something like that, any of you guys knows how this could be possible? Regards Dan Larsen Quote Link to comment Share on other sites More sharing options...
jairathnem Posted February 19, 2014 Share Posted February 19, 2014 I am not able to get your question. you need to auto-increment for each registered member? if so then declare a primary key and set it to auto-increment in the DB itself. when you insert you dont have to send the primary key valuse the DB will increment it for you. if this is not question - please explain it breifly. Quote Link to comment Share on other sites More sharing options...
Dezmo Posted February 19, 2014 Author Share Posted February 19, 2014 (edited) No its like if you have 1 gold on your account and then make like 1 gold each sec, then when you get back into your account again your gold should be 26 if it was 25 secs ago you last checked your gold. Simply put, the gold factor should raise by 1 for every sec there goes by. Edited February 19, 2014 by Dezmo Quote Link to comment Share on other sites More sharing options...
jairathnem Posted February 19, 2014 Share Posted February 19, 2014 record the time the user logged in and the time the user logged out. get the difference amount in seconds - use strtotime() on both the variables and get the difference. add the resultant value to the DB. Quote Link to comment Share on other sites More sharing options...
Dezmo Posted February 19, 2014 Author Share Posted February 19, 2014 Nice thanks! I will try that, will it work when the user is still online? Or do i have to use another way for that? because it should still update the res when you are online. Quote Link to comment Share on other sites More sharing options...
jairathnem Posted February 20, 2014 Share Posted February 20, 2014 It will work. You have to compare the login time with current time. Quote Link to comment Share on other sites More sharing options...
WebStyles Posted February 20, 2014 Share Posted February 20, 2014 the time() function will return the number of seconds passed since the 1st January 1970. You can take advantage of that to count the seconds in an easy way: // store the time they last checked for gold: $last_gold_check = time(); // get the time when they check again: $current_time = time(); // number of seconds will be final time - initial time:$seconds = $current_time - $last_gold_check; // update the gold count: $availableGold += $seconds; (or just skip the previous command and do it directly with $availableGold = $current_time - $last_gold_check) (dont forget to update the last time gold was checked after this) $last_gold_check = $current_time; This seems like you're creating an incentive for people to keep refreshing the page... if every time they check for new gold it just adds the seconds from last check, you'll get people hitting the refresh button constantly just to see their gold increase. Quote Link to comment 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.