Hi, i am thinking about creating a sort of text based mmorpg game, i have a fair amount of experience in designing and building websites. I see that a lot of text based games use ticks as a sort of time frame for completeing tasks etc... I was wondering if there was an alternative to this, so that the game could constantly be running live, where players didn't have to wait till the end of the tick to complete a task. For example they could the game might involve the player building a house, the system for a tick based game might say your house will be ready in 3 ticks, i want a system where it might say your house will be ready in 3 minutes. Is there anyway to do this? I just need ideas at this stage, so i can continue doing a bit more planning and researching.

Sorry if this is a bit confusing

Thanks

I think you would need to enter either the time the task was started and the time to complete or the calculated end time (as a time stamp) into a database. Then you could read the value whenever you needed to inform the player of the time remaining. I have the need to do this in one of my own projects (which is moving ahead very slowly) but I haven't got around to this part yet so I'll be interested in the responses.

I am inclined to agree. My simple idea would be to have a database back-end as suggested by hericles where you either add two columns to a user's db row or if you have the room for more tables you could even create a table especially for this feature.

But either way there could be a column where you specify what the current action which they are undertaking in this case "Building a house." And then put the timestamp of the time that they started the task. The script can print out the task which they are undertaking and waiting on to be finished. Then you can do the math to compare the current time when the page was loaded with the time that it was started. You should have a database table with actions that can be done and how long each takes. Maybe even a column for text that will be displayed after that specific action has been completed. Actually to simplify things you can have the 'tasks' table have an unique key such as action_id where the ID increments with each task a user can undertake. So that in the first table I mentioned you could put the ID number of the current task and use a join statement to get the message about what they are doing as well as how long it takes to complete the task.

At the top of the script have it compare the time stored in the database that was created when they clicked to start the task with the server's current time to see how much time has elapsed. And if the elapsed time is greater than the amount of time specified in the second table as to how long it takes to complete the task then it can print out the success message, run any database queries that you may want regarding a house being built such as incrementing their house numbers by 1 or whatever you'd need to do to make the task they completed have a result in the game world and then delete the database row for that user involving the task that completed.

Now you can do the math and if not enough time has passed then perhaps try:

header("refresh: 10; url=URL OF THIS SCRIPT");

And if the required amount of time has elapsed then have it run a function you write to delete the task row for that user and whatever else you need done upon successful completion of a task such as if the user earns some experience points or whatever for completing said task.

I haven't personally tested but the timed 'refresh' will hopefully keep reloading the browser if the required amount of time hasn't elapsed. You can also use the time and math to show how much time remains before their task is complete. So the time wouldn't quite be a continuous running time but would be updated every time that there is still time remaining before the task is complete incremented by 10 seconds (or however long you specify) until it has completed.

Once the browser refreshes and the required time has passed it will run the "completion" function. I wouldn't go with too low of a refresh time so that their browser isn't constantly clicking every second as that could annoy them. But you wouldn't want it to go too long either because then they'd have to wait longer than the specified time because the script could refresh with only half the time needed to completion that it takes to refresh so they end up waiting longer.

You should definitely note either in game rules and/or on this page itself that the browser will refresh every "however often you set the refresh for". This will also be good if a user starts a task and either logs off, closes the broswer/tab or leaves for some reason so that the task can still be completed as soon as they come back to the site.

Just my 50 cents haha

wow, that is an amazing thought on how it can be run, i will definately use your ideas of a seperate table to hold the event id and timestamp as well as the refresh brwser idea, thanks so much for the help!

You're quite welcome. If you run into any other problems post in the forums and/or PM me. I'd be glad to help where I can as well as perhaps test what you have going. I'd be interested in getting on board in any capacity depending upon my schedule/availability.

Ok thankyou very much i would definately be interested in getting you to test a few things after i have got the majority of it done. Thanks again.

You're quite welcome. If you feel that you have enough info on the topic then you can mark the thread as solved. But you can leave it "open" if you think someone else can add something else useful!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.