Resident Evil 2'ish Inventory System - Progress Thread

Grab your favourite IDE and tinker with the innards of game engines

Resident Evil 2'ish Inventory System - Progress Thread

Postby Garrador on Wed Dec 18, 2013 12:30 am

Hello!

I'm currently working on a inventory system that is based on the functionality of the one you have in Resident Evil 1/2/3.

Follow in detail here: http://oyvindandersson.net/blog/?p=226

I need somewhere to put out progress and i.e. get feedback/ideas as I go. For now, I'm establishing the fundamentals and I have some key features in:

Completed:
  • Load/parse item-definitions from script file(s) (See below for an example definition)
  • Load inventory-settings from script file (For flexibility while developing. Not decided if I want that in scripts. I do love to edit settings in scripts instead of code, though).
  • Cache all parsed item definitions to data structures for use in a "CBaseInventoryItem" that takes such a definition.
  • Implement utility features for writing item definitions in script files: Inher from a definition, and use a definition as an abstract base-def
  • Enable creation of the actual entities from the data they get from the defintions
  • Tie the system to the player
  • Create specialized item type classes: Usable, Equipable(weapon, etc), KeyItem (TODO: Just parse a value in the definition that specifies this? I.e: canEquip, canUse, etc.)
  • Remove items, that are picked up, from the world.
  • Respawn items that are discarded TO the world (if flagged to allow that. Some items should be gone forever )
  • Implement Add/Remove item in the player's inventory

