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

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

Fixes

File size: 1.6 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 ItemBase item = null;
39
40 foreach (ItemBase ib in ItemBase.list) {
41 if (ib.name != null && ib.name.ToLower ().Equals (_params [1].ToLower ())) {
42 item = ib;
43 break;
44 }
45 }
46
47 if (item == null) {
48 m_Console.SendResult ("Item not found.");
49 return;
50 }
51
52 int n = int.MinValue;
53 if (!int.TryParse (_params [2], out n) || n <= 0) {
54 m_Console.SendResult ("Amount is not an integer or not greater than zero.");
55 return;
56 }
57
58 EntityPlayer p = CommonMappingFunctions.GetEntityPlayer (ci);
59 CommonMappingFunctions.GetGameManager ().DropEntityItemServer (item.itemID, n, p.GetPosition (), Vector3.zero, Vector3.zero, 50, CommonMappingFunctions.GetEntityID (ci));
60
61 m_Console.SendResult ("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.