A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: How in the world do I keep track of everything in an RPG with PHP?

  1. #1
    Senior Member
    Join Date
    Jul 2008
    Posts
    391

    How in the world do I keep track of everything in an RPG with PHP?

    If I were to make an RPG in Flash (with like inventory and warehouses and weapons and stuff), how the heck do I put all that information in a database? Like the character's name, level, HP, MP, what he is wearing, the position of each item in his inventory, all that fun stuff.

    PHP is the only server language I know currently and the only database I've ever made with that is a user account database with 4 fields. For an RPG... I would need like... more than 30 fields.

    Yeah this is gonna be a fun summer project.

  2. #2
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    You'll need different tables for users and weapons and for a user's inventory. Basically any time you have a many-to-one relationship between two data concepts (e.g., weapons to users) then you'll need to create a new table. in that case, i would create USERS, WEAPONS, and USERS_TO_WEAPONS or something like that.

    USERS_TO_WEAPONS would just have a user_id, a weapon_id, and maybe a sequence number to determine what the ordering is.

    And then you'll need to learn how to query and join these tables together to get the info you want.
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    Yeah that's sort of what I did so far. I have a table that has all the character stats like class, hp, the stats, stuff you'll see if you open the character stats window in a game. I'm planning on adding an inventory table that has a username field and a field for each of the inventory spots, so 10 fields if my inventory size is 10.

    For the values in the inventory fields, if I set the values as the names of the items in there, like the first slot is a value of "LeatherArmor", I could send that back to Flash and check that value with a variable that already has all the stats of that item defined. This is all I have thought up for how that would work right now.

  4. #4
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    it's probably not a good idea to create a table for inventory with 10 spots. What if you increase this amount to 15? Then you'll need to change your table definition (and you queries are going to be pretty damn ugly).

    You should also give each item an integer id. For instance,"Leather Armor" would be id #17.

    Then create a USER_INVENTORY table which connects the numeric id for a user to the numeric id for an item. This is called 'normalization' and is how experienced database writers do it.
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

  5. #5
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    Could you give an example? I've never dealt with anything like this before.

  6. #6
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    users:
    user_id
    user_name
    user_money
    user_health
    user_strength
    user_etc

    weapon:
    weapon_id
    weapon_name
    weapon_damage_low
    weapon_damage_high
    weapon_etc

    weapon_to_user:
    weapon_id
    user_id
    sort_order

    To get the weapons belonging to a user with user_id of 6:
    Code:
    SELECT w.*
    FROM weapon_to_user w2u, weapon w
    WHERE
      w.weapon_id = w2u.weapon_id
      AND w2u.user_id = 6
    ORDER BY w2u.sort_order
    EDIT: spacing got lost so i used bold formatting.

    Also, Unlike what I've done here, one should try to consistently name tables either plural or singular.
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

  7. #7
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    My CharacterStats table is similar to the users table you have. I believe the weapon table contains the stats for all the different weapons I'll have in the game?

    But I don't quite understand how the weapon_to_user table works. Your syntax is a bit confusing to me and it seems like it selects all the fields in the weapon table from the weapon_to_user table and the weapon table? That doesn't make much sense to me, and where does the value for weapon_id and user_id come from in the weapon_to_user table?

  8. #8
    Programmer
    Join Date
    Aug 2007
    Posts
    173
    hello , i have created a method of what i would do to achieve what you trying to do ...

    All items would be stored in its own table so eg.. 'rpg_items'

    each item created in the world will have its own id along with its own stats.

    table 'rpg_items' may contain such fields as 'id' , 'lvl' , 'type'.. ect

    e.g


    id: 8292 | lvl: 50| type: weapon | item_name: sword-of-a-thousand-truths | stats: stabina/80***health/200|
    id: 8293 | lvl: 1| type: resource | item_name: brown-bread | stats: health/20|



    --

    All clients would be stored in their own table so eg.. 'rpg_client'

    each client created in the world will have there own row of fields

    eg.

    user: huntysin | pass: AHJKHIUJH76786KJHSJH|items_on: 2342,5454,23,34255,53|inventory: 232,233,5,3,4,235,2323,43,5,36,6,3,45,346,3,46,3,4 6,346|


    ----


    so when flash wants to request the inventory, all you do is send your inventory array (witch contains all of the item id's) to a php script that searches each id in the array and parses the information into something that flash can read.

    e.g echoing something looking like this.

    &item0=8292,50,weapon, sword-of-a-thousand-truths, stabina/80***health/200&
    &item1=8293,1,resource,brown-bread, health/20&


    witch will then be parsed with your own flash functions to put the data into use.

    ---

    hope this all makes sense and helps.
    Freelance: AS2, AS3, PHP, MySQL, JavaScript
    Skype: hunty93

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center