Jump to content

Advanced Coding Help Needed: Update System for Game


Hiro

Recommended Posts

This is a bit long so bear with me please.

 

I've been trying to figure this out on my own but it's pretty much a big mess. I need to code an online text based game, which requires a daily update to the database of users. I've already set up the database and stats, but now I need an update system.

 

I'll need 2 things: A user CP where users can select "actions" for their character, and an admin CP where I can run an "update" script with a push of a button.

 

The control panels are both ready, but now I need the scripts. For this game, each player can select "actions" for their character that will edit their stats daily according to the actions.

 

For example, player 1's stats in the database are as follows:

 

HP: 500/1000

Strength: 100

Speed: 100

Defense: 100

 

For his 3 actions, he selects "Training", "Learning how to swim (5)" and "Resting".

 

Training will increase each stat by 5% per day, Learning a skill will take 5 days, and he will automatically have the skill added to his profile once it's complete, and Resting will restore his HP by 20% of the maximum value each day.

 

I'm not quite sure how to get started with this. Should I make a table in the database with all possible actions first? If anyone can guide in the right direction, I will appreciate it greatly.

Thanks for the reply, but sorry I'm still new to PHP. Could you elaborate on what a cron is? Also, do you have any advice on how to set up the update script in the first place? Automatically updating it isn't the problem, it's the process of setting up the user pages and making them ready to update.

Thanks for the reply, but sorry I'm still new to PHP. Could you elaborate on what a cron is? Also, do you have any advice on how to set up the update script in the first place? Automatically updating it isn't the problem, it's the process of setting up the user pages and making them ready to update.

CRON jobs is a way to automatically run a script every X about of time. Check to see if your host has CRON jobs, if not there are some external CRON programs (try googling ezcron-lite) which do it for you simply by telling it how often to run a script, and it's location.

I would suggest you creating a row in users table authorization. Then retrieve his stats from mysql and use check.

if($authorization==1)
{
print '<a href="actions.php">Admin CP</a>';
}
else
{
print '<a href="actions.php">Actions</a>';
}

 

I am not sure why you need that update stuff. You can do everything with the help of mktime. When a player is learning a skill, update the users table set learning=1, skill=swim, time=$time

But firstly add this

$time=mktime(date("H"),date("i"),date("s"),date("m"),date("d")+5,date("Y"));

Then add a check somewhere, if five days have already passed, but firsly, of course, retrieve his stats from the database.

$date=mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
if($learning==1)
{
if($usertime<$date)
{
mysql_query("UPDATE users set learning='0' where id='...'")
}
}

It's not that hard, jus keep learning and trying.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.