Blade Maker Posted April 25, 2011 Posted April 25, 2011 Well I wanted to know how you guys think the best way to use timestamps are. EX: You give the user a certain amount of time and you want it to display hours and or mins left until they lose. Any tutorials you recommend, timestamps are my week spot and I have been wanting to know how you guys would use them, thanks. Quote
Curt Posted April 25, 2011 Posted April 25, 2011 Hey, Timestamps can be used for a variety of things. They can be used in place of cron jobs to update the users every 5 minutes/hour/day. Here is an example of a use for timestamps: You want to allow players to be able to mug someone once every 15 seconds. First you would need to set the current time: $TIME=timestamp(); Next you update the users table with this time: $db->query("UPDATE users SET mug_time=($TIME+15) WHERE userid=$userid"); Next you make an if command to check if the current time is more than the time you set in the database: $TIME=timestamp(); if ($TIME>$ir['mug_time']) { // 15 SECONDS HAVE PASSED echo " YOU CAN MUG AGAIN !"; } else { // 15 SECONDS HAVE NOT PASSED echo "You cannot mug right now !"; } If the timestamp is greater that means 15 seconds have passed and the player is able to mug someone again. Hope that helps you a little...im not the best at explaining things but i tried to be as simple as possible :) Quote
Blade Maker Posted April 25, 2011 Author Posted April 25, 2011 Thanks I kinda knew you to do that already but it helped :) Umm say I wanted to display like "You have to wait 1 hour and x minutes longer" or just "you need to wait 1:15 longer" I can only make it display the things in seconds, does it do that in timestamps, because before I always used time();, small example of that would work. Also last question, what would mug_time be set to as a row, int? timestamp? time? thanks Curt. Quote
Dominion Posted April 25, 2011 Posted April 25, 2011 Well... there is this http://makewebgames.io/content.php/118-Timestamps-Tutorial As for when they are used you can use them to give out an initial time, then javascript counts down from that. Just one example since you said something about a countdown. Quote
Blade Maker Posted April 25, 2011 Author Posted April 25, 2011 Thanks dominion I will check that out. Quote
Curt Posted April 26, 2011 Posted April 26, 2011 lol...my mistake about timestamp()....you can use either time() or unix_timestamp()...both do the same i believe... to display how much longer they must have you could use some javascript or php.. something like : $TIME=time(); $TIMELEFT=$r['time_stamp_here']-$TIME; Now the $TIMELEFT will equal how many seconds are left before the time is up. Now to display how long do something like this : $TIMELEFT=$BTIMELEFT; if ($TIMELEFT>60) { $TIMELEFT/=60; $TIMELEFT=abs((int)$TIMELEFT); $STIMELEFT=$BTIMELEFT-($TIMELEFT*60); echo "$TIMELEFT Minutes and $STIMELEFT Seconds left !"; } else { echo "$TIMELEFT Seconds left !"; } Thats how I would do it... hope that helps you out :) 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.