NPC Items [How to...]

So here is how the new NPC inventory system works. Regardless of the NPC class, all NPCs draw what items they should be carrying from Cataclysm-DDA/data/json/npcs/items_generic.json when they do not have a unique file (more in a sec). When you open items_generic.json you will see item groups that should seem understandable… if you need to pull an item from group ‘npc_pants_male’ there are currently 4 options.

{ "type" : "item_group", "id" : "npc_pants_male", "items":[ ["jeans", 20], ["pants", 20], ["pants_leather", 20], ["pants_cargo", 20] ] }

The probability of getting one of the four is adding up all the weighted scores on the right and dividing that item’s score by the total.

The possible item groups are:
npc_pants_male*
npc_pants_female*
npc_shirt_male*
npc_shirt_female*
npc_gloves*
npc_coat*
npc_shoes*
npc_masks*
npc_eyes*
npc_hat*
npc_extra* (Currently backpacks)
npc_bashing
npc_cutting
npc_stabbing
npc_throw (Throwing logic is currently very limited)
npc_archery
[npc_pistols] (See below for these four)
[npc_shotgun]
[npc_smg]
[npc_rifle]
npc_launcher
npc_weapon_random
npc_misc

*For clothing only, ‘null’ means that you don’t want the npc to have an item.
[] These item groups currently pull from item_groups.json, in their respective fields… BUT can be edited in a unique class file.

NPCs naturally draw a weapon from their strongest combat skill group. If one or more are tied or they have no skills then they can draw from npc_weapon_random. As we go, there are bound to be more groups (bionics) added but for now this is plenty. After the NPC is all kitted up, it will attempt to fill any extra volume that it has with items from npc_misc. Ammo is spawned automatically for weapons but it doesn’t handle UPS or a few stray weapons with potential errors in their definitions (they only get a full clip/charge and no spare).

Custom/Unique inventories are remarkably easy… create a new file in the npcs directory and you will fill it with any of the above item groups that you wish to define but use the NPC class instead of ‘npc’ in its definition. For example:

{ "type" : "item_group", "id" : "NC_TRADER_pants_male", "items":[ ["jeans", 20], ["pants", 20], ["pants_leather", 20], ["pants_cargo", 60] ] }

Is the class “NC_TRADER”s version of npc_pants_male. Here we wanted to use the same kinds of pants but wanted cargo pants to be more common so the merchant would have more carrying capacity. You don’t have to add an item group for a NPC class though! If we wanted traders to use the normal npc_pants_male item group all we have to do is delete the entry… so just pick and choose how you want your NPC class to be different. Weapons are the same since you can change their group by using ‘NC_TRADER_pistols’ to have it draw from there instead of the pistols entry in item_groups.json.

That’s really all there is to it. I’ve already converted the existing NPC classes into .jsons but we could use a lot of help making them unique (originally there were few changes to their inventories… like ninjas not wearing shirts or doctors usually spawning with medicine). Maybe the biggest thing would be filling up items_generic.json’s item group ‘npc_misc’ with all the random things you’d find in the apocalypse (almost every item in game worth picking up)… in correctly balanced ratios.

Since random NPCs spawn from the classes, if you want to make a new class I can hard code the stats (someday will be moved to jsons) if you shoot-me/post the item group file.

Existing classes:
arsonist - flame throwers are incredibly powerful against low armored players
bounty hunter
cowboy
doctor
evac shopkeep – unique, won’t random spawn… in Refugee (Evacuation) Center
hacker
hunter
ninja
scavenger - light pistol focus, similar to cowboy but emphasis on survival
scientist
thug - melee is actually fairly weak compared to point-blank firearms
trader