Added support to spawn all types of slimes (have to use the full exact name)
Added SpawnNPC in TSServerPlayer Warn user if multiple mob with name are found
This commit is contained in:
parent
7bccfbe441
commit
51aa337839
4 changed files with 98 additions and 67 deletions
|
|
@ -291,19 +291,19 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
string plStr = args.Parameters[0];
|
string plStr = args.Parameters[0];
|
||||||
var player = Tools.FindPlayer(plStr);
|
var players = Tools.FindPlayer(plStr);
|
||||||
if (player.Count == 0)
|
if (players.Count == 0)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Invalid player!", Color.Red);
|
args.Player.SendMessage("Invalid player!", Color.Red);
|
||||||
}
|
}
|
||||||
else if (player.Count > 1)
|
else if (players.Count > 1)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("More than one player matched!", Color.Red);
|
args.Player.SendMessage("More than one player matched!", Color.Red);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string reason = args.Parameters.Count > 1 ? String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1)) : "Misbehaviour.";
|
string reason = args.Parameters.Count > 1 ? String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1)) : "Misbehaviour.";
|
||||||
if (!Tools.Kick(player[0], reason))
|
if (!Tools.Kick(players[0], reason))
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("You can't kick another admin!", Color.Red);
|
args.Player.SendMessage("You can't kick another admin!", Color.Red);
|
||||||
}
|
}
|
||||||
|
|
@ -324,19 +324,19 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
string plStr = args.Parameters[0];
|
string plStr = args.Parameters[0];
|
||||||
var player = Tools.FindPlayer(plStr);
|
var players = Tools.FindPlayer(plStr);
|
||||||
if (player.Count == 0)
|
if (players.Count == 0)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Invalid player!", Color.Red);
|
args.Player.SendMessage("Invalid player!", Color.Red);
|
||||||
}
|
}
|
||||||
else if (player.Count > 1)
|
else if (players.Count > 1)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("More than one player matched!", Color.Red);
|
args.Player.SendMessage("More than one player matched!", Color.Red);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string reason = args.Parameters.Count > 1 ? String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1)) : "Misbehaviour.";
|
string reason = args.Parameters.Count > 1 ? String.Join(" ", args.Parameters.GetRange(1, args.Parameters.Count - 1)) : "Misbehaviour.";
|
||||||
if (!Tools.Ban(player[0], reason))
|
if (!Tools.Ban(players[0], reason))
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("You can't ban another admin!", Color.Red);
|
args.Player.SendMessage("You can't ban another admin!", Color.Red);
|
||||||
}
|
}
|
||||||
|
|
@ -547,24 +547,43 @@ namespace TShockAPI
|
||||||
args.Player.SendMessage("Missing mob name/id", Color.Red);
|
args.Player.SendMessage("Missing mob name/id", Color.Red);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int type = -1;
|
|
||||||
int amount = 1;
|
int amount = 1;
|
||||||
|
|
||||||
if (!int.TryParse(args.Parameters[0], out type))
|
|
||||||
type = TShock.GetNPCID(args.Parameters[0]);
|
|
||||||
if (args.Parameters.Count == 2 && !int.TryParse(args.Parameters[1], out amount))
|
if (args.Parameters.Count == 2 && !int.TryParse(args.Parameters[1], out amount))
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Invalid syntax! Proper syntax: /spawnmob <mob name/id> [amount]", Color.Red);
|
args.Player.SendMessage("Invalid syntax! Proper syntax: /spawnmob <mob name/id> [amount]", Color.Red);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type >= 1 && type < Main.maxNPCTypes)
|
NPC npc;
|
||||||
|
int type = -1;
|
||||||
|
if (int.TryParse(args.Parameters[0], out type))
|
||||||
{
|
{
|
||||||
int npcid = -1;
|
npc = Tools.GetNPCById(type);
|
||||||
for (int i = 0; i < amount; i++)
|
}
|
||||||
npcid = NPC.NewNPC((int)args.Player.X, (int)args.Player.Y, type, 0);
|
else
|
||||||
Tools.Broadcast(string.Format("{0} was spawned {1} time(s).", Main.npc[npcid].name, amount));
|
{
|
||||||
|
var npcs = Tools.GetNPCByName(args.Parameters[0]);
|
||||||
|
if (npcs.Count == 0)
|
||||||
|
{
|
||||||
|
args.Player.SendMessage("Invalid mob type!", Color.Red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (npcs.Count > 1)
|
||||||
|
{
|
||||||
|
args.Player.SendMessage("More than one mob matched!", Color.Red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
npc = npcs[0];
|
||||||
|
type = npc.type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (npc.type >= 1 && npc.type < Main.maxNPCTypes)
|
||||||
|
{
|
||||||
|
TSPlayer.Server.SpawnNPC(npc.type, npc.name, (int)args.Player.X, (int)args.Player.Y);
|
||||||
|
Tools.Broadcast(string.Format("{0} was spawned {1} time(s).", npc.name, amount));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
args.Player.SendMessage("Invalid mob type!", Color.Red);
|
args.Player.SendMessage("Invalid mob type!", Color.Red);
|
||||||
|
|
@ -597,14 +616,14 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
string plStr = String.Join(" ", args.Parameters);
|
string plStr = String.Join(" ", args.Parameters);
|
||||||
var player = Tools.FindPlayer(plStr);
|
var players = Tools.FindPlayer(plStr);
|
||||||
if (player.Count == 0)
|
if (players.Count == 0)
|
||||||
args.Player.SendMessage("Invalid player!", Color.Red);
|
args.Player.SendMessage("Invalid player!", Color.Red);
|
||||||
else if (player.Count > 1)
|
else if (players.Count > 1)
|
||||||
args.Player.SendMessage("More than one player matched!", Color.Red);
|
args.Player.SendMessage("More than one player matched!", Color.Red);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var plr = player[0];
|
var plr = players[0];
|
||||||
TShock.Teleport(args.Player.Index, plr.X, plr.Y);
|
TShock.Teleport(args.Player.Index, plr.X, plr.Y);
|
||||||
args.Player.SendMessage(string.Format("Teleported to {0}", plr.Name));
|
args.Player.SendMessage(string.Format("Teleported to {0}", plr.Name));
|
||||||
}
|
}
|
||||||
|
|
@ -619,18 +638,18 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
string plStr = String.Join(" ", args.Parameters);
|
string plStr = String.Join(" ", args.Parameters);
|
||||||
var player = Tools.FindPlayer(plStr);
|
var players = Tools.FindPlayer(plStr);
|
||||||
if (player.Count == 0)
|
if (players.Count == 0)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Invalid player!", Color.Red);
|
args.Player.SendMessage("Invalid player!", Color.Red);
|
||||||
}
|
}
|
||||||
else if (player.Count > 1)
|
else if (players.Count > 1)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("More than one player matched!", Color.Red);
|
args.Player.SendMessage("More than one player matched!", Color.Red);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var plr = player[0];
|
var plr = players[0];
|
||||||
TShock.Teleport(plr.Index, args.Player.X, args.Player.Y);
|
TShock.Teleport(plr.Index, args.Player.X, args.Player.Y);
|
||||||
plr.SendMessage(string.Format("You were teleported to {0}.", plr.Name));
|
plr.SendMessage(string.Format("You were teleported to {0}.", plr.Name));
|
||||||
args.Player.SendMessage(string.Format("You brought {0} here.", plr.Name));
|
args.Player.SendMessage(string.Format("You brought {0} here.", plr.Name));
|
||||||
|
|
@ -878,18 +897,18 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
string plStr = args.Parameters[0];
|
string plStr = args.Parameters[0];
|
||||||
var player = Tools.FindPlayer(plStr);
|
var players = Tools.FindPlayer(plStr);
|
||||||
if (player.Count == 0)
|
if (players.Count == 0)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Invalid player!", Color.Red);
|
args.Player.SendMessage("Invalid player!", Color.Red);
|
||||||
}
|
}
|
||||||
else if (player.Count > 1)
|
else if (players.Count > 1)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("More than one player matched!", Color.Red);
|
args.Player.SendMessage("More than one player matched!", Color.Red);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var plr = player[0];
|
var plr = players[0];
|
||||||
int damage = 5;
|
int damage = 5;
|
||||||
if (args.Parameters.Count == 2)
|
if (args.Parameters.Count == 2)
|
||||||
{
|
{
|
||||||
|
|
@ -910,18 +929,18 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
string plStr = String.Join(" ", args.Parameters);
|
string plStr = String.Join(" ", args.Parameters);
|
||||||
var player = Tools.FindPlayer(plStr);
|
var players = Tools.FindPlayer(plStr);
|
||||||
if (player.Count == 0)
|
if (players.Count == 0)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Invalid player!", Color.Red);
|
args.Player.SendMessage("Invalid player!", Color.Red);
|
||||||
}
|
}
|
||||||
else if (player.Count > 1)
|
else if (players.Count > 1)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("More than one player matched!", Color.Red);
|
args.Player.SendMessage("More than one player matched!", Color.Red);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var plr = player[0];
|
var plr = players[0];
|
||||||
plr.DamagePlayer(999999);
|
plr.DamagePlayer(999999);
|
||||||
args.Player.SendMessage(string.Format("You just killed {0}!", plr.Name));
|
args.Player.SendMessage(string.Format("You just killed {0}!", plr.Name));
|
||||||
plr.SendMessage(string.Format("{0} just killed you!", args.Player.Name));
|
plr.SendMessage(string.Format("{0} just killed you!", args.Player.Name));
|
||||||
|
|
@ -1019,18 +1038,18 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
string plStr = args.Parameters[1];
|
string plStr = args.Parameters[1];
|
||||||
var player = Tools.FindPlayer(plStr);
|
var players = Tools.FindPlayer(plStr);
|
||||||
if (player.Count == 0)
|
if (players.Count == 0)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Invalid player!", Color.Red);
|
args.Player.SendMessage("Invalid player!", Color.Red);
|
||||||
}
|
}
|
||||||
else if (player.Count > 1)
|
else if (players.Count > 1)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("More than one player matched!", Color.Red);
|
args.Player.SendMessage("More than one player matched!", Color.Red);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var plr = player[0];
|
var plr = players[0];
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
for (int i = 0; i < 40; i++)
|
for (int i = 0; i < 40; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -1057,18 +1076,18 @@ namespace TShockAPI
|
||||||
if (args.Parameters.Count > 0)
|
if (args.Parameters.Count > 0)
|
||||||
{
|
{
|
||||||
string plStr = String.Join(" ", args.Parameters);
|
string plStr = String.Join(" ", args.Parameters);
|
||||||
var player = Tools.FindPlayer(plStr);
|
var players = Tools.FindPlayer(plStr);
|
||||||
if (player.Count == 0)
|
if (players.Count == 0)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("Invalid player!", Color.Red);
|
args.Player.SendMessage("Invalid player!", Color.Red);
|
||||||
}
|
}
|
||||||
else if (player.Count > 1)
|
else if (players.Count > 1)
|
||||||
{
|
{
|
||||||
args.Player.SendMessage("More than one player matched!", Color.Red);
|
args.Player.SendMessage("More than one player matched!", Color.Red);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var plr = player[0];
|
var plr = players[0];
|
||||||
DropHearts(plr.X, plr.Y, 20);
|
DropHearts(plr.X, plr.Y, 20);
|
||||||
if (plr == args.Player)
|
if (plr == args.Player)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,14 @@ namespace TShockAPI
|
||||||
NetMessage.syncPlayers();
|
NetMessage.syncPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int SpawnNPC(int type, string name, int x, int y)
|
||||||
|
{
|
||||||
|
int npcid = NPC.NewNPC(x, y, type, 0);
|
||||||
|
// This is for special slimes
|
||||||
|
Main.npc[npcid].SetDefaults(name);
|
||||||
|
return npcid;
|
||||||
|
}
|
||||||
|
|
||||||
public void StrikeNPC(int npcid, int damage, float knockBack, int hitDirection)
|
public void StrikeNPC(int npcid, int damage, float knockBack, int hitDirection)
|
||||||
{
|
{
|
||||||
Main.npc[npcid].StrikeNPC(damage, knockBack, hitDirection);
|
Main.npc[npcid].StrikeNPC(damage, knockBack, hitDirection);
|
||||||
|
|
|
||||||
|
|
@ -464,31 +464,6 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO : Notify the player if there is more than one match. (or do we want a First() kinda thing?)
|
|
||||||
public static int GetNPCID(string name, bool exact = false)
|
|
||||||
{
|
|
||||||
NPC npc = new NPC();
|
|
||||||
for (int i = 1; i < Main.maxNPCTypes; i++)
|
|
||||||
{
|
|
||||||
if (exact)
|
|
||||||
{
|
|
||||||
//Method #1 - must be exact match, allows support for different coloured slimes
|
|
||||||
npc.SetDefaults(name);
|
|
||||||
if (npc.name == name)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//Method #2 - allows impartial matching
|
|
||||||
name = name.ToLower();
|
|
||||||
npc.SetDefaults(i);
|
|
||||||
if (npc.name.ToLower().StartsWith(name))
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int GetItemID(string name)
|
public static int GetItemID(string name)
|
||||||
{
|
{
|
||||||
Item item = new Item();
|
Item item = new Item();
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,35 @@ namespace TShockAPI
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static NPC GetNPCById(int id)
|
||||||
|
{
|
||||||
|
NPC npc = new NPC();
|
||||||
|
npc.SetDefaults(id);
|
||||||
|
return npc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<NPC> GetNPCByName(string name)
|
||||||
|
{
|
||||||
|
//Method #1 - must be exact match, allows support for different coloured slimes
|
||||||
|
for (int i = 1; i < Main.maxNPCTypes; i++)
|
||||||
|
{
|
||||||
|
NPC npc = new NPC();
|
||||||
|
npc.SetDefaults(name);
|
||||||
|
if (npc.name == name)
|
||||||
|
return new List<NPC> { npc };
|
||||||
|
}
|
||||||
|
//Method #2 - allows impartial matching
|
||||||
|
var found = new List<NPC>();
|
||||||
|
for (int i = 1; i < Main.maxNPCTypes; i++)
|
||||||
|
{
|
||||||
|
NPC npc = new NPC();
|
||||||
|
npc.SetDefaults(i);
|
||||||
|
if (npc.name.ToLower().StartsWith(name.ToLower()))
|
||||||
|
found.Add(npc);
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an NPC
|
/// Creates an NPC
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue