source: binary-improvements/7dtd-server-fixes/src/TelnetCommands/ShowInventory.cs@ 105

Last change on this file since 105 was 103, checked in by alloc, 10 years ago

fixes

File size: 1.8 KB
RevLine 
[93]1using System;
2using System.Collections.Generic;
3
4public class ShowInventory : ConsoleCommand
5{
6 private GameManager manager;
7
8 public ShowInventory (ConsoleSdtd cons) : base(cons)
9 {
10 manager = m_Console.gameManager;
11 }
12
13 public override string Description ()
14 {
15 return "list inventory of a given player (entity id or name)";
16 }
17
18 public override string[] Names ()
19 {
20 return new string[] { "showinventory", "si" };
21 }
22
23 public override void Run (string[] _params)
24 {
[103]25 try {
26 if (_params.Length < 1) {
27 m_Console.md000a ("Usage: showinventory <playername|entityid>");
28 return;
29 }
[93]30
[103]31 int entityId = -1;
32 PlayerDataStuff.PlayerItems items = null;
33 if (int.TryParse (_params [0], out entityId)) {
34 items = PlayerDataStuff.GetPlayerItems (entityId);
35 }
[93]36
[103]37 if (items == null) {
38 string playerName = _params [0].ToLower ();
39 foreach (KeyValuePair<int, EntityPlayer> kvp in manager.World.playerEntities.dict) {
40 if (kvp.Value.EntityName.ToLower ().Equals (playerName)) {
41 entityId = kvp.Key;
42 break;
43 }
[93]44 }
45 }
[103]46 items = PlayerDataStuff.GetPlayerItems (entityId);
[93]47
[103]48 if (items == null) {
49 m_Console.md000a ("Playername or entity id not found or no inventory saved (first saved after a player has been online for 30s).");
50 return;
51 }
[93]52
[103]53 m_Console.md000a ("Belt of player:");
54 foreach (KeyValuePair<string, int> kvp in items.belt) {
55 m_Console.md000a (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));
56 }
57 m_Console.md000a (string.Empty);
58 m_Console.md000a ("Bagpack of player:");
59 foreach (KeyValuePair<string, int> kvp in items.bag) {
60 m_Console.md000a (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));
61 }
62 m_Console.md000a (string.Empty);
63 } catch (Exception e) {
64 Log.Out ("Error in ShowInventory.Run: " + e);
[93]65 }
66 }
67}
68
Note: See TracBrowser for help on using the repository browser.