Hiro Posted June 21, 2009 Share Posted June 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163094-advanced-coding-help-needed-update-system-for-game/ Share on other sites More sharing options...
Hiro Posted June 23, 2009 Author Share Posted June 23, 2009 I've set up the actions in a table too, but still don't know where to go from here. Any advice/words of wisdom? Quote Link to comment https://forums.phpfreaks.com/topic/163094-advanced-coding-help-needed-update-system-for-game/#findComment-861757 Share on other sites More sharing options...
MasterACE14 Posted June 23, 2009 Share Posted June 23, 2009 use a cron to automatically run your script once a day. Quote Link to comment https://forums.phpfreaks.com/topic/163094-advanced-coding-help-needed-update-system-for-game/#findComment-861794 Share on other sites More sharing options...
Hiro Posted June 24, 2009 Author Share Posted June 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163094-advanced-coding-help-needed-update-system-for-game/#findComment-862471 Share on other sites More sharing options...
Alex Posted June 24, 2009 Share Posted June 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163094-advanced-coding-help-needed-update-system-for-game/#findComment-862472 Share on other sites More sharing options...
n3ziniuka5 Posted June 24, 2009 Share Posted June 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163094-advanced-coding-help-needed-update-system-for-game/#findComment-862474 Share on other sites More sharing options...
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.