# Is NPC spawning a yes/no thing?

**URL:** <https://discourse.cataclysmdda.org/t/is-npc-spawning-a-yes-no-thing/24443>\
**Category:** The Toolbox\
**Created:** [August 14, 2020, 2:13pm UTC](https://discourse.cataclysmdda.org/t/is-npc-spawning-a-yes-no-thing/24443 "2020-08-14T14:13:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nonesuch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/nonesuch/32/8516_2.png) [@Nonesuch](https://discourse.cataclysmdda.org/u/Nonesuch)\
**Post date:** [August 14, 2020, 2:13pm UTC](https://discourse.cataclysmdda.org/t/is-npc-spawning-a-yes-no-thing/24443/1 "2020-08-14T14:13:16Z")

</div>

I’ve been looking at documentation, and it appears that monsters can be placed with a spawn chance, but I don’t see anything about NPCs being placed with a chance. I see NPC classes placed (so you can randomize what you get), but no spawn chances. Is this correct, or is it a case of ‘no one tried it previously’?  
Just curious, as adding NPC spawn chance to something like sealed houses would be interesting. Bash your way into the boarded up building and SURPRISE! INSTANT BANDIT!

---

<div class="post-metadata">

**Author:** ![mlangsdorf](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/mlangsdorf/32/2462_2.png) [@mlangsdorf](https://discourse.cataclysmdda.org/u/mlangsdorf)\
**Post date:** [August 14, 2020, 4:00pm UTC](https://discourse.cataclysmdda.org/t/is-npc-spawning-a-yes-no-thing/24443/2 "2020-08-14T16:00:58Z")

</div>

I’m pretty sure `place_npcs` take a `chance` parameter, same as the other `place_` invocations. Try it and tell us the results.

---

<div class="post-metadata">

**Author:** ![Nonesuch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/nonesuch/32/8516_2.png) [@Nonesuch](https://discourse.cataclysmdda.org/u/Nonesuch)\
**Post date:** [August 14, 2020, 6:39pm UTC](https://discourse.cataclysmdda.org/t/is-npc-spawning-a-yes-no-thing/24443/3 "2020-08-14T18:39:23Z")

</div>

Initial test, set bandits to spawn in refugee center. Set % of 90, 50, 25, 10. Three attempts, in all three all the bandits spawned. Second test put % to 10 for all, bandits spawned every time. Was basing my % off the evac shelter basement, which has a 40% zombie spawn and you almost never see it.  
This could be where I was putting the entries in the JSON. I’ll test again later. It definitely took the “chance” field without spitting an error back, so it recognizes it in conjunction with the NPC, but questionable as to if it applies it.

---

<div class="post-metadata">

**Author:** ![Nonesuch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/nonesuch/32/8516_2.png) [@Nonesuch](https://discourse.cataclysmdda.org/u/Nonesuch)\
**Post date:** [August 14, 2020, 9:39pm UTC](https://discourse.cataclysmdda.org/t/is-npc-spawning-a-yes-no-thing/24443/4 "2020-08-14T21:39:55Z")

</div>

Well, found _an_ answer, but as it’s from 2019 I don’t know how current it is. The pull request below was the one that introduced the Bone Seer into the game, and in it someone explicitly states that `chance` does _not_ work on `place_npcs`. Looks like the main way to get an NPC ‘random encounter’ is via nested mapgens, which I have to look up more details on.  
Still kinda weird, as it takes the parameter and doesn’t spit errors back, but I know next to nothing about C++ so…

> <https://github.com/CleverRaven/Cataclysm-DDA/pull/33828>

---

<div class="post-metadata">

**Author:** ![Nonesuch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/nonesuch/32/8516_2.png) [@Nonesuch](https://discourse.cataclysmdda.org/u/Nonesuch)\
**Post date:** [August 15, 2020, 12:32pm UTC](https://discourse.cataclysmdda.org/t/is-npc-spawning-a-yes-no-thing/24443/5 "2020-08-15T12:32:44Z")

</div>

OK, going to leave this here for anyone else who has the same question I did. Working off Brigitte the Bone Seer, it’s fairly simple to add in a chance of an NPC spawning to a given map. First step is to create a nested mapgen entry, like so:  
[  
{  
“type”: “mapgen”,  
“method”: “json”,  
“nested\_mapgen\_id”: “bandit\_spawn”,  
“object”: { “mapgensize”: [1, 1], “place\_npcs”: [{ “class”: “bandit”, “x”: 0, “y”: 0 }] }  
}  
]

That’s exactly the same as Brigitte’s, so it’s _only_ an NPC spawn - it doesn’t force anything else to spawn with her. If you want examples of how to spawn NPCs with specific map functions, you can check the city\_npc.json in the Nested folder under mapgen.

To place the NPC is almost as simple. You make a “place\_nested” entry like so:

```
"place_nested": [{ "chunks": [ [ "bandit_spawn", 80], ["null", 20] ], "x": 49, "y": 19 },

```

Again, this was copied from Brigitte. The 80 after the “bandit\_spawn” is the chance the nested mapgen chunk will spawn, the “null” is the chance it won’t.  
If you want to place multiples, you just make separate “chunks” entries, like so:  
“place\_nested”: [{ “chunks”: [ [ “bandit\_spawn”, 80], [“null”, 20] ], “x”: 49, “y”: 19 },  
{ “chunks”: [[ “bandit\_spawn”, 50], [“null”, 50] ], “x”: 48, “y”: 18 },  
{ “chunks”: [[ “bandit\_spawn”, 25], [“null”, 75] ], “x”: 47, “y”: 17 },  
{ “chunks”: [[ “bandit\_spawn”, 10], [“null”, 90] ], “x”: 46, “y”: 16 }

In this case, what I did was torture the poor Broker at the refugee center by giving bandits a chance to spawn right next to him. He didn’t appreciate it. The format of multiple nested chunks was taken from the lab JSON entries, if you need a reference.  
I’m sure the folks who are more experienced with either JSON or mapgens and nested mapgens would be able to tell you more and better info on this, but I’ve tested this and it _does_ work.

---

<div class="post-metadata">

**Author:** ![TheZoneWizard](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/thezonewizard/32/1397_2.png) [@TheZoneWizard](https://discourse.cataclysmdda.org/u/TheZoneWizard)\
**Post date:** [August 15, 2020, 7:15pm UTC](https://discourse.cataclysmdda.org/t/is-npc-spawning-a-yes-no-thing/24443/6 "2020-08-15T19:15:29Z")

</div>

Would there be some kind of narrative for them being inside or just as any other survivor looting and plundering? Would be funny to pop open a survivor boarded house and a Bandit charges you and gets stuck in a bear trap or trips a mine lol

---

<div class="post-metadata">

**Author:** ![Nonesuch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/nonesuch/32/8516_2.png) [@Nonesuch](https://discourse.cataclysmdda.org/u/Nonesuch)\
**Post date:** [August 15, 2020, 7:28pm UTC](https://discourse.cataclysmdda.org/t/is-npc-spawning-a-yes-no-thing/24443/7 "2020-08-15T19:28:09Z")

</div>

“Our defense is unassailable! Watch as I demonstrate -” _explosion_

My opinion, both are valid. It’d make sense for bandit/raider types to have a fortified pepper house to work from when they’re in town, but the random raider type in the back bedroom acting as zombie bait is fun as well." Help, there’s a maniac! “ _glass shatters_ Zombie Brute:" Surprise, mother\*\*\*\*er! "

---

<div class="post-metadata">

**Author:** ![TheZoneWizard](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/thezonewizard/32/1397_2.png) [@TheZoneWizard](https://discourse.cataclysmdda.org/u/TheZoneWizard)\
**Post date:** [August 15, 2020, 7:32pm UTC](https://discourse.cataclysmdda.org/t/is-npc-spawning-a-yes-no-thing/24443/8 "2020-08-15T19:32:23Z")

</div>

Are you actually making this a thing, because it sounds like a gas to me when I see a boarded up building.

I’d like to suggest some things if you feel like a few ideas.

---

<div class="post-metadata">

**Author:** ![Ashtray\_Gray](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/ashtray_gray/32/9399_2.png) [@Ashtray\_Gray](https://discourse.cataclysmdda.org/u/Ashtray_Gray)\
**Post date:** [August 17, 2020, 5:15am UTC](https://discourse.cataclysmdda.org/t/is-npc-spawning-a-yes-no-thing/24443/9 "2020-08-17T05:15:38Z")

</div>

I personally would love to be killed by some bum with a shotgun who lives in a random subway tile.

---

<div class="post-metadata">

**Author:** ![Ashtray\_Gray](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/ashtray_gray/32/9399_2.png) [@Ashtray\_Gray](https://discourse.cataclysmdda.org/u/Ashtray_Gray)\
**Post date:** [August 17, 2020, 5:17am UTC](https://discourse.cataclysmdda.org/t/is-npc-spawning-a-yes-no-thing/24443/10 "2020-08-17T05:17:45Z")

</div>

Maybe there is a tent and fire pit there too. Maybe what I’m describing and you’re describing are two different things… 🤔
