PC Enemy spawn area with sniper scope?

I don't think its changed by just having it equipped (i know so because of my pumpkin moon arena) i think it changes the spawn area when you are looking around with the scope.
 
I haven't tested it but the wiki says: "Having a Sniper Scope equipped, even if you aren't zoomed out, drastically increases the mob spawning rectangle".
 
I always thought it moved the spawn area, keeping the center of the screen in the center of the spawn area. That's what I've heard, at least.
 
This might be outdated, but back in one of the very early 1.3 releases I remember I used to make use of the sniper scope's zoom to force NPC spawns below me in my chaos elementals farm. Either way, your best way to test it out is probably build a fairly high enough platform (high enough so that the ground is at the edge of your screen), then use the scope to look up for a few second and check whether the area below gets filled up with spawns. If the spawn area follows the camera, then it should.
 
tl;dr version: with just a sniper scope, spawn area is 228x126

Relevant pieces of code(if my files are correct) seems to be
Code:
public static int sWidth = 1920;
public static int sHeight = 1080;
private static int spawnRangeX = (int) ((double) (NPC.sWidth / 16) * 0.7);
private static int spawnRangeY = (int) ((double) (NPC.sHeight / 16) * 0.7);
public static int safeRangeX = (int) ((double) (NPC.sWidth / 16) * 0.52);
public static int safeRangeY = (int) ((double) (NPC.sHeight / 16) * 0.52);
Code:
if (Main.player[plr].inventory[Main.player[plr].selectedItem].type == 1254 || Main.player[plr].inventory[Main.player[plr].selectedItem].type == 1299 || Main.player[plr].scope)
{
float num3 = 1.5f;
if (Main.player[plr].inventory[Main.player[plr].selectedItem].type == 1254 && Main.player[plr].scope)
  num3 = 1.25f;
else if (Main.player[plr].inventory[Main.player[plr].selectedItem].type == 1254)
  num3 = 1.5f;
else if (Main.player[plr].inventory[Main.player[plr].selectedItem].type == 1299)
  num3 = 1.5f;
else if (Main.player[plr].scope)
  num3 = 2f;
NPC.spawnRangeX += (int) ((double) (NPC.sWidth / 16) * 0.5 / (double) num3);
NPC.spawnRangeY += (int) ((double) (NPC.sHeight / 16) * 0.5 / (double) num3);
NPC.safeRangeX += (int) ((double) (NPC.sWidth / 16) * 0.5 / (double) num3);
NPC.safeRangeY += (int) ((double) (NPC.sHeight / 16) * 0.5 / (double) num3);
}
item id 1254 is sniper rifle, 1299 is binoculars
Scope is rifle or sniper scope, but only if selected weapon uses bullets as ammo, or candy corn, or oddly enough gel. Who knew flamethrower was a precision weapon?
Spawn area goes from -spawnRange to +spawnRange.
With just a sniper scope spawn area is extended by 30 blocks horizontally in both directions, and by 16 blocks vertically in both directions.
(84+30)*2=228
(47+16)*2=126
So, with just a sniper scope, spawn area is 228x126
Afaik it's counted from the top left block the player character sprite occupies.
Hope that helps and I didn't mess up anything
P.S. Afaik casting to integer drops non integer part, aka rounds down
P.P.S. Didn't test in-game

edit: I guess spawn area is technically 1 less on the right and bottom sides, because random function used works that way, so it's technically (player position - spawn range) to (player position + spawn range - 1). But I don't recall at which position mobs are spawned, so maybe their width height accounts for that? Kind of minor but figured I'd edit it in anyway.
 
Last edited:
Thanks! This what exactly what i was looking for, i will test this in-game, btw how can you see the code?
 
Last edited:
btw how can you see the code?
Well, first, you acknowledge/ignore any legal issues with reverse engineering. Then you find a good enough decompiler, feed it the binaries and hope it works and doesn't take two days just to produce out of memory error(haven't tried personally, might be exaggerated). Or you google terraria source and hope whoever did step two didn't alter the code(that's what I'm definitely(*cough*legalities*cough*)not not not doing). A possible third step is noticing that decompiler failed to decompile a certain function, getting source for older version and having to verify things in-game if you recall them being changed recently(although it's always useful to verify, code can be tricky).
 
I've done some testing in-game and i confirm that with the scope equipped (even if you don't zoom out) the spawn area expands from 168x94 to 228x128, also the safe area expands from 124x70 to 184x104.
 
Last edited:
Back
Top Bottom