Adding NPCs to your json building map

We are currently in the process of porting parts of NPCs to jsons… it doesn’t seem very exciting but I’m going to walk you through the things you should be familiar with before adding an NPC to your building in the new system.

I assume you have already created your map so you want to use place_specials to add an NPC spawn…

"place_specials": [
     { "type": "npc", "class": "guard", "x": 19, "y": 21 }
],

Here, ‘guard’ is the NPC id that lets the game know what kind of NPC to generate. These are defined in data/json/npcs/npc.json… when you open it, the first entry looks really ugly but that is because it has info to reference in the comments. If we look for id ‘guard’ you will find

},{
    "type" : "npc",
    "id" : "guard",
    "comment" : "A generic guard for the Free Merchants faction.",
    "name+" : ", Guard",
    "class" : 9,
    "attitude" : 0,
    "mission" : 7,
    "chat" : 2,
    "faction" : "free_merchants"
  },{

“id” must be unique and is what you will put in the place_specials entry.

“comment” lets other users know where the NPC is used and if they should feel free to use the same entry… ‘guard’ is very generic and it is meant to be. These guys are friends with most people… if you were building a camp nothing there would indicate that you couldn’t use them also.

“name+” This is a title appended to the end of their regular name… it is there to make it easier for the player to track who is who.

“class” Here is where the enums start, someday these will all be strings but for now you have to pick the number associated with the class you want your NPC to be from. The comments at the top of npc.json lists the important ones:

The numbers missing from that list are for unique NPCs… someday these will be fully ported to jsons but for now you can either hard-code them or use the existing ones. Gear for the classes is described in detail here: http://smf.cataclysmdda.com/index.php?topic=7179.0

“attitude” Lets you set the NPC’s immediate reaction to the player. Most should be 0. Talk means the NPC will approach the player and begin conversation. Follow and Defend will make them perform the associated follower tasks. Kill will make the NPC hostile to the player without even checking to see if you are hostile to their faction (at the moment it also lets them know where the player is and will make them rush you). And flee will make them run away.

“mission” If you want the NPC to wander, as they are prone to, keep it at null. Shopkeep is of limited use and causes an NPC to generally stay in the same area. Guard is the most common for NPCs associated with a building, this will typically cause them to leave their spawn point to kill enemies but have them return when they are done.

“chat” Is the least accessible since conversations are entirely hard-coded. Done ends conversation before it starts (can’t talk to them) and guard will simply return a neutral/friendly hi. All 100+ options exist but you’d have to understand the talk_topic enum in npc.h. Stranger_friendly will return the same thing a random NPC would say if they liked you.

“faction” Finally, this determines which faction your NPC represents… if you aren’t familiar with the current factions check out factions.json in the same folder you found npc.h. Below I pulled up the ‘free_merchants’ id that the NPC above referenced.

},{ "type" : "faction", "id" : "free_merchants", "name" : "The Free Merchants", "likes_u" : 30, "respects_u" : 30, "known_by_u" : true, "size" : 999, "power" : 100, "good" : 1, "strength" : 1, "sneak" : -1, "crime" : -1, "cult" : -1, "desc" : "A conglomeration of entrepreneurs and businessmen that stand together to hammer-out an existence through trade and industry." },{
These guys seem pretty swell… faction relations are still a work in progress but to check your starting relationship all you need to know is that likes_u and respects_u should both be positive. If they become significantly negative the factions members will attack you on sight… fighting back will only drop your faction relationship further. So if you wanted an NPC to be hostile you could set its faction to “hells_raiders” since they already hate you.

If you are working on a project and need help, feel free to ask any questions you might have. I’ll try and keep this updated as things improve.

“doesn’t seem very exciting”

Bullshit. NPCs were a major problem for pretty much all of 2013, the factions screen was pretty much a joke, and this is essential infrastructure to continue turning that around. Nice job, Acidia.