Terraria in game housing and npc spawn time.

Jcapp

Terrarian
So all testing was done on the same world, from world gen start time of 8:15 in game time. I would just replace the world file each time i started over or made an edit with an original copy of the world and the appropriate housing. Time in non parenthesis are the in game time, in parenthesis is the elapsed real time. I would log in and loot a chest at spawn containing 1 gold, 20 bombs and a gold watch to simulate looting it in world. It is also all done on the same character. i would just delete their inventory before exiting each time so they logged in with no criteria met. if it has (sp) it means i accidently logged into the world in single player mode rather then host&play

All these times are recorded manually, and none of this was automated. so there will be a positive variance of a second or two sometimes, just due to my reaction time.

2 strip 3 houses. (4tries this time, more later)
merch- 2:30pm (6:15) | 2:30pm (6:15) | 2:30 (6:15) | 12:15 (4:00)
demo - 5:00pm day2 (32:45) | 12:20 day2 (28:05) | 6:03pm day2 (33.48) | 8:15am day2 (24:00)

~See the 21 2 strip thumbnail for the house type, just three of those.

21 big houses, solid edge full wall. (10 tries)
merch 10:15(sp) (2:00) | 10:15 (2:00) | 10:15 (2:00) | 10:25 (2:10) | 10:15 (2:00) | 10:25 (2:10) | 9:40 (1:25sp) | 10:20 (2:05) | 10:16 (2:01) |10:15 (2:00)
demo 12:16(sp) (4:01) | 12:16 (4:01) | 12:15 (4:00) | 12:24 (4:09) | 12:17 (4:02) | 12:26 (4:00) | 11:40 (3:25sp) | 12:19 (4:04) | 12:15 (4:00) |12:15 (4:00)
21lrg.jpg

2 strip, 21 houses (badger housing, 10 tries)
merch 10:37 (2:16) | 10:36 (2:15) | 10:24 (2:09) | 10:45 (2:30) | 10:27 (2:12) | 10:24 (2:09) | 10:24 (2:09) | 10:37 (2:22) | 10:25 (2:10) | 10:24 (2:09)
demo 12:21 (4:06) | 12:20 (4:05) | 1:56 (5:41) | 2:02 (5:47) | 2:02 (5:47) | 2:30 (6:15) | 2:02 (5:47) | 2:02 (5:47) | 12:21 (4:06) | 12:21 (4:06)
21-2strip.jpg

3 min size solid edge, full wall, roughly rectangular (5 tries)
merch 12:10 (3:55) | 11:40 (3:25) | 12:25 (4:10) | 12:25 (4:10) | 12:25 (4:10)
demo 1:57 (5:42) | 2:00 (5:45) | 4:45 (8:30) | 4:44 (8:29) | 4:44 (8:29)
3rec.jpg

2 strip 3 houses again (4 tries, missed when the merchant spawned in one. Demo still hasn't spawned in the 4th try of the last world. 4 in game days in.)
Merch - 1:02 (4:47) | 1:02 (4:47) | ???? (???) | 1:02 (4:47)
Demo - 7:22pm (11:07) | 6:42pmday2 (34:27) | 12:44pm day2 (28.29) |(Not yet spawned.)
 
Last edited:
Thank you for the tests & post!

I also did some testing

a fresh character i gave 99 torches, 50 bombs, a platinum coin and a cosmic car key.
i made a fresh map and put the builds (without torches) in per tedit. and put the time at 4:30(!)
copy pasted that map.
then i joined and 'activated' either Build A or Build B by putting in 3 torches (i alternated between A & B, but here it is in order)

v3VWrBb.png
A (3 tries)
merch 6:58am | 11:41am | 3:30pm
demo 10:02am | 7:17 pm | 7:19pm


NgqicRp.png
B (3 tries)
merch 10:02am | 9:08am | 9:30am
demo 2:33 pm | 11:13am | 3:40pm

then i copy pasted 3k valid houses like this with tedit
jdLDrtR.png
2kA+1kB (3 tries)
merch 10:30am | 8:40am | 6:33am
demo 12:30am | 10:20am | 8:32am


I am still not fully convinced that Build A will delay demo man spawn. This hints to it, but the sample size is too small.
Also: npcs do not spawn at night, so when no spawn happens at the first day, the whole spawn gets delayed by a night.


EDIT:

did some more:
e7lCyDb.png
corner house (2 tries)
merch 5:59am | 8:30am
demo 7:08am | 1:09 pm


cwwkOGU.png
one strip housing (4 tries)
merch 2:40pm | 9:39am | night | 2:41pm
demo 6:50pm | 1:32 pm | night | night
(i stopped test when it turned night)
 
Last edited:
I plan on doing some automated testing, if you guys would like me to test a variety of housing setups, let me know (send me a world file with the housing built or a screenshot would suffice)

If you would like to do automated testing for yourself, here is the script I wrote (designed to work only on a 1920x1080 resolution because I was lazy):

; ------------------------------------------------------------------------------------------------------------------------------------------------------
; 1) Press CTRL + ESC to terminate the script at any time
; 2) You need a .plr file on your desktop named NPC_Waiter (or you can change the parameters in the script)
; 3) NPC_Waiter.plr should have item requirements for demo/Merchant spawn beforehand.
; 4) Two .wld files should exist on your desktop, named BigBoiHaus.wld and SmolHaus.wld (or you can change the parameters in the script)
; 5) There is a loop in the script that clicks on the location of a Grandfather Clock to display the in-game time (for easy time stamping during VOD review)
; ------------------------------------------------------------------------------------------------------------------------------------------------------



