source: binary-improvements/CoppisAdditions/src/Commands/SpawnHorde.cs@ 277

Last change on this file since 277 was 273, checked in by alloc, 9 years ago

fixes 8_10_13_1

File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Threading;
4using UnityEngine;
5
6namespace CoppisAdditions.CustomCommands
7{
8 public class SpawnHorde : ConsoleCmdAbstract
9 {
10 public override string GetDescription ()
11 {
12 return "spawn horde near a player or coordinate";
13 }
14
15 public override string GetHelp ()
16 {
17 return "Spawn horde near a player." +
18 "Usage:\n" +
19 " sh <steam id/player name/entity id>\n" +
20 "or" +
21 " sh <x> <y> <z>\n";
22 }
23
24 public override string[] GetCommands ()
25 {
26 return new string[] { "spawnhorde", "sh" };
27 }
28
29 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
30 {
31 try {
32 if (_params.Count != 1 && _params.Count != 3) {
33 SdtdConsole.Instance.Output ("Wrong number of arguments, expected 1 or 3, found " + _params.Count + ".");
34 SdtdConsole.Instance.Output (" ");
35 SdtdConsole.Instance.Output (GetHelp ());
36 return;
37 }
38
39 Vector3 pos = new Vector3 ();
40 int x = int.MinValue;
41 int y = int.MinValue;
42 int z = int.MinValue;
43
44 if (_params.Count == 1) {
45 ClientInfo ci1 = ConsoleHelper.ParseParamIdOrName (_params [0]);
46 if (ci1 == null) {
47 SdtdConsole.Instance.Output ("Playername or entity/steam id not found.");
48 return;
49 }
50 EntityPlayer ep1 = GameManager.Instance.World.Players.dict [ci1.entityId];
51 pos = ep1.GetPosition ();
52 } else if (_params.Count == 3) {
53 int.TryParse (_params [0], out x);
54 int.TryParse (_params [1], out y);
55 int.TryParse (_params [2], out z);
56
57 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
58 SdtdConsole.Instance.Output ("x:" + x);
59 SdtdConsole.Instance.Output ("y:" + y);
60 SdtdConsole.Instance.Output ("z:" + z);
61 SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
62 return;
63 }
64
65 pos = new Vector3 ((float)x, (float)y, (float)z);
66 }
67
68 AIDirectorChunkEventComponent chunkComponent = GameManager.Instance.World.aiDirector.GetComponent<AIDirectorChunkEventComponent> ();
69 if (chunkComponent == null) {
70 SdtdConsole.Instance.Output ("No AIDirectorChunkEventComponent Component found");
71 return;
72 }
73
74 chunkComponent.CreateHorde (pos);
75 SdtdConsole.Instance.Output ("Horde spawning at " + pos.x + ", " + pos.y + ", " + pos.z);
76
77 } catch (Exception e) {
78 Log.Out ("Error in SpawnHorde: " + e);
79 }
80 }
81 }
82}
Note: See TracBrowser for help on using the repository browser.