[REQ]implementing time in stats

Post all your tuts or request for tuts here.
Post Reply
Sebastian
Posts: 31
Joined: Sun Dec 11, 2011 8:21 pm

[REQ]implementing time in stats

Post by Sebastian »

Hi Lads
This is my first post here so at the begging i want so say that you are doing a great job! :)
Since i remember ive always wanted to make games, but life went the other way :) Ive been watching tuts about making Browser-Based MMORPG lately and learning PHP almost from scratch. I am trying to build this general image of the game i want to make and make sure i got all "php" parts covered but there is a lot to ask about ;P
Well, mainly i want to ask how to implement time-flow i the game. What i mean:
I want to use something like "stamina" and every action you want to make (attack or training) would use stamina points. You could refresh stam with a potions, but that was covered. But i want stam to refresh by itself lets say 1 point every 3min and i not so sure how to do that.
Could some1 throw me an idea for that, and maybe some small counter :)
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: [REQ]implementing time in stats

Post by Jackolantern »

Check out Halls' tutorial video on crons, a Linux feature that allows you to set up specific scripts to run at certain time intervals. You could just set the script to add 1 to everyone's stamina every 3 minutes, but make sure you don't put them past their maximum.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: [REQ]implementing time in stats

Post by hallsofvallhalla »

yep and if you dont have crons available you can go the less sexy route of setting up a time field in the players table that when the player is playing it checks to see if that time is reached. If so it gives stamina and sets the time back to another 30 minutes ahead.

Make sure to give stamina for every 30 minute incriment that happened as well be subtracting current time from stored time then dividing by 30.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: [REQ]implementing time in stats

Post by Jackolantern »

Hey Halls, have you ever thought of making a follow-up to the crons video that would show the major alternative (the "on-view" method)? I know some people either don't like using a completely different method when developing on Windows (Task Scheduler), don't have crons available on their host, or don't like the fact that a major part of their game is being handled by the OS instead of the web server software.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: [REQ]implementing time in stats

Post by hallsofvallhalla »

hmm good idea, I will make it in the next video
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: [REQ]implementing time in stats

Post by Jackolantern »

Awesome :) I bet that will help out a lot of folks. People around here seem wary of crons because you can't test them on Windows the same way they will work on the server.
The indelible lord of tl;dr
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: [REQ]implementing time in stats

Post by Callan S. »

Yeah, I tip toed around crons and developed my own on view method. I think when I feel more confident in future, perhaps on a latter project, I'll go for crons. They don't look hard, but when your starting out just missing a semi colon somewhere makes your code crash and burn, so your afraid of going for any extra layer of unknown complexity.
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: [REQ]implementing time in stats

Post by hallsofvallhalla »

I am working on the videos now. Almost done but mic went out so buying another one.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: [REQ]implementing time in stats

Post by Jackolantern »

hallsofvallhalla wrote:I am working on the videos now. Almost done but mic went out so buying another one.
The universe is conspiring against you. Don't let it win! :)
The indelible lord of tl;dr
User avatar
Ark
Posts: 427
Joined: Wed Jun 01, 2011 10:25 pm

Re: [REQ]implementing time in stats

Post by Ark »

When I grow up I wanna be like halls :roll:
Orgullo Catracho
Post Reply

Return to “Tutorials”