Hey.
I am trying to create a turn-based rpg game.
I want to plan out how I will keep scores, turn actions, and rankings...
First of all, I need to do alot of calculations to get the score for a player. And the rankings are based on the score of the player.
What way can I keep the scoring and ranking database design in an organized structure? I think that if the rankings are generated everytime a person browses the rankings page.... it would take too long and overload the server. I am thinking about keeping the ranking in a seperate table then the player_accounts table which I am keeping the variables that I need to use to calculate the score. I could set a cronjob to calculate the rankings of the players every 10 minutes and change the rankings table. That way when a person browses the rankings; the page is only retrieving one field from the database (rankings table).
I have never created a game before in PHP... so I am new to all this. Please bear with me lol.
Also.. I have realized that I have been using alot of nested if statements in the coding; what would be the best way to solve this problem? I do not mind them... but its just that I have heard they can slow down the performance of the application.
I welcome any advise anybody can give me about how to structure the database for a turnbased rpg game. How should I manage the turns? Any suggestions would be greatly appreciated!
Does anybody know of any good articles or tutorials about basic RPG/Turn Based php coding?

Thanks in advanced!

    You need to complete the high level design of the game, decide how it will work.

    Personally I think web games work best using a "tick-based" system which is similar to turn-based, but the players don't have individual turns, rather everything happens during a "tick" which affects all players.

    You could run it from "cron", but if running every ten minutes, be VERY SURE that it has completed its previous run before starting the next one (consider using a file lock or other mutual exclusion mechanism to ensure it doesn't run multiple copies).

    Your turn processor will probably take quite a while to run once you have a moderate number of players. You will want to ensure that the web interface is unavailable (or gives players a "please wait" message) while it's running.

    There are a lot of fairness / cheating considerations to build in. In my opinion, players shouldn't have a significant advantage by continually hitting reload on some page - it will kill your server anyway if many do so.

    You need to ensure that regardless of when during a tick (be it 10 minutes or 2 hours etc) a player hits the site, they have no advantage or disadvantage (other than having more time before the next tick to think about their game plan).

    That way you give nobody any incentive to sit there hitting refresh waiting for the next tick.

    Mark

      drag0n wrote:

      Hey.
      I have never created a game before in PHP... so I am new to all this. Please bear with me lol.

      It is fairly difficult, but if you have written a significant-sized non-game site, and made a game in another language, you are probably ready.

      Mark

        Thanks for the great advise Mark!
        So... you are basically saying that while the turn processor script is being ran... i should halt all activity on the website?
        Like I tried out some turb-based rpg games online and I see that most of them deduct/add turns on the fly. EX: www.pimpwar.com
        On that site... once you perform an action... the turns will be deducted instantly. Turns are added instantly every 30 minutes as well. You are able to do anything you want 24/7 no waiting. They have alot of players as well... so how did they do that?

        Thanks

          Also. WHat about the ranking system? How should that be done?

            You could average all their stats and base their total rank on that basis. There's many ways to do it and it's your decision.

            I tried to make a game like this once, I think you can find my old posts about it. I failed 😛

              drag0n wrote:

              Thanks for the great advise Mark!
              So... you are basically saying that while the turn processor script is being ran... i should halt all activity on the website?

              Not necessarily all activity, but stop people doing any modifications to their next turn. There are potential race conditions that you don't want to have to think about if people change their plans half way through a tick,

              Like I tried out some turb-based rpg games online and I see that most of them deduct/add turns on the fly. EX: www.pimpwar.com
              On that site... once you perform an action... the turns will be deducted instantly. Turns are added instantly every 30 minutes as well. You are able to do anything you want 24/7 no waiting. They have alot of players as well... so how did they do that?

              Personally I think that sort of system is flawed because things happen instantly when people press the button - to be totally fair, everything happens only during turn processing, and nothing happens in between (they can see stats and plan the next turn though).

              Mark

                Mark:
                So from what I understand... the actions each player takes are not realized until the "tick" processes? Basically... each player performs actions... but these actions are going to be stored temporary somewhere and when the tick process happens... the actions are realized and the temporary is deleted. Am I way off or am I close to what you mean?
                Popcorn:
                In what ways did you fail?

                  drag0n wrote:

                  Mark:
                  So from what I understand... the actions each player takes are not realized until the "tick" processes?

                  Yes. That's exactly what I'm suggesting.

                  Basically... each player performs actions... but these actions are going to be stored temporary somewhere and when the tick process happens... the actions are realized and the temporary is deleted. Am I way off or am I close to what you mean?

                  Pretty much spot on.

                  I had a table which was effectively an "orders" table which is scanned by the tick processor to work out what to do. It assigns my characters to teams who carry out the various orders, then based on what happens, allocates resource usage etc, and computes new resource levels. This is done concurrently for all players (I had about seven phases in the turn processing, each of which happened for all players in turn effectively).

                  What

                    Write a Reply...