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

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

fixes

File size: 1.5 KB
RevLine 
[128]1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
[130]5namespace AllocsFixes.CustomCommands
[128]6{
[130]7 public class Give : ConsoleCommand
[128]8 {
[130]9 public Give (ConsoleSdtd cons) : base(cons)
10 {
11 }
[128]12
[130]13 public override string Description ()
14 {
15 return "give an item to a player (entity id or name)";
16 }
[128]17
[130]18 public override string[] Names ()
19 {
20 return new string[] { "give", string.Empty };
21 }
[128]22
[130]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 }
[128]30
[130]31 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], false);
[128]32
[130]33 if (ci == null) {
34 m_Console.SendResult ("Playername or entity id not found.");
35 return;
36 }
[128]37
[197]38 Nullable<ItemValue> iv = ItemList.Instance.GetItemValue(_params[1]);
39 if (iv == null) {
[130]40 m_Console.SendResult ("Item not found.");
41 return;
42 }
[128]43
[130]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 }
[128]49
[130]50 EntityPlayer p = CommonMappingFunctions.GetEntityPlayer (ci);
[197]51 CommonMappingFunctions.GetGameManager ().DropEntityItemServer ((int)iv.Value.rawData, n, p.GetPosition (), Vector3.zero, Vector3.zero, 50, CommonMappingFunctions.GetEntityID (ci));
[128]52
[130]53 m_Console.SendResult ("Dropped item");
54 } catch (Exception e) {
55 Log.Out ("Error in Give.Run: " + e);
56 }
[128]57 }
58 }
59}
Note: See TracBrowser for help on using the repository browser.