From 90505435bafefac46b50dee49513fc48d96530de Mon Sep 17 00:00:00 2001 From: White Date: Mon, 13 Mar 2017 12:00:46 +1030 Subject: [PATCH] Improved NPC spawning functionality via `/sm`. Display names can now be used to find NPCs. Spawning by ID should now spawn unique NPCs, when multiple NPCs share the same name. Closes #1383 --- TShockAPI/TSServerPlayer.cs | 9 ++++++++- TShockAPI/Utils.cs | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/TShockAPI/TSServerPlayer.cs b/TShockAPI/TSServerPlayer.cs index 94036b96..b155bf53 100644 --- a/TShockAPI/TSServerPlayer.cs +++ b/TShockAPI/TSServerPlayer.cs @@ -153,7 +153,14 @@ namespace TShockAPI out spawnTileY); int npcid = NPC.NewNPC(spawnTileX * 16, spawnTileY * 16, type, 0); // This is for special slimes - Main.npc[npcid].SetDefaults(name); + if (type == 1) + { + Main.npc[npcid].SetDefaults(name); + } + else + { + Main.npc[npcid].netDefaults(type); + } } } diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 34d9d20d..0dd94d71 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -420,9 +420,9 @@ namespace TShockAPI for (int i = -17; i < Main.maxNPCTypes; i++) { npc.netDefaults(i); - if (npc.name.ToLower() == nameLower) + if (npc.name.ToLower() == nameLower || npc.displayName.ToLower() == nameLower) return new List { npc }; - if (npc.name.ToLower().StartsWith(nameLower)) + if (npc.name.ToLower().StartsWith(nameLower) || npc.displayName.ToLower().StartsWith(nameLower)) found.Add((NPC)npc.Clone()); } return found;