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
Line 
1using AllocsFixes.PersistentData;
2using System;
3using System.Collections.Generic;
4
5namespace AllocsFixes.CustomCommands
6{
7 public class ShowInventory : ConsoleCmdAbstract
8 {
9 public override string GetDescription ()
10 {
11 return "list inventory of a given player";
12 }
13
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
23 public override string[] GetCommands ()
24 {
25 return new string[] { "showinventory", "si" };
26 }
27
28 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
29 {
30 try {
31 if (_params.Count < 1) {
32 SdtdConsole.Instance.Output ("Usage: showinventory <steamid|playername|entityid>");
33 return;
34 }
35
36 string steamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true);
37 if (steamid == null) {
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).");
39 return;
40 }
41
42 Player p = PersistentContainer.Instance.Players [steamid, false];
43 PersistentData.Inventory inv = p.Inventory;
44
45 SdtdConsole.Instance.Output ("Belt of player " + p.Name + ":");
46 for (int i = 0; i < inv.belt.Count; i++) {
47 if (inv.belt [i] != null)
48 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i, inv.belt [i].count, inv.belt [i].itemName));
49 }
50 SdtdConsole.Instance.Output (string.Empty);
51 SdtdConsole.Instance.Output ("Bagpack of player " + p.Name + ":");
52 for (int i = 0; i < inv.bag.Count; i++) {
53 if (inv.bag [i] != null)
54 SdtdConsole.Instance.Output (string.Format (" Slot {0}: {1:000} * {2}", i, inv.bag [i].count, inv.bag [i].itemName));
55 }
56 SdtdConsole.Instance.Output (string.Empty);
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.