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

Last change on this file since 243 was 238, checked in by alloc, 9 years ago

Server fixes for A12

File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5namespace AllocsFixes.CustomCommands
6{
7 public class Give : ConsoleCmdAbstract
8 {
9 public override string GetDescription ()
10 {
11 return "give an item to a player (entity id or name)";
12 }
13
14 public override string GetHelp () {
15 return "Give an item to a player by dropping it in front of that player\n" +
16 "Usage:\n" +
17 " give <name / entity id> <item name> <amount>\n" +
18 "Either pass the full name of a player or his entity id (given by e.g. \"lpi\").\n" +
19 "Item name has to be the exact name of an item as listed by \"listitems\".\n" +
20 "Amount is the number of instances of this item to drop (as a single stack).";
21 }
22
23 public override string[] GetCommands ()
24 {
25 return new string[] { "give", string.Empty };
26 }
27
28 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
29 {
30 try {
31 if (_params.Count != 3) {
32 SdtdConsole.Instance.Output ("Wrong number of arguments, expected 3, found " + _params.Count + ".");
33 return;
34 }
35
36 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
37
38 if (ci == null) {
39 SdtdConsole.Instance.Output ("Playername or entity id not found.");
40 return;
41 }
42
43 ItemValue iv = ItemList.Instance.GetItemValue (_params[1]);
44 if (iv == null) {
45 SdtdConsole.Instance.Output ("Item not found.");
46 return;
47 }
48
49 int n = int.MinValue;
50 if (!int.TryParse (_params [2], out n) || n <= 0) {
51 SdtdConsole.Instance.Output ("Amount is not an integer or not greater than zero.");
52 return;
53 }
54
55 EntityPlayer p = GameManager.Instance.World.Players.dict [ci.entityId];
56
57 ItemStack invField = new ItemStack (iv, n);
58
59 GameManager.Instance.ItemDropServer (invField, p.GetPosition (), Vector3.zero, -1, 50);
60
61 SdtdConsole.Instance.Output ("Dropped item");
62 } catch (Exception e) {
63 Log.Out ("Error in Give.Run: " + e);
64 }
65 }
66 }
67}
Note: See TracBrowser for help on using the repository browser.