Repository navigation
[Mod] Npc spawning with chat commands
Blake-The-Terraria-Modder edited this page Aug 20, 2011
·
2 revisions
Inside of your onChat function add this
try
{
if (text.Substring(0, 1) == "/")
{
var command = text.Substring(1, text.IndexOf(' ') - 1);
if (command == "spawn")
{
var parameter = text.Substring(text.IndexOf(' ') + 1);
if (parameter == "skeletron")
{
int num70 = NPC.NewNPC((int)Main.player[Main.myPlayer].position.X,
(int)Main.player[Main.myPlayer].position.Y, 0x23, 0);
Main.npc[num70].netUpdate = true;
string str = "Skeletron";
if (Main.netMode == 0)
{
Main.NewText(str + " has awoken!", 0xaf, 0x4b, 0xff);
}
else if (Main.netMode == 2 || Main.netMode == 1)
{
NetMessage.SendData(0x19, -1, -1, "", 0xff, 175f, 75f, 255f);
}
}
return false;
}
}
catch (Exception)
{
return false;
}
return true;
That will make it so if you type "/spawn skeletron" it will spawn a skeletron, and it does work in multiplayer. If you want to add more monsters to spawn just create another if statement inside of the "spawn" if using the if block for skeletron as a template. For a different monster edit this line:
int num70 = NPC.NewNPC((int)Main.player[Main.myPlayer].position.X,
(int)Main.player[Main.myPlayer].position.Y, 0x23, 0);
Change the 3rd parameter (0x23) to the ID of the NPC, which you can find by searching for it in NPC.cs
example for adding:
//spawns Eye of Cthulhu
else if (parameter == "eye")
{
int num70 = NPC.NewNPC((int)Main.player[Main.myPlayer].position.X,
(int)Main.player[Main.myPlayer].position.Y, 4, 0);
Main.npc[num70].netUpdate = true;
string str = "Cthulhu";
if (Main.netMode == 0)
{
Main.NewText(str + " has awoken!", 0xaf, 0x4b, 0xff);
}
else if (Main.netMode == 2 || Main.netMode == 1)
{
NetMessage.SendData(0x19, -1, -1, "", 0xff, 175f, 75f, 255f);
}
}
Add this after the "skeletron" if block, this spawn an Eye of Cthulhu if you type "/spawn eye"
This also works if you want to spawn a meteor but the code is a bit different, so if you want to spawn a meteor (In single player only I think) goto the meteor spawn wiki.