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
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
[238]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
[230]23 public override string[] GetCommands ()
[224]24 {
25 return new string[] { "give", string.Empty };
26 }
27
[230]28 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
[224]29 {
30 try {
[230]31 if (_params.Count != 3) {
[238]32 SdtdConsole.Instance.Output ("Wrong number of arguments, expected 3, found " + _params.Count + ".");
[224]33 return;
34 }
35
[230]36 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
[224]37
38 if (ci == null) {
[230]39 SdtdConsole.Instance.Output ("Playername or entity id not found.");
[224]40 return;
41 }
42
[230]43 ItemValue iv = ItemList.Instance.GetItemValue (_params[1]);
[224]44 if (iv == null) {
[230]45 SdtdConsole.Instance.Output ("Item not found.");
[224]46 return;
47 }
48
49 int n = int.MinValue;
50 if (!int.TryParse (_params [2], out n) || n <= 0) {
[230]51 SdtdConsole.Instance.Output ("Amount is not an integer or not greater than zero.");
[224]52 return;
53 }
54
[230]55 EntityPlayer p = GameManager.Instance.World.Players.dict [ci.entityId];
[224]56
[238]57 ItemStack invField = new ItemStack (iv, n);
[224]58
[230]59 GameManager.Instance.ItemDropServer (invField, p.GetPosition (), Vector3.zero, -1, 50);
[224]60
[230]61 SdtdConsole.Instance.Output ("Dropped item");
[224]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.