#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
;SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetKeyDelay, 50, 10
SetMouseDelay, 50
SetTitleMatchMode, 3

; --------Start on the Title screen before activating the script-------
if !FileExist("C:\Users\%A_UserName%\Documents\My Games\Terraria\Players\NPC_Waiter.plr")
FileCopy, C:\Users\%A_UserName%\Desktop\NPC_Waiter.plr, C:\Users\%A_UserName%\Documents\My Games\Terraria\Players\NPC_Waiter.plr
Loop
{
WinActivate, ahk_exe Terraria.exe
Sleep, 1000
If !WinActive("ahk_exe Terraria.exe"){
MsgBox, Terraria EXE could not be found.. Exiting APP
ExitApp
}
---Big Haus---
FileDelete, C:\Users\%A_UserName%\Documents\My Games\Terraria\Worlds\BigBoiHaus.wld
FileDelete, C:\Users\%A_UserName%\Documents\My Games\Terraria\Worlds\BigBoiHaus.wld.bak
Sleep, 4000
FileCopy, C:\Users\%A_UserName%\Desktop\BigBoiHaus.wld, C:\Users\%A_UserName%\Documents\My Games\Terraria\Worlds\BigBoiHaus.wld
WinActivate, ahk_exe Terraria.exe
Sleep, 1000
Click 960, 280 ; Single Player
Click 668, 310 ; Play
Click, 665, 314 ; Enter World
Sleep, 3000
MouseMove, 916, 535
Sleep, 1000
Click, right, 916, 535
Send {Escape}
Click, 1802, 409

; Click on location of grandfather clock to display in-game time
Loop, 675{
Click, right, 916, 535
Sleep, 1000
}

Sleep, 2000
WinActivate, ahk_exe Terraria.exe
Click 1762, 1033 ; Bottom right
Click 749, 719 ; Save and Exit
Send {RButton up}

---Small Haus---
FileDelete, C:\Users\%A_UserName%\Documents\My Games\Terraria\Worlds\SmolHaus.wld
FileDelete, C:\Users\%A_UserName%\Documents\My Games\Terraria\Worlds\SmolHaus.wld.bak
Sleep, 4000
FileCopy, C:\Users\%A_UserName%\Desktop\SmolHaus.wld, C:\Users\%A_UserName%\Documents\My Games\Terraria\Worlds\SmolHaus.wld
WinActivate, ahk_exe Terraria.exe
Sleep, 1000
Click 960, 280 ; Single Player
Click 668, 310 ; Play
MouseMove, 665, 413 ; Enter World
Sleep, 2000
Click
Sleep, 3000
MouseMove, 916, 535
Sleep, 1000
Click, right, 916, 535
Send {Escape}
Click, 1802, 409
Loop, 675{
Click, right, 916, 535
Sleep, 1000
}
;Sleep, 675000 ; Sleep 11 minutes 15 seconds
Sleep, 2000
WinActivate, ahk_exe Terraria.exe
Click 1762, 1033 ; Bottom right
Click 749, 719 ; Save and Exit
Sleep, 2000
Send {RButton up}
}
ExitApp

^Esc::ExitApp
 
Thanks Travis! I probably will borrow the script this weekend and edit it for my resolution and to test in multiplayer. Im going to switch to just two house designs, the single strip house badger is most recently using that Curt designed and houses of the same design with full backwall. I am fairly convinced the backwall has something to do with it. But i want a big sample size before i make any conclusions.
 
