/
TrainUnlocker.cs
76 lines (68 loc) · 1.91 KB
/
TrainUnlocker.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
using System.Collections;
using Rocket.API.Collections;
using Rocket.Core.Plugins;
using Rocket.Unturned.Chat;
using SDG.Unturned;
using Steamworks;
using UnityEngine;
using Logger = Rocket.Core.Logging.Logger;
namespace PhaserArray.TrainUnlocker
{
public class TrainUnlocker : RocketPlugin<TrainUnlockerConfiguration>
{
public const string Version = "v1.2";
private TrainUnlockerConfiguration _config;
protected override void Load()
{
_config = Configuration.Instance;
if (_config.Enabled)
{
SteamChannel.onTriggerSend += OnTriggerSend;
Logger.Log("Loaded TrainUnlocker " + Version + "!");
}
else
{
Logger.Log("TrainUnlocker " + Version + " is installed but not enabled!");
}
}
protected override void Unload()
{
if (!_config.Enabled)
{
return;
}
SteamChannel.onTriggerSend -= OnTriggerSend;
Logger.Log("Unloaded TrainUnlocker " + Version + "!");
}
public void OnTriggerSend(SteamPlayer player, string name, ESteamCall mode, ESteamPacket type, params object[] arguments)
{
if (name != "tellVehicleLock")
{
return;
}
var vehicle = VehicleManager.getVehicle((uint) arguments[0]);
if (vehicle.asset.engine != EEngine.TRAIN || (bool) arguments[3] == false)
{
return;
}
UnturnedChat.Say((CSteamID) arguments[1], Translate("trainunlocker_undid_lock"), Color.red);
StartCoroutine(DelayedUnlockVehicle(vehicle, 1f));
}
public IEnumerator DelayedUnlockVehicle(InteractableVehicle vehicle, float delay)
{
yield return new WaitForSecondsRealtime(delay);
VehicleManager.instance.channel.send(
"tellVehicleLock",
ESteamCall.ALL,
ESteamPacket.UPDATE_RELIABLE_BUFFER,
vehicle.instanceID,
CSteamID.Nil,
CSteamID.Nil,
false);
}
public override TranslationList DefaultTranslations => new TranslationList()
{
{"trainunlocker_undid_lock", "Do not lock the train!"}
};
}
}