C#:
using Facepunch;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Libraries.Covalence;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Rust;
namespace Oxide.Plugins
{
[Info("FastAirdrop", "Qbis", "1.0.2")]
public class FastAirdrop : RustPlugin
{
#region [Config]
private PluginConfig config;
protected override void LoadDefaultConfig()
{
config = PluginConfig.DefaultConfig();
}
protected override void LoadConfig()
{
base.LoadConfig();
config = Config.ReadObject<PluginConfig>();
if (config.PluginVersion < Version)
UpdateConfigValues();
SaveConfig();
}
private void UpdateConfigValues()
{
PluginConfig baseConfig = PluginConfig.DefaultConfig();
if (config.PluginVersion < Version)
{
PrintWarning("Plugin update detected! Checking config values...");
config.PluginVersion = Version;
PrintWarning("Config checked completed!");
}
config.PluginVersion = Version;
}
protected override void SaveConfig()
{
Config.WriteObject(config);
}
private class PluginConfig
{
[JsonProperty("Ignored supply signals skins")]
public HashSet<ulong> ignoredSkins = new();
[JsonProperty("Destroy smoke?")]
public bool destroySmoke;
[JsonProperty("Smoke alive time [seconds]")]
public float smokeAliveTime;
[JsonProperty("Plane speed [default 50]")]
public float planeSpeed;
[JsonProperty("Fast drop supply?")]
public bool supplyFastMove;
[JsonProperty("Groud offset drop for Supply")]
public float groundOffset;
[JsonProperty("Add light to Supply?")]
public bool siren;
[JsonProperty("Config version")]
public VersionNumber PluginVersion = new VersionNumber();
public static PluginConfig DefaultConfig()
{
return new PluginConfig()
{
ignoredSkins = new()
{
64123623,
69942325
},
destroySmoke = true,
smokeAliveTime = 5f,
planeSpeed = 500f,
supplyFastMove = true,
groundOffset = 10f,
siren = true,
PluginVersion = new VersionNumber()
};
}
}
#endregion
#region Hooks
private const int layers = (1 << 0) | (1 << 4) | (1 << 8) | (1 << 10) | (1 << 16) | (1 << 21) | (1 << 23) | (1 << 25) | (1 << 26);
private void OnCargoPlaneSignaled(CargoPlane cargo, SupplySignal supply)
{
if (supply == null) return;
if (config.ignoredSkins.Contains(supply.skinID) || !config.destroySmoke) return;
timer.Once(config.smokeAliveTime, () =>
{
if (supply != null)
supply.Kill();
});
}
private void OnAirdrop(CargoPlane cargo, Vector3 drop)
{
if (cargo == null) return;
cargo.secondsToTake = Vector3.Distance(cargo.startPos, cargo.endPos) / config.planeSpeed;
cargo.secondsToTake *= UnityEngine.Random.Range(0.95f, 1.05f);
}
private void OnSupplyDropDropped(SupplyDrop supply, CargoPlane cargo)
{
if(supply == null) return;
if (config.siren) NextTick(() => AddSiren(supply));
if (config.supplyFastMove && Physics.Raycast(new Ray(supply.transform.position, Vector3.down), out var hit, 1000f, layers))
{
supply.transform.position = hit.point + Vector3.up * config.groundOffset;
supply.TransformChanged();
}
}
#endregion
#region Utils
private void AddSiren(SupplyDrop supply)
{
if (supply == null) return;
FlasherLight siren = GameManager.server.CreateEntity("assets/prefabs/deployable/playerioents/lights/flasherlight/electric.flasherlight.deployed.prefab", supply.transform.position + Vector3.up * 2.5f, Quaternion.identity) as FlasherLight;
siren.Spawn();
DestroyComponent<GroundWatch>(siren);
DestroyComponent<DestroyOnGroundMissing>(siren);
if (siren is BaseCombatEntity baseCombatEntity)
baseCombatEntity.pickup.enabled = false;
siren.SetParent(supply, true);
SetFlag(siren, BaseEntity.Flags.Busy, true);
SetFlag(siren, BaseEntity.Flags.Locked, true);
SetFlag(siren, BaseEntity.Flags.Reserved8, true);
siren.UpdateFromInput(11, 0);
}
private void SetFlag(BaseEntity entity, BaseEntity.Flags f, bool b, bool recursive = false, bool networkupdate = true)
{
using var flags = entity.StartSetFlags(networkupdate ? BaseEntity.FlagsUpdateMode.SendNetworkUpdate : BaseEntity.FlagsUpdateMode.Local);
flags.Set(f, b, recursive);
}
private void DestroyComponent<T>(BaseEntity entity) where T : UnityEngine.Object
{
if (entity == null) return;
if (entity.TryGetComponent<T>(out var component1))
UnityEngine.Object.DestroyImmediate(component1);
}
#endregion
}
}