source: binary-improvements/7dtd-server-fixes/src/CustomCommands/Give.cs@ 218

Last change on this file since 218 was 197, checked in by alloc, 10 years ago

fixes

File size: 1.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5namespace AllocsFixes.CustomCommands
6{
7 public class Give : ConsoleCommand
8 {
9 public Give (ConsoleSdtd cons) : base(cons)
10 {
11 }
12
13 public override string Description ()
14 {
15 return "give an item to a player (entity id or name)";
16 }
17
18 public override string[] Names ()
19 {
20 return new string[] { "give", string.Empty };
21 }
22
23 public override void Run (string[] _params)
24 {
25 try {
26 if (_params.Length != 3) {
27 m_Console.SendResult ("Usage: give <playername|entityid> <itemname> <amount>");
28 return;
29 }
30
31 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], false);
32
33 if (ci == null) {
34 m_Console.SendResult ("Playername or entity id not found.");
35 return;
36 }
37
38 Nullable<ItemValue> iv = ItemList.Instance.GetItemValue(_params[1]);
39 if (iv == null) {
40 m_Console.SendResult ("Item not found.");
41 return;
42 }
43
44 int n = int.MinValue;
45 if (!int.TryParse (_params [2], out n) || n <= 0) {
46 m_Console.SendResult ("Amount is not an integer or not greater than zero.");
47 return;
48 }
49
50 EntityPlayer p = CommonMappingFunctions.GetEntityPlayer (ci);
51 CommonMappingFunctions.GetGameManager ().DropEntityItemServer ((int)iv.Value.rawData, n, p.GetPosition (), Vector3.zero, Vector3.zero, 50, CommonMappingFunctions.GetEntityID (ci));
52
53 m_Console.SendResult ("Dropped item");
54 } catch (Exception e) {
55 Log.Out ("Error in Give.Run: " + e);
56 }
57 }
58 }
59}
Note: See TracBrowser for help on using the repository browser.