source: binary-improvements/AllocsCommands/Commands/Give.cs@ 235

Last change on this file since 235 was 230, checked in by alloc, 10 years ago

Binary improvements

File size: 1.5 KB
RevLine 
[224]1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5namespace AllocsFixes.CustomCommands
6{
[230]7 public class Give : ConsoleCmdAbstract
[224]8 {
[230]9 public override string GetDescription ()
[224]10 {
11 return "give an item to a player (entity id or name)";
12 }
13
[230]14 public override string[] GetCommands ()
[224]15 {
16 return new string[] { "give", string.Empty };
17 }
18
[230]19 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
[224]20 {
21 try {
[230]22 if (_params.Count != 3) {
23 SdtdConsole.Instance.Output ("Usage: give <playername|entityid> <itemname> <amount>");
[224]24 return;
25 }
26
[230]27 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
[224]28
29 if (ci == null) {
[230]30 SdtdConsole.Instance.Output ("Playername or entity id not found.");
[224]31 return;
32 }
33
[230]34 ItemValue iv = ItemList.Instance.GetItemValue (_params[1]);
[224]35 if (iv == null) {
[230]36 SdtdConsole.Instance.Output ("Item not found.");
[224]37 return;
38 }
39
40 int n = int.MinValue;
41 if (!int.TryParse (_params [2], out n) || n <= 0) {
[230]42 SdtdConsole.Instance.Output ("Amount is not an integer or not greater than zero.");
[224]43 return;
44 }
45
[230]46 EntityPlayer p = GameManager.Instance.World.Players.dict [ci.entityId];
[224]47
48 InventoryField invField = new InventoryField (iv, n);
49
[230]50 GameManager.Instance.ItemDropServer (invField, p.GetPosition (), Vector3.zero, -1, 50);
[224]51
[230]52 SdtdConsole.Instance.Output ("Dropped item");
[224]53 } catch (Exception e) {
54 Log.Out ("Error in Give.Run: " + e);
55 }
56 }
57 }
58}
Note: See TracBrowser for help on using the repository browser.