Thank you Travis!

For anyone reading and wondering:

We want to find the fastest way to spawn in town npcs in a speedrunners scenario. (new world, new character):

You must build a house to spawn them in, but also met other requirements (per npc).

So you want to reduce time for housebuilding and time to met the other requirements while maximizing the chance that they spawn (if that is possible).

The questions i/we have, are (please correct me/add yours):

Is the 'spawnrate' of friendly town npcs correlated to
1. amount of backwalls in the provided housing (this is what jcapp wants to test)?
2. amount of valid houses in the world?
3. shape of the house (for example 5x12 vs 6x10 housing)?


we already know that a no backwall house will not make them spawn despite the tool saying its viable housing

Jm3q7tu.png

while just a single backwall makes them spawn

g4hq3jS.png

and also that the decision if its valid house at all can become a little bit complicated.
see: PC - How NPC housing (at NPC rest position) validation does work (an unrevealed game change in 1.3.5)
 
Interesting idea! But not sure if spawn time it is related to anything. A lot of RNG is involved. But as far as I remember they prefer at least rest positions with higher score. Will have some look in source code and try to find something.
Those ~2min look very stable. Maybe there is something ongoing.

I plan on doing some automated testing, if you guys would like me to test a variety of housing setups, let me know (send me a world file with the housing built or a screenshot would suffice)
If you like you can also try some other flat structures: tModLoader - Start with base

while just a single backwall makes them spawn
To be correct in my test some existing NPC went in. Not a new one. That might be some difference. Edit: made some world with only those flats New NPC spawned in. So they work.

Edit:
Found so far:
in short:
-new NPC chance related to the number of walls without objects on top
-check rate if a NPC can spawn (e.g. bomb in inventory) is checked in 2 min interval among all worlds and chars
-underground or deeper and in pyramid have lower chances
-if your seed has high surface level the chance for spawn are also higher (above surface)
=> with many flat walls you can let them spawn in less than 10 sec.


------full story----
a random world tile is chosen:
if more than a little water in there -> no spawn -> don't fill your flat with water :)
if 'active' tile -> no spawn, sky/only wall/only liquid (and some more?) are not active -> many furniture in room should reduce chance of spawn
tile need to have a valid wall -> more walls should decrease spawn time
If it had a valid wall it checks if it is in a room and find the best rest position.

If wall is sandbrick wall (pyramids) chances for spawn is lower (~1/4). -> quick pyramid flat not that good

for multiplayer: at least 500 blocks without a player at one side of the free NPC flat (best rest position). At single player one side should always be free (or?).

to be exact not only one tile is chosen but multiple at once: world size in blocks times 3*10^-5 (tile is above underground) and a 2nd trial 1.5*10^-5 (underground or below). For a small world: 151 + 75 chosen random tiles. So building in underground decreases the chances. So chances (for small worlds) should be about:
above surface: walltiles *151/ ( (4200-20)*(surfaceLevel-11)) )
below surface: walltiles *75 / ( (4200-20) * (1200-surfaceLevel-21) )
This about 3 times a second.
(but those random tiles could be the same, so they are a little lower)
-> if your seed has a high surface level chances for spawn should increase


---
It also checks if a NPC can spawn (e.g. if you have bombs) after some time 7200 (updates) and only during day. Afaik it does about 60 world updates per second -> it checks every 2 min. The fun thing is this is among all worlds and chars. So if you played with other char and other world first you can spawn merchant npc in a set up world in less than 10 sec.

upload_2019-8-9_4-55-51.png


No guarantee for correctness. I may missed something or misinterpreted it.
 
Last edited:
Can i ask you to clarify a few things in your post Unftf, there is still some confusion.


Basically, the more walls you have inside a house/flat when the play timer reaches 2 minutes the more likely an npc is to successfully spawn correct?

Thus this housing
NgqicRp.png


Is more likely to result in successful npc spawn then this house

cwwkOGU.png


First house has 30 walls per room, 2nd house has 4.
 
@Jcapp: If i understand him correctly: Yes, more backwall more chance to spawn

@Unftf Thank you, very helpful!

I still have 2 questions:
1. Is the spawning related to the spawn of other npcs(mobs) or critters?
(we know the other way: npcs make more critter spawn and less mobs, but regarding spawn-rate[can be altered with potions and water/peace-candle] and max-spawn [which gets abused with duck-glitch] maybe there is a way to help npc-spawn?)

