Game Development Your number one stop for anything related to creating games (except ROM hacks). You can even make your own!

Ad Content
Reply
 
Thread Tools
  #1   Link to this post, but load the entire thread.  
Old May 25th, 2018 (4:43 AM).
Geomonlover Geomonlover is offline
     
    Join Date: Apr 2017
    Posts: 15
    So if your wondering the content to this, I have been making a pokemon online rpg, and I am still setting up the database, but while setting up said database, I need help with trying to figure out some things, mostly with catching pokemon and having pokemon in your inventory. I'm gonna have to figure out how to look at pokemon too, but right now I'm more worried of the captured pokemon being linked to the persons account, so they can use it in battles, or for better words, how to have the captured pokemon with the trainer and not just have on screen you captured it and not have the pokemon linked to the account, if that makes sense. same goes for poke balls and items, since they fall under a similar category. do I add something like $link pokemon.png to user0 or die( capture failed) ?
    or am I like getting the idea but I'm not getting the exact code?

    Thank you!
    Reply With Quote
      #2   Link to this post, but load the entire thread.  
    Old May 25th, 2018 (10:54 PM).
    mgriffin's Avatar
    mgriffin mgriffin is offline
     
    Join Date: Apr 2014
    Posts: 252
    There's lots of things you could do here, but one of the more traditional ones is to store the information about players and what they own in your database.

    If you have a table for a player that looks something like this:

    Code:
    CREATE TABLE Player
      ( id INT NOT NULL AUTO_INCREMENT
      , email VARCHAR(40) NOT NULL
      , password_hash VARCHAR(32) NOT NULL -- NOTE: Look into hashing passwords with salt.
      , name VARCHAR(16) NOT NULL
      , PRIMARY KEY (id)
      );
    Then you can associate other data with that player by giving the other data a foreign key into Player.player_id:

    Code:
    CREATE TABLE Pokemon
      ( species INT NOT NULL -- e.g. 1 = Bulbasaur. If you have a different scheme, use that.
      , nickname VARCHAR(16)
      , ... -- Things like level, EVs, moves, etc can go here.
      , owner INT NOT NULL
      , FOREIGN KEY (owner) REFERENCES Player (id)
      );
    To give a player a Pokémon I could execute a query that looks like this (assuming you're using MySQLi in PHP—I'd recommend it, because consistent use of bind_param will save you from SQL injection):
    Code:
    /* Assuming we have $mysqli connected to a database, and $species, $nickname, $player_id set to appropriate values. */
    $stmt = $mysqli->prepare("INSERT INTO Pokemon (species, nickname, owner) VALUES (?, ?, ?)") or die($mysqli->error);
    $stmt->bind_param("i", $species) or die($stmt->error);
    $stmt->bind_param("s", $nickname) or die($stmt->error);
    $stmt->bind_param("i", $owner) or die($stmt->error);
    $stmt->execute() or die($stmt->error);
    And to get the list of Pokémon a player owns you can do this:
    Code:
    $stmt = $mysqli->prepare("SELECT * FROM Pokemon WHERE owner=?") or die($mysqli->error);
    $stmt->bind_param("i", $player_id) or die($stmt->error);
    $stmt->execute() or die($stmt->error);
    $res = $stmt->get_result() or die($stmt->error);
    while ($row = $res->fetch_assoc()) {
      /* Do something with each Pokémon. */
      echo $row["nickname"];
    }
    (I haven't run any of the code, so there could be some errors but hopefully this will point you in a direction!)
    Reply With Quote
      #3   Link to this post, but load the entire thread.  
    Old May 27th, 2018 (7:04 PM).
    Geomonlover Geomonlover is offline
       
      Join Date: Apr 2017
      Posts: 15
      This is super helpful! If there are any bugs in it ill debug them! Thank you so much!
      And ill credit you for the code, this is super helpful! QwQ
      Reply With Quote
      Reply

      Quick Reply

      Join the conversation!

      Create an account to post a reply in this thread, participate in other discussions, and more!

      Create a PokéCommunity Account
      Ad Content
      Thread Tools

      Posting Rules
      You may not post new threads
      You may not post replies
      You may not post attachments
      You may not edit your posts

      BB code is On
      Smilies are On
      [IMG] code is On
      HTML code is Off

      Forum Jump


      All times are GMT -8. The time now is 10:38 PM.