Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Inventory system for text based rpg/mud  (Read 8749 times)

0 Members and 2 Guests are viewing this topic.

snaef98

  • Newbie
  • *
  • Posts: 14
    • View Profile
Inventory system for text based rpg/mud
« on: May 24, 2011, 11:51:04 am »
I have a question is there an easier way to manage inventory/bank and equiping/transfering items then using massive ammounts of variables / bools to keep track of stuff? I'm only at a moderate level of knowledge with C++ ive yet to learn arrays and classes and stuff like that. Could someone show me some code examples? Thanks

I would need to seperate things like:

Is the item stackable?
Loot buffer.
Quest Items.
Player bag inventory.
Bank vault.
Equipment slots.


Like an example

Item 1
Short Sword
Description
Atk +5
Gold Value: 50
Equipment Slot: Weapon
Stackable: No

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Inventory system for text based rpg/mud
« Reply #1 on: May 25, 2011, 06:06:28 am »
You NEED to learn arrays and classes and stuff like that before you try and make any somewhat serious level of game. Also, RPGs are usually considered one of the more difficult types of games to create.

You've basically just designed a class yourself, although I wouldn't make a whole new class for every slight variation of a sword (Just have one or a few key variations and then set up instances of them differently).

If you go and learn more of C++ and programming in general, what you want to do will become much clearer.  :)

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Inventory system for text based rpg/mud
« Reply #2 on: May 25, 2011, 06:37:39 am »
Quote
Also, RPGs are usually considered one of the more difficult types of games to create.


By who?

Minimal collision detection and physics = one of the easier types of games in my book.

snaef98

  • Newbie
  • *
  • Posts: 14
    • View Profile
Inventory system for text based rpg/mud
« Reply #3 on: May 25, 2011, 10:25:42 am »
Well im accually planning to work on a mud style without graphics just text and sound and puzzles with a simple combat system for now. I already have most of the engine done including inventory and other stuff but i revising it with wav files for the music using playsound instead of midi because the preload for a file with increased length due to the inability to loop was a pain... secondly coding the entire inventoy required a huge ammount of nested if/else just for inventory swaping... the global variables will be needed for the save file which is just a simple text file. What i need is a sample code on how to do classes/arrays specifically in the manner used for inventory/bank/equipment management.


Also for all the menu options for different text stuff is there an easier way to manage the dialog then lots of switch's or if/else? id rather not have to have tons of nested switch's or if/else for all the dialog if possible. im trying to clean up my code and reduce the coding needed. The old style engine i designed required about 18,000 lines of code most of which was just inventory swaping not even counting the bank which was missing atm

snaef98

  • Newbie
  • *
  • Posts: 14
    • View Profile
Inventory system for text based rpg/mud
« Reply #4 on: May 25, 2011, 10:39:39 am »
Would this be correct? What else is missing? It won't let me store bool values or strings inside the class though.



Code: [Select]
class CopperSword
{
public:
                string Equip001 = "Copper_Sword";
string Equip001Title = "A_Short_Sword_Made_Of_Copper";
int Equip001Atk = 2;
int Equip001Price = 50;
int Equip001Slot = 1;
bool Equip001Stack = false;
};

PhiLLe

  • Newbie
  • *
  • Posts: 36
    • View Profile
Inventory system for text based rpg/mud
« Reply #5 on: May 25, 2011, 02:15:40 pm »
Quote from: "snaef98"
Would this be correct? What else is missing? It won't let me store bool values or strings inside the class though.


No! You really need to read the chapter about classes of your C++ book again (if you have one).

This is what I can tell you:
A class holds all information of a kind of object. In your case it holds a name, price, etc. So it's kind of a list of variables in your case, but a class can also contain functions. It should look more like this:

Code: [Select]
class Item
{
public:
   Item(string equip, string title, int atk, int price, int slot, bool stack);
   string GetEquip();
   string GetEquipTitle();
   int GetEquipAtk();
   // ...
private:
   string Equip;
   string EquipTitle;
   int EquipAtk;
   int EquipPrice;
   int EquipSlot;
   bool EquipStack;
};


You need to define all the functions. The Item() function is the constructor of the class. In your case it should set all the values of the member variables.

All (not always but almost) member variables should be private. That has some reasons:
- It's saver. You can not change the data by accident.
- You can easily change the Get functions without changing your whole other program. You could even change the type of the internal variable without showing it to the program.

