Slot selection and replacement
A new NPC spawn attempt scans the 200 slots in order from the start and takes the first empty one, with a few exceptions to that rule. If no slot is free, the game looks for a replaceable NPC and puts the incoming NPC in its place; when none qualifies as replaceable, the attempt fails and nothing appears.
Spawn rate basics
Spawn rate determines the chance of an NPC spawning on each tick. The default value is 1/600, which the source describes as a 0.17% per-tick chance and about a 9.52% chance per second that at least one NPC spawns.
Step-by-Step Guide
Expect first-empty-slot placement
New NPCs generally go into the earliest empty slot, keeping in mind that the source notes exceptions to this ordering.
Fill slots with replaceable NPCs
When every slot is taken, a spawn succeeds only by swapping out a replaceable NPC; lacking any replaceable occupant, the attempt produces nothing.
Allow for the post-death gap
After any NPC dies or despawns, spawning is suppressed for the next tick for all players.