2. If the 2minute timer is per player, would it help to have more players?
for example in 3p+ run or you join your partner in 2player just as he accumulates the requirements to have your 'character'-timer spawn them immediately)


After reading your post, one could say (please correct me):
The spawn does not depend on how much 'npc-rest-blocks' there are in a house or world per se.
The spawn does depend on how much backwalls (who are inside a valid house) and how high up in the world they are.
Cause a house has a maximum size, this makes it indirectly depend on number of houses in a world and therefore npc blocks.
The algo does discriminate pyramid housing, but not tree or sky island housing.

For unseeded: build as much housing as possible, as high as possible, with maximum backwalls and minimal furniture (workbench instead of tables) as you are comfortable with losing time with for other objective.

For seeded: you already have the run timed when you meet the requirements for merchant and demo, so you play with another char in another world before your actual run first to hit instant timing.
 
Last edited:
Can i ask you to clarify a few things in your post Unftf, there is still some confusion.


Basically, the more walls you have inside a house/flat when the play timer reaches 2 minutes the more likely an npc is to successfully spawn correct?
[..]
First house has 30 walls per room, 2nd house has 4.
Only walls without any on top count. So the first has 26 each and the 2nd 3 each. As long they are in any valid flat they count. No matter if you have only big single flat or 3 small with same free wall count.
So total possible chances for first picture are 3*26 = 78 for 2nd 3*3 = 9.
I think best way to compute it is the complementary probability. Will add some formula later.


I still have 2 questions:
1. Is the spawning related to the spawn of other npcs(mobs) or critters?
(we know the other way: npcs make more critter spawn and less mobs, but regarding spawn-rate[can be altered with potions and water/peace-candle] and max-spawn [which gets abused with duck-glitch] maybe there is a way to help npc-spawn?)
Can't tell for sure but didn't see any special. They should be unable to spawn if already 200 other NPC around. They won't spawn if other NPC looking for flat. The town NPC spawn (at least partly) in a given order. Some can only if other exist.



2. If the 2minute timer is per player, would it help to have more players?
for example in 3p+ run or you join your partner in 2player just as he accumulates the requirements to have your 'character'-timer spawn them immediately)
It should be server side and not per player. It's not a 'character'-timer. At one game instance it is shared among all characters and worlds (during play, at day). Against speed run rules I think but you can idle with any character on any world (in single player) for some time (or play some loot seeds). After this start your new world with new char (or continue with old). Build one small flat for Guide (assign him) and one big flat for merchant, get 50silver and the merchant can spawn in less than 2min game time. At this checkout interval you need to have 50 silver and the Guide icon in one flat.
For multiplayer someone with the accumulated requirements (e.g. 50 silver) can join shortly before this checkout happen at the server.


The spawn does not depend on how much 'npc-rest-blocks' there are in a house or world per se.
ye

The spawn does depend on how much backwalls (who are inside a valid house) and how high up in the world they are.
-backwalls without anything on top. backwalls with e.g. a torch on top don't count.
-not related to high (except world edges not allowed). Each world seed has a surface layer height. You can see this in game at the background wall you can't mine.
For some reasons this is reduced by one to the top.
upload_2019-8-9_23-21-25.png
In green is at above surface layer flat below is below surface layer flat.
Those random tiles are separated between those areas.
If a seed has a high surface layer, so the space in between top of the world/space and start of underground is small (less green blocks in picture) the chance a random tile of those is part of your flat (located above surface layer/in green area) is higher than a seed with a larger green area.
But in case your flat is below this green area e.g. a tree flat in underground the chance for spawn decrease with a higher surface layer. If upper part is smaller to lower is bigger and so the chance of a random tile part of your flat.

Cause a house has a maximum size, this makes it indirectly depend on number of houses in a world and therefore npc blocks.
Not sure if I understood you correct. It is independent of the number of houses. As long you have the same amount of walls (without stuff on it).

The algo does discriminate pyramid housing, but not tree or sky island housing.
Ye, if the random tile is a pyramid wall tile it has only a 25% chance to get checked if there is flat.
Tree flats (pyramid and any other) have a lower chance if located in underground (so not at surface in this green area of top picture).
Sky islands should be fine.