Next:
  • Add mixing features to items. An item should be able to mix with another if set in the definition (i.e: two small X mixes into one big X, or "attachment A can be mixed with item B to get item C")
  • Create entity for hammer that initializes and manages the inventory items you spawn with.
  • Carry inventory across level-sessions (So you don't lose the items you have when a new level loads)

Features TODO:
  • - Add feature to sort the items according to how it is sorted in the UI.
  • - VGUI part of the inventory (Client)
    • 1. Mouse-enabled panel for selection
    • 2. Dynamically create inventory slots
    • 3. Add manual sorting feature
    • 4. Pop-up panel for item selection choices (equip, use, examine, discard etc)
    • 5. A panel to render 3D models of the items on, for examining and such (interactable OnExamine)
    • 6. Player monitor panel(health, name, avatar, etc)
  • Trigger(s) that can interact with usable items (i.e: If a specific key is used within the trigger, the door should be unlocked)
  • OR create entities that implement such behaviour such as: my_door_ent [key: "Unlocked By", Val: "item_classname"] (seems excessive)
  • Edit HL2's current weapons to abide to the inventory system

That is my plan for now. Any good ideas or suggestions are welcome!

Some progress to show:

Here (for now) is a item definition example (defined to its fullest):
A better formatted view of this "code" is located directly here: http://oyvindandersson.net/SourceSDK/InventorySystem/usable_items.txt

Code: Select all
"item_definition_file_name"
{
    // Default category is "global". Item definitions can be precached/loaded by category
    "my_category"
    {
         "item_health_small"
         {
               "print_name"    "Item small" // Localize
               "quantity" "1"  // How "many" of this item you get (i.e: ammo could be "100")
               "capacity_per_slot"  "1"  // How many of this item a slot can take (the capacity does not influence this.
                                                    // If the quantity is 100, then a capacity of 2 yields: 1 slot => 2 items of 100 quantity => 200. The
                                                    // items are merged and the internal quantity is set to 200)
               "can_discard"   "1"  // Should the player be allowed to discard it? Is it "expendable"?

               "view_model"  "path/to/v_model.mdl"  // A view model, in the case of FPS
               "world_model"  "path/to/w_model.mdl" // Model shown in the world

              // How much space of the inventory this item takes (1 row x 1 col = 1 slot, 1 row x 2 col = 2 slots vertically)
              // Optional to define: defaults to 1x1
               SlotSize
               {
                     "row_span"   "1" 
                     "column_span"  "1"
               }
 
               // Sound data. Optional as default sounds are in place
               SoundData
               {
                     "use"   "item_health_small.UseSound"
                     "drop"  "item_health_small.DropSound"
                     // TODO: Need something else?? We'll see...
               }

               // Required for VGUI
               TextureData
               {
                     "item_idle" // The state of the icon in the inventory UI when it's just sitting there...
                     {
                           "sprite_sheet"   "item_icons_selected_sheet" // A custom script type that defines a sprite-sheet with some properties
                           "row_span" "1" // How many "row" slots in the sheet the icon takes up
                           "column_span" "1" // How many column slots in the sheet the icon takes up
                           "row"  "3" // Which row in the sheet the icon is located
                           "column" "1" // Which column its's located

                           // All these settings are relative to what the sprite_sheet script defines. I.e:
                           // resolution of texture.vtf: 1024x1024. 1x1 slot icon takes up 128x128 pixels
                           // that yields 8 rows and 8 columns in that sheet. rows = 8, cols = 8.
                           // item_health_small icon is located at row 3, and col 1. It only takes up 128x128 pixels (1 slot)
                           // so the row-/column span is set to 1.
                           // This is for sprite-sheets (or texture atlas if you will). No use having single .vtf's for each item
                           // in the game!!
                     }

                     "item_selected" // The state of the icon in the inventory UI when it's selected
                     {
                           // typing is exhausting... same params as above
                     }

                     "item_disabled" // The state of the icon in the inventory UI when it's disabled
                     {
                           // typing is exhausting... same params as above
                     }

                     // Every state can use the same sheet however. That is all up to you, but the states needs to be defined.
           // To simplify such an event, you can set this:
           //
           // "item_selected"
           // {
           //       "use"      "item_idle"
           // }
           //
               }
         }
    }
}


// A new definition of similar values can inherit from a base definition. Take this as an example:

"item_health_medium"
{
    "use"  "item_health_small"

    // You can now redefine any parameter that you would like to specialize (i.e: slotsize, texturedata, models, etc)
 
    "print_name" "Health medium"
    "quantity"  "3"
}



SO, some text there... But _should_ make perfect sense I guess. One can create as many item-definition files as you'd like (to organize or whatnot). In the end, the code reaches out for this file: "item_database_manifest.txt" in scripts.

Example manifest:
Code: Select all
"item_database_manifest"
{
   "file"   "items/combat_items.txt"
   "file"   "items/usable_items.txt"
   "file"   "items/key_items.txt"
        "file" "items/mixable_utility_items.txt"
}




Soooo. Finally I got started with this project ( been wanting to do it for years tbh :P )
I, of course, plan on releasing the thing when it's properly optimized and as extendable/customizable as I want, along with a tutorial perhaps.
For now, I'm only doing singleplayer version of this, but I'm sure (after I'm done) it won't get too troublesome "porting" it to multiplayer.

Regards,
Oyvind
Last edited by Garrador on Sat Dec 21, 2013 1:02 am, edited 4 times in total.
You click on Build or type
make (or some equivalent), and you are astonished, then mortified, as you realize that the whole world is being
recompiled and relinked!
- Scott Meyers
User avatar
Garrador
Veteran
Veteran
 
Joined: Fri May 12, 2006 10:39 pm
Location: Norway

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby Armageddon on Wed Dec 18, 2013 12:39 am

Very cool of you to do this. A good inventory tutorial has been needed for quite sometime.
User avatar
Armageddon
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Sun Dec 14, 2008 5:53 am

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby Garrador on Thu Dec 19, 2013 7:41 pm

Armageddon wrote:Very cool of you to do this. A good inventory tutorial has been needed for quite sometime.


Yeah definitely! For all these years I have been looking for one :P Better to do it yourself in the end I guess.

Ok, some minor but very useful update(s):

- Item definitions can now inherit other definitions to save some typing, as well as defining a definition as abstract (will not be parsed as a valid item that can be spawned, or used in the inventory). This is simply a utility function for writing item definitions.

Here is an example of this new behaviour:

Code: Select all
"combat_items"
{
   "global"
   {
      //
      // Base definition for equipable items (weapon, torch, etc)
      //
      "base_equipable"
      {
         "used_as_base" "1"   // Make abstract
         
         "quantity" "1"
         "capacity_per_slot" "1"
         
         "can_equip" "1"
         "can_discard" "1"   
         
         // Specialized behaviour. Child def's should define this themselves
         "can_use" "0" 
         "can_combine" "0"   
         
         // SlotSize, SoundData and TextureData now uses default values that is
         // set in code, so we can avoid a shit-load of typing for base-def's
      }
      
      //
      // Simple equipable item for debugging
      //
      "item_stick_debug"
      {
         "inherit" "used_as_base"
         
         "view_model" "models/weapons/v_stick.mdl"
         "world_model" "models/weapons/w_stick.mdl"
         
         TextureData
         {
            "item_idle"
            {
               "sprite_sheet"   "item_icons_weapons_idle_sheet"
               // row_span, column_span, row and column all default to 1.
               // This item is at that position, so we don't type it
            }
            "item_selected"
            {
               "sprite_sheet"   "item_icons_weapons_idle_sheet"
               "column" "2" // Selected version is next to the idle one
            }
            "item_disabled"
            {
               "sprite_sheet"   "item_icons_weapons_idle_sheet"
               "column" "3" // Selected version is next to the selected one
            }
         }
      }
   }
}



Concept design of inventory

As the resident evil 2 inventory system inspired me, I'll be creating a new version of it for the same "game" (just for fun). So here is what I want to enable:

Image
You click on Build or type
make (or some equivalent), and you are astonished, then mortified, as you realize that the whole world is being
recompiled and relinked!
- Scott Meyers
User avatar
Garrador
Veteran
Veteran
 
Joined: Fri May 12, 2006 10:39 pm
Location: Norway

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby Garrador on Sat Dec 21, 2013 12:49 am

Small update. Nothin in particular to show but features!

- Items can now be created in hammer
- Items can be picked up and stored in the players' inventory (which also removes the entity from the world)
- Items can be removed from the inventory (and respawned to the world if flagged to do so)
- Player inventory now loads a inventory definition that sets max slots/bonus slots etc
- Added a "description" field to item definitions

I'll post a video of it working in game tomorrow perhaps.

Oh, and more detailed "reports" here: http://oyvindandersson.net/blog/?p=226
You click on Build or type
make (or some equivalent), and you are astonished, then mortified, as you realize that the whole world is being
recompiled and relinked!
- Scott Meyers
User avatar
Garrador
Veteran
Veteran
 
Joined: Fri May 12, 2006 10:39 pm
Location: Norway

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby Garrador on Sat Dec 28, 2013 11:40 am

Yet another update:

- fully integrated system and networked.
- prototype gui for inventory is set up to debug commands

Spent some time debugging some errors I had no clue as to where they were coming from. Damn macros.

On a side note: not so familiar with how entities are stored across levels. Do they just implement
data description tables for that, or does it involve more? Going to take a look on how the player keeps his weapons in hl2, but got to track down the actual logic unless, as said, it's done via datadescs.
You click on Build or type
make (or some equivalent), and you are astonished, then mortified, as you realize that the whole world is being
recompiled and relinked!
- Scott Meyers
User avatar
Garrador
Veteran
Veteran
 
Joined: Fri May 12, 2006 10:39 pm
Location: Norway

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby zombie@computer on Sat Dec 28, 2013 11:47 am

iirc its done via datadescs, so youll have to take care on how you design the backend of the inventory. For my last inventory i simply made unique IDs for each itemtype; by limiting the number of items to max 255 i could transfter the entire inventory as a single string in the datadesc without problems
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby Garrador on Sat Dec 28, 2013 4:27 pm

Ah, ok! Great, that makes it easier ;)

Yeah I won't support more than that at any given time (in the one I want, I only need 12), but of course, it is extendable.
You click on Build or type
make (or some equivalent), and you are astonished, then mortified, as you realize that the whole world is being
recompiled and relinked!
- Scott Meyers
User avatar
Garrador
Veteran
Veteran
 
Joined: Fri May 12, 2006 10:39 pm
Location: Norway

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby MrTwoVideoCards on Sun Dec 29, 2013 5:50 am

Whoa it's garrador, long time no see! Also that is pretty rad. Are you using Gameui or vgui for this?
User avatar
MrTwoVideoCards
Monothetic
 
Joined: Thu Aug 02, 2007 11:18 am
Location: IN YOUR SOUL

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby Garrador on Mon Dec 30, 2013 4:23 am

Was using vgui until I had to search up what you meant by Gameui. I saw the interface and the new overrides in sourcesdk 2013...

I'll probably be using gameui. Have not found out what the main difference is, other than that I can create a whole new UI for the main menu and such (which I will do for fun, after it's done ).

