Jump to content
MakeWebGames

Recommended Posts

Posted

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.

Posted

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 :)

Posted

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.

Posted

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 :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...