For unseeded: build as much housing as possible, as high as possible, with maximum backwalls and minimal furniture (workbench instead of tables) as you are comfortable with losing time with for other objective.
As written above height and flat count doesn't matter. Only above surface (green area in top picture) has a higher chance to get selected.
So you just need as many as possible background walls without anything on top. For the Guide you can build as simple you like, assign him to this flat.
If no flat has the Guide-icon at this 2min mark you need to wait another 2min.
For later NPC's you can reassign them to small flats. So maybe a good way to go is one large flat and some simple.
Optimal big flat size is a question which need to be answered. Every wall tile you add increases the spawn chances by a lower amount.


For seeded: you already have the run timed when you meet the requirements for merchant and demo, so you play with another char in another world before your actual run first so you to hit instant timing.
As long this is not against the rules :).
(But RNG still need to find flat wall tiles)
 
Chance/time calculation:

variables:
c...chance new NPC spawns (from 0 to 1)
w...number of walls placed in a valid flat without stuff on it
s...surface level
t...number of times those random tiles need to be checked, t/3 is time in seconds
T...waiting time in seconds (= t/3)

-----Summary------
Which time is needed until a new NPC spawned with chance 'c':
for above surface flat (at Wolfram|Alpha)
for below surface flat (at Wolfram|Alpha)

How high is the chance a new NPC spawned after waiting time 'T' (in seconds) or less
for above surface flat (at Wolfram|Alpha)
for below surface flat (at Wolfram|Alpha)

What is the mean waiting time for a new NPC?
above surface flat (at Wolfram|Alpha)
below surface flat (at Wolfram|Alpha)

change the variable values according to your flat & world seed. Those links are for small worlds only. All those times are after those 2min intervals. The new NPC need to be chosen at that time.

Update:
in case you have flat walls above and below surface or at other world size
mean waiting time m in seconds
chance after waiting T seconds
time to wait until having a chance of c


-----read below for more info----


----1) Chance----

example for small worlds

above surface:
possible tiles to check:
(4200-20)*(s-11) = 4180*(s-11)
(s-1 is the height of the green area in top picture)
number of chosen tiles in about 3 times in a second (afaik):
3*10^(-5) * (4200*1200) = 151.2
rounded up to 152
(and times 3 = 456 tiles/sec)

complementary probability, chance a random tile is not a free wall tile in a valid flat:

((4180*(s-11))-w) / (4180*(s-11)) = 1-w/(4180*(s-11))

chance this is the case for all 152 trials

(1-w/(4180*(s-11)) )^152

repeat it t times
((1-w/(4180*(s-11)) )^152) ^t
= chance no NPC spawned after t repetitions
But we want the chance he spawns, so 1-this

c = 1-( (1-w/(4180*(s-11)) )^152) ^t

to know how often it need to repeat we need to compute the logarithm of this.

t = log(1-c)/log( ((1-w/(4180*(s-11)) )^152) )

to get the time, we need to round up and divide by 3

time in sec :
T = roundUp( log(1-c)/log( ((1-w/(4180*(s-11)) )^152) ) ) /3

for easy use:
Formula for above surface at Wolfram|Alpha
and insert c,w,s
for 'c' 0.5 is a good value - means 50% chance NPC will spawn in this time or less.
's' you can get e.g. in Tedit.

example a common tree flat located above surface layer, chest & 1 chair remove + torch added could have those values:
seed has surface height 350
upload_2019-8-10_1-23-16.png

this flat has 15*5+3-8-1 = 69 possible walls
we want to know the time where in 50% of the cases a new NPC already went in. -> c=0.5

Calculation for above surface at Wolfram|Alpha
---> ~31.333 sec
To this time you need to add those 2min after the game checks if a new NPC can spawn.
So if you start a new game and manage to own 50 silver and the Guide is living in another flat in less than 2min than the merchant should spawn in about 2min 31sec or less in 50% of you trials.

If we want to know the chance after some time we use the formula from above.
With waiting time 'T' in seconds (t/3 = T):
c = 1-( (1-w/(4180*(s-11)) )^152)^(3*T)
or here the example:
Calculating the chance a new NPC spawned after a waiting time or faster for above surface flat at Wolfram|Alpha


-------------------------
below surface layer (below this green area)
possible tiles to check:
(4200-20)*(1200-20-s+1) = 4180*(1181-s)
number of chosen tiles:
1.5*10^(-5) * (4200*1200) = 75.6
rounded up to 76

now the same steps as above

c = 1-((1-w/(4180*(1181-s)) )^76) ^t

time in sec
T = roundUp( log(1-c)/log( ((1-w/(4180*(1181-s)) )^76) ) ) /3

for easy use, including the values for the same tree flat but assuming it is placed below surface layer/ in underground:

Calculation for below surface at Wolfram|Alpha
-->153.3 sec

For the chance after some waiting time T:
Calculating the chance a new NPC spawned after a waiting time or faster for below surface flat at Wolfram|Alpha

----2) mean waiting time--------
In first part we only computed the chance how likely it is the new NPC went in.
Even we computed it for 50% it is different to mean waiting time until he moved in.
It has a low chance but It can happen that no NPC went in even after a year of waiting.
So we need to sum up all possible waiting times with their chance.

probability he moving in at first 152 random tiles:
p = 1-(1-w/(4180*(s-11)) )^152
probability he does not:
q = 1-p
if that happen he has the same chance p at the next 152 tiles. only the count increased by one. So you can write the mean time as:
m = p* 1 + (1-p) * (1 + (p * 1 + (p-1) * (1+p*1....))
m = p*1 + (1-p) * (1 + m)
m = p + 1 + m -1 - p*m = p + m - p * m
divide by m
1 = 1/m+1+p
=>m = 1/p

those random tiles are chosen 3 times a second. To get the time in seconds we need to divide it by 3.

so the mean waiting time (in seconds) for flats above surface with 'w' free wall tiles at at small world with surfaces layer depth 's' is:
m = (1/( 1-(1-w/(4180*(s-11)) )^152 ))/3 seconds

or here with values from example above:
Calculation mean waiting time for new NPC for above surface at Wolfram|Alpha
So the mean waiting time for the example would be 45.2 sec.

for below surface it is:
m = (1/( 1-(1-w/(4180*(1181-s)) )^76))/3 seconds
or here with values from example:
Calculation mean waiting time for new NPC for blow surface at Wolfram|Alpha
In mean it will need 221 seconds.

Those are the mean times after the 2min interval.

------
For medium or large world change those worlds sizes 4200 & 1200
--
If you like you can do some tests if those calculated values are true in normal play.
No guarantee for correctness. I may missed something or misinterpreted it.
 
Last edited:
Thanks Unftf, you've been a huge help!
Also interested in this topic. Thank you for bringing up this idea.

Did some test. Made some small mod to do so.
test flat:
upload_2019-8-11_2-24-19.png

free walls: w = 4*13-4-1-2*2-6 = 37
surface layer: s = 346
above surface

expected values for my test case:
50% in 57.7 sec or less
in mean 83.1612 sec
Did 70 trials. In 34 of those the NPC went in before 57.7 sec. The mean time was 91 sec.
First the results looked a little off for the mean time. After checking the waiting time I noticed at one trial the NPC did not spawned at the first day. I subtracted night time (9min) from this value. After doing this I had a mean waiting time of 83.3955 sec. That is very close to the expected calculated value of 83.1612.
So chances are high at least for above surface those formula is correct.

(I only counted the waiting time after this 2min check up interval. So only the time which was needed to find the flat)

Edit:
Did some test for underground in same world:
walls=153
280 trials
calculated times:
mean: 100.219 sec
50%: 69.666.. sec
I got: mean 101.35 sec and 140 less than 69.666.
 
Last edited:
(here a short version of all written above)
Game checks every two minutes of daytime if a new NPC can settle in (no other NPC without flat and e.g. player has 50silver for merchant). This time is shared among all characters and worlds you play. It resets if you restart Terraria.
The waiting time after those 2min you can calculate with the following equations.
As more placed wall tiles any of your free flats have the faster a new NPC will spawn. If anything placed at top of this wall it won't count that wall.
The spawning chance is separated above and below surface.

variables:
T...waiting time in seconds
c...chance new NPC spawns (from 0 to 1)
a,b...number of walls placed in a valid flat without stuff on it, (a)bove and/or (b)elow surface
s...surface level
h...number of (h)orizontal world tiles: 4200(small), 6400(medium) or 8400(large)
v...number of (v)vertical world tiles: 1200(smal), 1800(medium), 2400(large)

(formula link at Wolfram Alpha)
mean waiting time m in seconds
chance after waiting T seconds
time to wait until having a chance of c
change the variable values according to your flat & world seed (at end of input line).

upload_2019-8-12_17-17-22.png


further notes:
-pyramid wall's only have 1/4 chance of spawning a new NPC
-wall tiles with more than a little water won't count
-underground flat is way slower than above
-seeds with higher surface level have a slightly higher chance for flat above surface level (but less below)

No guarantee for correctness. Recent tests showed those values are at least very close.
 
Last edited:
Back
Top Bottom