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)
- 1. Mouse-enabled panel for selection
- 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 )
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