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
This commit is contained in:
White 2017-03-13 12:00:46 +10:30
parent 86c180c156
commit 90505435ba
2 changed files with 10 additions and 3 deletions

View file

@ -153,7 +153,14 @@ namespace TShockAPI
out spawnTileY); out spawnTileY);
int npcid = NPC.NewNPC(spawnTileX * 16, spawnTileY * 16, type, 0); int npcid = NPC.NewNPC(spawnTileX * 16, spawnTileY * 16, type, 0);
// This is for special slimes // This is for special slimes
Main.npc[npcid].SetDefaults(name); if (type == 1)
{
Main.npc[npcid].SetDefaults(name);
}
else
{
Main.npc[npcid].netDefaults(type);
}
} }
} }

View file

@ -420,9 +420,9 @@ namespace TShockAPI
for (int i = -17; i < Main.maxNPCTypes; i++) for (int i = -17; i < Main.maxNPCTypes; i++)
{ {
npc.netDefaults(i); npc.netDefaults(i);
if (npc.name.ToLower() == nameLower) if (npc.name.ToLower() == nameLower || npc.displayName.ToLower() == nameLower)
return new List<NPC> { npc }; return new List<NPC> { npc };
if (npc.name.ToLower().StartsWith(nameLower)) if (npc.name.ToLower().StartsWith(nameLower) || npc.displayName.ToLower().StartsWith(nameLower))
found.Add((NPC)npc.Clone()); found.Add((NPC)npc.Clone());
} }
return found; return found;