source: binary-improvements/AllocsCommands/Commands/ShowInventory.cs@ 246

Last change on this file since 246 was 238, checked in by alloc, 9 years ago

Server fixes for A12

File size: 2.1 KB
RevLine 
[224]1using AllocsFixes.PersistentData;
2using System;
3using System.Collections.Generic;
4
5namespace AllocsFixes.CustomCommands
6{
[230]7 public class ShowInventory : ConsoleCmdAbstract
[224]8 {
[230]9 public override string GetDescription ()
[224]10 {
[238]11 return "list inventory of a given player";
[224]12 }
13
[238]14 public override string GetHelp () {
15 return "Usage:\n" +
16 " showinventory <steam id / player name / entity id>\n" +
17 "Show the inventory of the player given by his SteamID, player name or\n" +
18 "entity id (as given by e.g. \"lpi\")." +
19 "Note: This only shows the player's inventory after it was first sent to\n" +
20 "the server which happens at least every 30 seconds.";
21 }
22
[230]23 public override string[] GetCommands ()
[224]24 {
25 return new string[] { "showinventory", "si" };
26 }
27
[230]28 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
[224]29 {
30 try {
[230]31 if (_params.Count < 1) {
32 SdtdConsole.Instance.Output ("Usage: showinventory <steamid|playername|entityid>");
[224]33 return;
34 }
35
36 string steamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true);
37 if (steamid == null) {
[230]38 SdtdConsole.Instance.Output ("Playername or entity/steamid id not found or no inventory saved (first saved after a player has been online for 30s).");
[224]39 return;
40 }
41
[233]42 Player p = PersistentContainer.Instance.Players [steamid, false];
[224]43 PersistentData.Inventory inv = p.Inventory;
44
[230]45 SdtdConsole.Instance.Output ("Belt of player " + p.Name + ":");
[224]46 for (int i = 0; i < inv.belt.Count; i++) {
47 if (inv.belt [i] != null)
[230]48 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i, inv.belt [i].count, inv.belt [i].itemName));
[224]49 }
[230]50 SdtdConsole.Instance.Output (string.Empty);
51 SdtdConsole.Instance.Output ("Bagpack of player " + p.Name + ":");
[224]52 for (int i = 0; i < inv.bag.Count; i++) {
53 if (inv.bag [i] != null)
[230]54 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i, inv.bag [i].count, inv.bag [i].itemName));
[224]55 }
[230]56 SdtdConsole.Instance.Output (string.Empty);
[224]57 } catch (Exception e) {
58 Log.Out ("Error in ShowInventory.Run: " + e);
59 }
60 }
61 }
62}
Note: See TracBrowser for help on using the repository browser.