Since you ask, maybe you could also tell me what the difference is?

Atm I'm just inheriting from vgui::Frame and creating a global panel (like in the basic tutorial on the wiki). I'll go back on that to create a panel that will only initialize and work in the actual game (as a HUD panel).

For now I just need to prototype functionality. The actual commands and logic are in the inventory manager class, so I can change the frontend to whatever I like when it works like it should.
You click on Build or type
make (or some equivalent), and you are astonished, then mortified, as you realize that the whole world is being
recompiled and relinked!
- Scott Meyers
User avatar
Garrador
Veteran
Veteran
 
Joined: Fri May 12, 2006 10:39 pm
Location: Norway

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby Garrador on Mon Dec 30, 2013 5:44 am

A little prototype video (only discard command)

You click on Build or type
make (or some equivalent), and you are astonished, then mortified, as you realize that the whole world is being
recompiled and relinked!
- Scott Meyers
User avatar
Garrador
Veteran
Veteran
 
Joined: Fri May 12, 2006 10:39 pm
Location: Norway

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby Garrador on Sun Jan 05, 2014 3:18 am

Happy new year!
So, now I can get back to work on this. I've created a base class for keys. These keys are configured in Hammer and linked to any door by setting the ID of the key on the door (new func_door, as suggested by z@c). Works perfectly well!

So now every key uses the same entity, but the actual definition is also set in Hammer, which in turn makes them very customizable without much work at all.

Also hooked up the USE button in the inventory panel to call on the handler to the entity it targets, as well as a looooooooot of other stuff that is not interesting ;)

Here is a short demo:
You click on Build or type
make (or some equivalent), and you are astonished, then mortified, as you realize that the whole world is being
recompiled and relinked!
- Scott Meyers
User avatar
Garrador
Veteran
Veteran
 
Joined: Fri May 12, 2006 10:39 pm
Location: Norway

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby DoxC on Fri Jan 24, 2014 11:50 am

hey i was wondering if your inventory can be implemented with this tut :
http://forums.steamgames.com/forums/sho ... ?t=1935224

really wanna try out your method
DoxC
Member
Member
 
Joined: Fri Jan 10, 2014 5:44 am

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby Garrador on Fri Jan 24, 2014 12:12 pm

DoxC wrote:hey i was wondering if your inventory can be implemented with this tut :
http://forums.steamgames.com/forums/sho ... ?t=1935224

really wanna try out your method


Sure, you can, but you will still need the classes that parses the actual script files, and the inventory item data structure that stores the info.

All in all: Storing entities "on" the player is the easy part. Making all the utilities and structures that you need to make it a flexible and easy, plus making all these options easily available in hammer for configuration is the "hard" part. Not hard, but it takes a while.

Some time since last update. I'm also working on my final exam (making a game), so I'm jumping between projects depending on how tired I get of the other :P
You click on Build or type
make (or some equivalent), and you are astonished, then mortified, as you realize that the whole world is being
recompiled and relinked!
- Scott Meyers
User avatar
Garrador
Veteran
Veteran
 
Joined: Fri May 12, 2006 10:39 pm
Location: Norway

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby zombie@computer on Fri Jan 31, 2014 9:10 am

Hey Garrador, just wondering how you made the discard option. Just spawning something in front of the player is troublesome when skle's facing a wall, so you need to test for that and abort discarding or find another place to drop the item.

What was your brilliant solution?
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: Resident Evil 2'ish Inventory System - Progress Thread

Postby Garrador on Fri Feb 07, 2014 8:51 pm

I have not solved this! I just now became aware of it :P

I'll do some tracing around, and simply abort the process ("You cannot drop it here..."), or skip the re-spawn depending on inventory settings (i.e: "Fuck physics ? 1 : 0")
You click on Build or type
make (or some equivalent), and you are astonished, then mortified, as you realize that the whole world is being
recompiled and relinked!
- Scott Meyers
User avatar
Garrador
Veteran
Veteran
 
Joined: Fri May 12, 2006 10:39 pm
Location: Norway

Return to Programming

Who is online

Users browsing this forum: No registered users

cron