Added the DebugConsole.SpawnItem command from the dev branch (spawning items in the inventory of a character other than the controlled one works now).
This commit is contained in:
@@ -2119,23 +2119,48 @@ namespace Barotrauma
|
|||||||
Vector2? spawnPos = null;
|
Vector2? spawnPos = null;
|
||||||
Inventory spawnInventory = null;
|
Inventory spawnInventory = null;
|
||||||
|
|
||||||
int extraParams = 0;
|
if (args.Length > 1)
|
||||||
switch (args.Last())
|
|
||||||
{
|
{
|
||||||
case "cursor":
|
switch (args[1])
|
||||||
extraParams = 1;
|
{
|
||||||
spawnPos = cursorPos;
|
case "cursor":
|
||||||
break;
|
spawnPos = cursorPos;
|
||||||
case "inventory":
|
break;
|
||||||
extraParams = 1;
|
case "inventory":
|
||||||
spawnInventory = controlledCharacter == null ? null : controlledCharacter.Inventory;
|
spawnInventory = controlledCharacter?.Inventory;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
extraParams = 0;
|
//Check if last arg matches the name of an in-game player
|
||||||
break;
|
if (GameMain.Server != null)
|
||||||
|
{
|
||||||
|
var client = GameMain.Server.ConnectedClients.Find(c => c.Name.ToLower() == args.Last().ToLower());
|
||||||
|
if (client == null)
|
||||||
|
{
|
||||||
|
NewMessage("No player found with the name \"" + args.Last() + "\". Spawning item at random location. If the player you want to give the item to has a space in their name, try surrounding their name with quotes (\").", Color.Red);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (client.Character == null)
|
||||||
|
{
|
||||||
|
errorMsg = "The player \"" + args.Last() + "\" is connected, but hasn't spawned yet.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//If the last arg matches the name of an in-game player, set the destination to their inventory.
|
||||||
|
spawnInventory = client.Character.Inventory;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var matchingCharacter = FindMatchingCharacter(args.Skip(1).ToArray());
|
||||||
|
if (matchingCharacter?.Inventory != null) spawnInventory = matchingCharacter.Inventory;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string itemName = string.Join(" ", args.Take(args.Length - extraParams)).ToLowerInvariant();
|
string itemName = args[0];
|
||||||
|
|
||||||
var itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab;
|
var itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab;
|
||||||
if (itemPrefab == null)
|
if (itemPrefab == null)
|
||||||
@@ -2153,7 +2178,6 @@ namespace Barotrauma
|
|||||||
if (spawnPos != null)
|
if (spawnPos != null)
|
||||||
{
|
{
|
||||||
Entity.Spawner.AddToSpawnQueue(itemPrefab, (Vector2)spawnPos);
|
Entity.Spawner.AddToSpawnQueue(itemPrefab, (Vector2)spawnPos);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (spawnInventory != null)
|
else if (spawnInventory != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user