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

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

Fixes

File size: 1.6 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
[130]38 ItemBase item = null;
[128]39
[130]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 }
[128]45 }
46
[130]47 if (item == null) {
48 m_Console.SendResult ("Item not found.");
49 return;
50 }
[128]51
[130]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 }
[128]57
[130]58 EntityPlayer p = CommonMappingFunctions.GetEntityPlayer (ci);
59 CommonMappingFunctions.GetGameManager ().DropEntityItemServer (item.itemID, n, p.GetPosition (), Vector3.zero, Vector3.zero, 50, CommonMappingFunctions.GetEntityID (ci));
[128]60
[130]61 m_Console.SendResult ("Dropped item");
62 } catch (Exception e) {
63 Log.Out ("Error in Give.Run: " + e);
64 }
[128]65 }
66 }
67}
Note: See TracBrowser for help on using the repository browser.