source: binary-improvements/7dtd-server-fixes/src/CustomCommands/ShowInventory.cs@ 131

Last change on this file since 131 was 130, checked in by alloc, 10 years ago

Fixes

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