Then you can do this in your main program:
Code: [Select]
Item sword("Sword", "Sword_Title", 20, 30, 1, false)
//...
cout << sword.GetEquipAtk() << endl;

btw: I don't know what you want to do with stack.

For an array (list) of items you should use vectors.

Edit: sry not done with that post. just a minute..
Edit2: done :)

snaef98

  • Newbie
  • *
  • Posts: 14
    • View Profile
Inventory system for text based rpg/mud
« Reply #6 on: May 25, 2011, 05:02:31 pm »
yeah i kind of figured out a portion of it, this was just a test


Code: [Select]
class RustyBuckler
{
public:
static const int DataBaseID = 9;
static const int ItemType = 2;
static const int Atk = 0;
static const int Def = 2;
static const int GoldValue = 50;
static const int Stack = 1;
static const int MaxStack = 1;
};



obviously im missing the portion you put in. Can you rework it with that info? basically though i need to access different portions for stuff the inventory i have to accually take the variable of 1 inventory slot and make it take on the values of the item im transfering. Another thing i have is a database for monsters too but really anything that is temporary can just be run as a temp variable in its own function. Anything thats saved needs to be in global variable format 1 line at a time for saving / loading purposes.

Inventory Management consists of


Equipment Slots 1-7
Weapon
Shield
Helm
Gloves
Body
Pants
Boots

Inventory Slots ( 10 Of Them)
Quest Item Slots (5 Of Them)
Loot Buffer Slots (5 of them) (Temporary Loot Droped Goes Here)


Bank (Undecided number could be as high as 50 or 100 slots)


DatabaseID is item number in database
ItemType will either be 1-7 Equipment 8 for quest 9 for loot buffer 10 for general inventory.



For stacks it would be like an item thats stackable..... like say Fish Eyes or Arrows or some other item you that can stack up to 50 or 10 or 99 or whatever the setting is.. because if you swap items or combine stacks you would need to chec to see if

Is it stackable?
If it is, is it the same item,
If it is, does the location you moving to have room,
If so can you fit all items.
If not how many. xfer variable data and make modifications as needed.

snaef98

  • Newbie
  • *
  • Posts: 14
    • View Profile
Inventory system for text based rpg/mud
« Reply #7 on: May 25, 2011, 05:22:59 pm »
Another good question is how will Classes effect my global variables and my saves? Because i save all my variables 1 per line in as specific order to text file for reload later. And i should correct myself i did use 1 array awhile ago for exp to next level for my ExperienceCalculator() function after each fight it checks if character needs to level and handles all the stats. ill show you a sample of the code.


Code: [Select]
int ExperienceCalculator()
{
HANDLE hConsole; // Code for colored text
hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Code for colored text
// Array that stores the exp needed for each level
const int NextExperienceLevels[] = {0, 100, 225, 400, 925, 1400, 2425, 3650, 5675, 8150};
// LEVEL CHART GUIDE - Exp for each level
// Level 1 = 0
// Level 2 = 100
// Level 3 = 225
// Level 4 = 400
// Level 5 = 925
// Level 6 = 1400
// Level 7 = 2425
// Level 8 = 3650
// Level 9 = 5675
// Level 10 = 8150

// LEVEL CHART GUIDE - Total Exp at each level
// Level 1 = 0
// Level 2 = 100
// Level 3 = 325
// Level 4 = 725
// Level 5 = 1650
// Level 6 = 3025
// Level 7 = 5475
// Level 8 = 7900
// Level 9 = 11550
// Level 10 = 19700
// Variable that stores new hit points value for next level (Base 20 + 5 per level)
const int PlayerHitPointsUp = 5;
// Variable that stores new magic points value for next level (Base 10 + 3 per level)
const int PlayerMagicPointsUp = 3;
// Variable that store new attack value for next level (Base 6 + 2 per level)
const int PlayerAttackUp = 2;

// Variable that store new defense value for next level (Base 3 + 3 per level)
const int PlayerDefenseUp = 3;

// Variable that stores new hitrate value for next level (Base 50% + 1% per level)
const int PlayerHitRateUp = 1;
    {
SetConsoleTextAttribute(hConsole, 15); // Colored Text White
}
cout << "\n[";
{
SetConsoleTextAttribute(hConsole, 12); // Colored Text Red
}
cout << " SYSTEM MESSAGE: ";
{
SetConsoleTextAttribute(hConsole, 15); // Colored Text White
}
cout << "Experience Calculator ]\n";
cout << "\nChecking players level & experience stats.\n";
do
{
if (PlayerExperience >= PlayerNextExperience)
{
cout << "Leveling up player.\n";
if (PlayerLevel < PlayerMaxLevel) PlayerNextExperience = NextExperienceLevels[PlayerLevel+1];
++PlayerLevel;
PlayerHitPoints = PlayerHitPoints + PlayerHitPointsUp;
PlayerMaxHitPoints = PlayerLevel * 5 + 15;
PlayerMagicPoints = PlayerMagicPoints + PlayerMagicPointsUp;
PlayerMaxMagicPoints = PlayerLevel * 3 + 10;
PlayerAttack = PlayerAttack + PlayerAttackUp;
PlayerDefense = PlayerDefense + PlayerDefenseUp;
PlayerHitRate = PlayerHitRate + PlayerHitRateUp;
}
else
{
cout << "\nPlayer does not need to be leveled up.\n";
cout << "Returning to game...\n\n";
}
} while ( PlayerExperience >= PlayerNextExperience);
return 0;
}

