| [128] | 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using UnityEngine;
|
|---|
| 4 |
|
|---|
| 5 | public class Give : ConsoleCommand
|
|---|
| 6 | {
|
|---|
| 7 | public Give (ConsoleSdtd cons) : base(cons)
|
|---|
| 8 | {
|
|---|
| 9 | }
|
|---|
| 10 |
|
|---|
| 11 | public override string Description ()
|
|---|
| 12 | {
|
|---|
| 13 | return "give an item to a player (entity id or name)";
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | public override string[] Names ()
|
|---|
| 17 | {
|
|---|
| 18 | return new string[] { "give", string.Empty };
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | public override void Run (string[] _params)
|
|---|
| 22 | {
|
|---|
| 23 | try {
|
|---|
| 24 | if (_params.Length != 3) {
|
|---|
| 25 | m_Console.SendResult ("Usage: give <playername|entityid> <itemname> <amount>");
|
|---|
| 26 | return;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | ClientInfo ci = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], false);
|
|---|
| 30 |
|
|---|
| 31 | if (ci == null) {
|
|---|
| 32 | m_Console.SendResult ("Playername or entity id not found.");
|
|---|
| 33 | return;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | ItemBase item = null;
|
|---|
| 37 |
|
|---|
| 38 | foreach (ItemBase ib in ItemBase.list) {
|
|---|
| 39 | if (ib.name != null && ib.name.ToLower().Equals(_params[1].ToLower())) {
|
|---|
| 40 | item = ib;
|
|---|
| 41 | break;
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | if (item == null) {
|
|---|
| 46 | m_Console.SendResult ("Item not found.");
|
|---|
| 47 | return;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | int n = int.MinValue;
|
|---|
| 51 | if (!int.TryParse (_params [2], out n) || n <= 0) {
|
|---|
| 52 | m_Console.SendResult ("Amount is not an integer or not greater than zero.");
|
|---|
| 53 | return;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | EntityPlayer p = CommonMappingFunctions.GetEntityPlayer (ci);
|
|---|
| 57 | CommonMappingFunctions.GetGameManager().DropEntityItemServer(item.itemID, n, p.GetPosition(), Vector3.zero, Vector3.zero, 50, CommonMappingFunctions.GetEntityID(ci));
|
|---|
| 58 |
|
|---|
| 59 | m_Console.SendResult ("Dropped item");
|
|---|
| 60 | } catch (Exception e) {
|
|---|
| 61 | Log.Out ("Error in Give.Run: " + e);
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|