Results 1 to 6 of 6

Thread: Implement Battle system in PHP

  1. #1
    Join Date
    Jun 2011

    Default Implement Battle system in PHP

    Well, I am trying to make an online RPG on Pokemon, but I am stuck at the Battle system!
    I have seen the formula for the *Damage* on this website, but unable to think of a proper mechanism to implement it!

    If anyone is having any idea about it! please help me out!

  2. #2
    Join Date
    Sep 2009


    Just make a function which does the calculation, and call the calculation wherever it is needed. For the attack power and the stats of the Pokémon, make a parent function which collect these and give them to the calculation function. I might have made that a bit unclear so let me know if you want me to expand a bit more

    Edit: I've decided to expand my answer regardless, seeing as my previous answer was rubbish.

    First, you will want a parent class (We'll call it Stats) which collects the stats that the damage calculation needs. After this, you will need to build a child class (call it Damage) which extends the parent class, gathers each stat which should be saved inside of a variable, and does the calculation. After this, you can create an if statement which checks if a Pokémon has fainted or not by comparing the current HP stat to the damage done (yes, that means you should also collect the receiving Pokémon's HP stat too!).

    There are many other variables to think about, such as how you will want to implement the chances of a status occurring, recoil damage, weather and item buffs... but as long as you have this fundamental working you can build upon it.
    Last edited by Rezzo; 23rd April 2014 at 7:17 AM.

  3. #3
    Join Date
    Jun 2011


    Thats nice! but I have already stored everything in my database!
    Now I just required to somehow make it function!... I am able to understand all the formula and calculation where and when should I do!! But implementing that in PHP is a bit challenging stuff for me! :\

  4. #4
    Join Date
    Oct 2009
    Southern Island


    You should probably make it AJAX based. That's what my game is. Remember that every function you'll need to globalize certain variables, especially if you are using a class for database. Also, I'm going to recommend having mod1, mod2, and mod3 be separate functions so it is easier to read the code.

    If you do make it AJAX based, I can show you an example of the code I use.

    PHP Code:
    function battlemenu()
    $battlemenucontent "<div id=\"battlemenu\"><div class=\"fight\" onclick=\"loadScript('fight&wid=$wid&pid=$pid')\">Fight</div><!--End Fight Div-->
        <div class=\"switch\" onclick=\"loadScript('switchpokemon&wid=
    $wid&inbattle=1&pid=$pid&username=$username')\">Switch</div><!--End Switch Div-->
        <div class=\"item\" onclick=\"loadScript('item&wid=
    $wid&inbattle=1&pid=$pid')\">Items</div><!--End Items div-->
        <div class='run'><a href='?location=
    $location&x=$x&y=$y&id=$id&unique=$hash&run=1&inbattle=1&wid=$wid'>Run Away</a></div><!--End Run Div-->";
    $plugincontent $plugins->execute_code("battle_menu""menu""end");
    $battlemenucontent $plugincontent "</div><!--End Battle Menu Div-->";

    loadScript is my javascript function that makes AJAX requests. The first parameter is what function on the AJAX page it should call. The reason you'll see wid=$wid and pid=$pid is because otherwise it will lose that data which results in the page breaking.
    Last edited by Playful Latios; 23rd April 2014 at 5:54 PM.
    2015-2017: VGC Premier Challenge Organizer / Midseason Showdown Organizer
    Super Mario Maker Profile: https://supermariomakerbookmark.nint...ile/KINGARCEUS
    Showdown: Playful Latios

  5. #5
    Join Date
    Apr 2014


    I have some extra scripts from when I was creating mine, I can send them via email if you would like them.

  6. #6
    Join Date
    Jun 2011


    Actually my game till now is PHP based! coz m not use to AJAX properly... But surely I understand it requirement and would work on it!
    I would need it for LIVE Battle System!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts