interpim Posted March 4, 2007 Share Posted March 4, 2007 I am in the process of teaching myself PHP and have used this site to do some of my learning. I was inspired by the MMORPG contest, and I know it is over now, but have been attempting to build a fairly simple one for my first project to learn with. I want to prevent users from spamming the attack script to bump up their stats/level so my plan was to implement a limit on how many turns they could use per hour. The thing is, Say I want to give 1 turn every 10 minutes, or 6 turns an hour... If the user isn't online I still want to increment their turn count up while they are offline. This I have seen on some other websites, but I honestly don't have a clue where to start on this. I know basics, but am still learning, so if anyone could explain the process behind this it would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/41057-incrementing-a-variable-every-hour/ Share on other sites More sharing options...
sspoke Posted March 4, 2007 Share Posted March 4, 2007 if you are making a rpg with php you would use something for storage like txt based or SQL u can store the time of last attack and just check in php script if time is close etc. Link to comment https://forums.phpfreaks.com/topic/41057-incrementing-a-variable-every-hour/#findComment-198853 Share on other sites More sharing options...
interpim Posted March 4, 2007 Author Share Posted March 4, 2007 Im just curious if that would work... for instance... on account creation, I want to give each player 20 turns... so $turns=20; now, for every hour on the hour, I want to add 6 turns. Do i need to add a time since last turn field to my database? (Using mysql btw) the time() function in php really confuses me LOL. I have tried working with it before, but I usually mess it up especially when trying to do math with the returned value. are you saying, when a user loads the page, i should check $turns and time since last turn? then find the difference between current time and that time to add however many turns they should get? Could you also point me in the direction of a good tutorial on date/time functions in PHP? Link to comment https://forums.phpfreaks.com/topic/41057-incrementing-a-variable-every-hour/#findComment-198858 Share on other sites More sharing options...
sspoke Posted March 4, 2007 Share Posted March 4, 2007 well you make a function like function CheckTurns($playerID){ //sql stuff //get sql last turn time //do some sql math formula to check if the time is way too old to calulate how much turns to add not really that much of a math person if($dunno) return False; return True; } and everytime the player refreshes the page it would check turns.. ya ermm time is really confusing Link to comment https://forums.phpfreaks.com/topic/41057-incrementing-a-variable-every-hour/#findComment-198860 Share on other sites More sharing options...
sspoke Posted March 4, 2007 Share Posted March 4, 2007 actually time is extremely easy its just a unix timestamp which started in 1970 from 1 and every second it goes by 1 number so $total = sql timestamp - time(); would give how much seconds past last turn than u add a checker if its less than 60 so its only seconds if more than 60 than its a minute + etc.. u just do like $total > 5000 or something add to SQL $turns++; or something. u figure out the best number of seconds.. http://us2.php.net/time has some nice functions people posted in comments which fits what you want to do like this one <?php function ago($timestamp){ $difference = time() - $timestamp; if($difference < 60) return $difference." seconds ago"; else{ $difference = round($difference / 60); if($difference < 60) return $difference." minutes ago"; else{ $difference = round($difference / 60); if($difference < 24) return $difference." hours ago"; else{ $difference = round($difference / 24); if($difference < 7) return $difference." days ago"; else{ $difference = round($difference / 7); return $difference." weeks ago"; } } } } } ?> Link to comment https://forums.phpfreaks.com/topic/41057-incrementing-a-variable-every-hour/#findComment-198862 Share on other sites More sharing options...
interpim Posted March 4, 2007 Author Share Posted March 4, 2007 cool... thank you for the link and info Link to comment https://forums.phpfreaks.com/topic/41057-incrementing-a-variable-every-hour/#findComment-198968 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.