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

Last change on this file since 116 was 107, 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) {
[107]27 m_Console.SendResult ("Usage: showinventory <playername|entityid>");
[103]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) {
[107]49 m_Console.SendResult ("Playername or entity id not found or no inventory saved (first saved after a player has been online for 30s).");
[103]50 return;
51 }
[93]52
[107]53 m_Console.SendResult ("Belt of player:");
[103]54 foreach (KeyValuePair<string, int> kvp in items.belt) {
[107]55 m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));
[103]56 }
[107]57 m_Console.SendResult (string.Empty);
58 m_Console.SendResult ("Bagpack of player:");
[103]59 foreach (KeyValuePair<string, int> kvp in items.bag) {
[107]60 m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));
[103]61 }
[107]62 m_Console.SendResult (string.Empty);
[103]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.