-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.cs
123 lines (108 loc) · 4.46 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Timers;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.IO;
using System.Net;
using System.Xml;
using System.Xml.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
using System.Globalization;
using Rocket.API;
using Rocket.Core;
using Rocket.Unturned;
using Rocket.Unturned.Events;
using Rocket.Unturned.Items;
using Rocket.Unturned.Player;
using Rocket.Unturned.Enumerations;
using Rocket.Unturned.Plugins;
using Rocket.Core.Logging;
using Rocket.API.Collections;
using Rocket.Core.Plugins;
using SDG.Unturned;
using Steamworks;
using SDG;
using UnityEngine;
using UnityEngine.Events;
using UP = Rocket.Unturned.Player.UnturnedPlayer;
using Rocket.API.Serialisation;
using Rocket.Unturned.Chat;
using SDG.Provider;
using Logger = Rocket.Core.Logging.Logger;
namespace VehicleSpawner
{
public class VehicleSpawnerPlugin : RocketPlugin<Configuration>
{
public static VehicleSpawnerPlugin Instance;
public string Creator = "XXFOGS";
public string PluginName = "VehicleSpawner";
public string Version = "1.0.0";
public DateTime? lastSpawn = null;
protected override void Load()
{
Instance = this;
String cellsFolder = Rocket.Core.Environment.PluginsDirectory + "/VehicleSpawner/Databases/Nodes/";
if (!System.IO.Directory.Exists(cellsFolder))
{
System.IO.Directory.CreateDirectory(cellsFolder);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = (" ");
settings.CloseOutput = true;
settings.OmitXmlDeclaration = true;
using (XmlWriter writer = XmlWriter.Create(cellsFolder + "SpawnNodes.xml", settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("SpawnNodes");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
}
}
Logger.Log($"{PluginName} by {Creator} has been loaded! Version: {Version}");
}
protected override void Unload()
{
Instance = null;
Logger.Log($"{PluginName} has been unloaded");
}
void FixedUpdate()
{
spawnVehicle();
}
private void spawnVehicle()
{
try
{
if (State == PluginState.Loaded && Level.isLoaded && Configuration.Instance.Enabled && (lastSpawn == null || ((DateTime.Now - lastSpawn.Value).TotalSeconds > Configuration.Instance.Interval)))
{
String folder = Rocket.Core.Environment.PluginsDirectory + "/VehicleSpawner/Databases/Nodes/";
XDocument Nodes = XDocument.Load(folder + "SpawnNodes.xml");
var NodesList = Nodes.Element("SpawnNodes").Elements("SpawnNode").ToList();
List<SpawnNode> SpawnNodes = new List<SpawnNode>();
if (NodesList.Count > 0)
{
foreach (var SpawnNode in NodesList)
{
SpawnNodes.Add(new SpawnNode(float.Parse(SpawnNode.Element("X").Value), float.Parse(SpawnNode.Element("Y").Value), float.Parse(SpawnNode.Element("Z").Value)));
}
VehicleAsset vehicle = ((VehicleAsset)SDG.Unturned.Assets.find(EAssetType.VEHICLE, Configuration.Instance.Vehicles[UnityEngine.Random.Range(0, Configuration.Instance.Vehicles.Length - 1)].Id));
SpawnNode node = SpawnNodes.ToArray()[UnityEngine.Random.Range(0, SpawnNodes.ToArray().Length - 1)];
Vector3 pos = new Vector3(node.X, node.Y + 10, node.Z);
VehicleManager.SpawnVehicleV3(vehicle, 0, 0, 0, pos, new Quaternion(0, 90, 0, 0), false, false, false, false, vehicle.fuelMax, vehicle.healthMax, ushort.MaxValue, CSteamID.Nil, CSteamID.Nil, false, null, byte.MaxValue);
Logger.Log($"Spawned a {vehicle.vehicleName} at {pos}", ConsoleColor.Cyan);
lastSpawn = DateTime.Now;
}
}
}
catch (Exception ex)
{
Logger.LogException(ex);
}
}
}
}