private void NPCCommand(string[] args)
{
int type;
if (args.Length == 0 || !Int32.TryParse(args[0], out type))
{
Main.NewText("Usage: /npc type [x] [y] [number]");
Main.NewText("x and y may be preceded by ~ to use position relative to player");
return;
}
try
{
Player player = Main.LocalPlayer;
int x;
int y;
int num = 1;
if (args.Length > 2)
{
bool relativeX = false;
bool relativeY = false;
if (args[1][0] == '~')
{
relativeX = true;
args[1] = args[1].Substring(1);
}
if (args[2][0] == '~')
{
relativeY = true;
args[2] = args[2].Substring(1);
}
if (!Int32.TryParse(args[1], out x))
{
x = 0;
relativeX = true;
}
if (!Int32.TryParse(args[2], out y))
{
y = 0;
relativeY = true;
}
if (relativeX)
{
x += (int)player.Bottom.X;
}
if (relativeY)
{
y += (int)player.Bottom.Y;
}
if (args.Length > 3)
{
if (!Int32.TryParse(args[3], out num))
{
num = 1;
}
}
}
else
{
x = (int)player.Bottom.X;
y = (int)player.Bottom.Y;
}
for (int k = 0; k < num; k++)
{
if (Main.netMode == 0)
{
NPC.NewNPC(x, y, type);
}
else if (Main.netMode == 1)
{
var netMessage = GetPacket();
netMessage.Write((byte)ExampleModMessageType.SpawnNPC);
netMessage.Write(x);
netMessage.Write(y);
netMessage.Write(type);
netMessage.Send();
}
}
}
catch
{
Main.NewText("Usage: /npc type [x] [y] [number]");
Main.NewText("x and y may be preceded by ~ to use position relative to player");
}
}