snaef98

  • Newbie
  • *
  • Posts: 14
    • View Profile
Inventory system for text based rpg/mud
« Reply #8 on: May 25, 2011, 06:24:56 pm »
ok i tried to re-do what you did and its giving me a couple errors.

Code: [Select]
class CopperSword
{
public:
CopperSword(string CopperSword, string CopperSwordDesc, int DatabaseID, int ItemType, int Attack, int Defense, int GoldValue, int Stack, int MaxStack, bool Stackable);
string GetCopperSword();
string GetCopperSwordDesc();
int GetDatabaseID();
int GetItemType();
int GetAttack();
int GetDefense();
int GetGoldVale();
int GetStack();
int GetMaxStack();
bool GetStackable();
private:
string CopperSword;
string CopperSwordDesc;
int DatabaseID;
int ItemType;
int Attack;
int Defense;
int GoldValue;
int Stack;
int MaxStack;
bool Stackable;
};




 error C2380: type(s) preceding 'CopperSword' (constructor with return  error C2208: 'CopperSword' : no members defined using this type

AdventWolf

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Inventory system for text based rpg/mud
« Reply #9 on: May 25, 2011, 07:56:19 pm »
Instead of making a class for a specific item, you should make a broad "Item" class that you can create your items under.

I think the problem you might have is that you are trying to create a string by the name of your class in the private declaration. Also do you have your class functions coded?

Code: [Select]

class Item
{
public:
   Item();
   Item(string Name, string ItemDesc, int DatabaseID, int ItemType, int Attack, int Defense, int GoldValue, int Stack, int MaxStack, bool Stackable);
   string GetItem() {return Name;}
   string GetItemDesc() {return ItemDesc;}
   int GetDatabaseID() {return DatabaseID;}
   int GetItemType() {return ItemType;}
   int GetAttack() {return Attack;}
   int GetDefense() {return Defense;}
   int GetGoldVale() {return GoldValue;}
   int GetStack() {return Stack;}
   int GetMaxStack() {return MaxStack;}
   bool GetStackable() {return Stackable;}
private:  
   string Name;
   string ItemDesc;
   int DatabaseID;
   int ItemType;
   int Attack;
   int Defense;
   int GoldValue;
   int Stack;
   int MaxStack;
   bool Stackable;
};


Then you could implement it by:

Code: [Select]
Item CopperSword("Copper Sword","Desc",1,1,1,1,1,1,1,false);

snaef98

  • Newbie
  • *
  • Posts: 14
    • View Profile
Inventory system for text based rpg/mud
« Reply #10 on: May 25, 2011, 11:07:11 pm »
Hmmm you may be on to something there... depends on what you think im trying to use it for... my problem is right now im trying to organize my items into 1 database, and the monsters into another... thats relatively simple if done with just variables and strins 8-10 per item each commented in a specifc function  that manages them temporarily. My problem is managing my Global Variables that are tied to switching the information from storage unit to storage unit... for example


Moving items from inventory slot to inventory or from inventory to equipment or equipment to inventory or from the loot buffer to inventory, quest slots etc... it takes a ton of nested statements to do it, is there an easier way to manage them and still be able to load individual variables to the save files 1 line at a time for simple reloading upon loading the saved game.