≡ Menu

Armory – A Free (and Unfinished) Stat, Inventory, and Buff/Debuff Framework for Unity

So a couple of weeks ago, my wife and I went on our honeymoon to St. John in the Virgin Islands. The trip was AWESOME. St. John is absolutely gorgeous (like a screensaver), and we relaxed big time with a lot of snorkeling, hiking, reading, etc. On the plane ride home I spent some time working on something called Armory – a simple framework to add stats to a character in Unity and modify them through things like equipment and buffs/debuffs. I didn’t get very far on the plane, since I started reading the new Bobby Fischer biography and couldn’t put it down.

My plan was to finish this project up in my spare time, but unfortunately my laptop completely died right after I got home. I ordered a new one, but this whole thing kind of put a damper on Armory, at least for now. I managed to grab the project off of my comatose laptop, and thought that the unfinished project might help someone out – so I decided to throw it up online.

Here’s a webplayer example if you want to check it out (click the image below). You can see a simple set of defined stats (Strength, Intelligence, and Agility), with some different ways to modify them: equipping weapons and casting buffs/debuffs. This isn’t anything super sophisticated, and the UI is obviously primitive, but if you are interested in this type of functionality in your game, it might help you get started.

–> Download the Unity project here, complete with source code

I didn’t finish the project, as mentioned above, but here’s what you can do.

Define Stats

Check out StatController.cs, or the StatController component on the Hero game object included in the demo scene. In here you’re able to create a bunch of stats, along with some different options to control their behavior:

  • Minimum and Maximum values for the stat.
  • Starting value. Right now this is just a single simple value, but I was planning on adding some sort of mechanism to allow each stat to grow as the character ‘levels up’ – a concept that never made it in here.
  • Clamp type for the value. All stats are floats deep down. Do you want the stat to use the raw float value, the floor, or round to the nearest int.

If you check out the example, you’ll see Strength, Intelligence, and Agility stats defined to range from 0 -> 100.

Equip Weapons and See Stats Change

Check out Inventory.cs or the Inventory component on the Hero game object in the included demo scene. This is just a basic inventory system that allows you to define a list of weapons and switch between different equipped weapons.

Each weapon has a list of StatModifers that control how the weapon affects the Hero’s stats when equipped. StatModifers allow you to control the following:

  • Which stat to modify. Right now this is just a string, but if I kept working on this it might be nice to get an enum or something that reads from the values you setup in the StatController.
  • How much to modify the stat by. Currently Armory only support additive modifications, but if I kept working on this I would probably add more functionality here. It might be useful to have a sword that increases you strength by 5% instead of an absolute quantity.
  • How long to modify the stat for, < 0 = permanent. As you equip and unequip weapons it adds/removes permanent StatModifiers.

This code should be pretty straightforward.

Buff and Debuff Your Character

Spellbook.cs defines some simple spells that can be used to buff and debuff your character. Click around in the demo and you will see them working. These buffs use the same StatModifiers that the Inventory uses, but they are timed and not permanent – they wear off over time.

Goodnight

I think that pretty much sums it up. An unfinished project that just happened to be in the wrong place at the wrong time when my laptop decided to check out. Hopefully it is useful to someone anyway! Feel free to use this code for whatever you want, please just drop me a line and let me know what you are using it for.

{ 6 comments… add one }

  • Terry March 2, 2011, 1:31 pm

    Thank you for sharing this with the community. I will probably be using some of this code for a childrens game I am working on. If it gets completed I will drop you a note :)

  • saurabh March 18, 2011, 7:45 am

    sir i need ur small help….plz plz plz dont say no…

    i just need a simple example of calling a .3ds file in scene via xml file with x,y,z,rotation parameters…plz sir help me..i really neeed it for a small project of mine and coundn’t figure out the way…

    my project time is running out, i have a sample in which a rectangle is called from xml, i want to call a .3ds file…plz help sir..plz…my mail address is ersaurabh101@gmail.com

    if u want i can mail you that code + a sample .3ds file…
    Please please dont say nooo…

    • Steve March 18, 2011, 2:49 pm

      Hey man, unfortunately I’m not really sure how to do that and would have to look into it. I don’t really have time right now to take on any new projects. Good luck with figuring it out!

  • Mephisto January 20, 2014, 11:21 pm

    Using this for a game prototype if you’re alright with it.

    • Steve January 21, 2014, 1:08 pm

      Of course, that’s what it’s here for!

  • Gabriel February 13, 2014, 2:24 pm

    Hi, taking this to dissect in my quest to learn.
    Thanks for sharing!

Leave a Comment