C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
//#define DEBUG
using Oxide.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Convert = System.Convert;
namespace Oxide.Plugins {
[Info("My Vehicles", "RFC1920/bsdinis/Pho3niX90", "0.2.5")]
// Thanks to BuzZ[PHOQUE], the original author of this plugin
[Description("Spawn vehicles")]
public class MyVehicles : RustPlugin {
string Prefix = "[My Vehicles]: ";
const string prefabmini = "assets/content/vehicles/minicopter/minicopter.entity.prefab";
const string prefabscrap = "assets/content/vehicles/scrap heli carrier/scraptransporthelicopter.prefab";
const string prefabboat = "assets/content/vehicles/boats/rowboat/rowboat.prefab";
const string prefabrhib = "assets/content/vehicles/boats/rhib/rhib.prefab";
const string prefabhab = "assets/prefabs/deployable/hot air balloon/hotairballoon.prefab";
const string prefabhorse = "assets/rust.ai/nextai/testridablehorse.prefab";
const string prefabchinook = "assets/prefabs/npc/ch47/ch47.entity.prefab";
const string prefabsedan = "assets/content/vehicles/sedan_a/sedantest.entity.prefab";
const string prefabpiano = "assets/prefabs/instruments/piano/piano.deployed.prefab";
const string prefabautoturret = "assets/prefabs/npc/autoturret/autoturret_deployed.prefab";
const string prefabswitch = "assets/prefabs/deployable/playerioents/simpleswitch/switch.prefab";
const string prefabcctv = "assets/prefabs/deployable/cctvcamera/cctv_deployed.prefab";
private bool ConfigChanged;
private bool useCooldown = true;
private bool vehicleDecay = true;
private bool allowWhenBlocked = false;
private bool killOnSleep = false;
private bool allowFuelIfUnlimited = false;
private bool allowDriverDismountWhileFlying = true;
private bool allowPassengerDismountWhileFlying = true;
private bool ShowChinookMapMarker = false;
private bool allowSpawnIfAlreadyOwnsVehicle = false;
private float miniHealth = 750f;
private float scrapHealth = 1000f;
private float boatHealth = 400f;
private float rhibHealth = 500f;
private float habHealth = 1500f;
private float horseHealth = 400f;
private float chinookHealth = 1000f;
private float sedanHealth = 300f;
private float miniFuelConsumption = 0.5f;
private float scrapFuelConsumption = 0.5f;
private float boatFuelConsumption = 0.1f;
private float rhibFuelConsumption = 0.25f;
private float habFuelConsumption = 0.25f;
private float maxdistancemini = 50f;
private float maxdistancescrap = 50f;
private float maxdistanceboat = 50f;
private float maxdistancerhib = 50f;
private float maxdistancehab = 50f;
private float maxdistancehorse = 100f;
private float maxdistancechinook = 50f;
private float maxdistancesedan = 100f;
private float fetchdistancemini = 50f;
private float fetchdistancescrap = 50f;
private float fetchdistanceboat = 50f;
private float fetchdistancerhib = 50f;
private float fetchdistancehab = 50f;
private float fetchdistancehorse = 100f;
private float fetchdistancechinook = 50f;
private float fetchdistancesedan = 100f;
private float maxDismountHeight = 7f;
const string MyVehiclesAdmin = "myvehicles.admin";
const string MinicopterSpawn = "myvehicles.minispawn";
const string CombatMinicopterSpawn = "myvehicles.combatminispawn";
const string CCTVMinicopterSpawn = "myvehicles.cctvminispawn";
const string Minicopter1Spawn = "myvehicles.mini1spawn";
const string Minicopter2Spawn = "myvehicles.mini2spawn";
const string Minicopter3Spawn = "myvehicles.mini3spawn";
const string MinicopterFetch = "myvehicles.minifetch";
const string MinicopterWhere = "myvehicles.miniwhere";
const string MinicopterCooldown = "myvehicles.minicooldown";
const string MinicopterUnlimited = "myvehicles.miniunlimited";
const string ScrapSpawn = "myvehicles.scrapspawn";
const string PianoScrapSpawn = "myvehicles.pianoscrapspawn";
const string ScrapFetch = "myvehicles.scrapfetch";
const string ScrapWhere = "myvehicles.scrapwhere";
const string ScrapCooldown = "myvehicles.scrapcooldown";
const string ScrapUnlimited = "myvehicles.scrapunlimited";
const string BoatSpawn = "myvehicles.boatspawn";
const string BoatFetch = "myvehicles.boatfetch";
const string BoatWhere = "myvehicles.boatwhere";
const string BoatCooldown = "myvehicles.boatcooldown";
const string BoatUnlimited = "myvehicles.boatunlimited";
const string RHIBSpawn = "myvehicles.rhibspawn";
const string PianoRHIBSpawn = "myvehicles.pianorhibspawn";
const string RHIBFetch = "myvehicles.rhibfetch";
const string RHIBWhere = "myvehicles.rhibwhere";
const string RHIBCooldown = "myvehicles.rhibcooldown";
const string RHIBUnlimited = "myvehicles.rhibunlimited";
const string HABSpawn = "myvehicles.habspawn";
const string HABFetch = "myvehicles.habfetch";
const string HABWhere = "myvehicles.habwhere";
const string HABCooldown = "myvehicles.habcooldown";
const string HABUnlimited = "myvehicles.habunlimited";
const string HorseSpawn = "myvehicles.horsespawn";
// const string Horse1Spawn = "myvehicles.horse1spawn";
const string HorseFetch = "myvehicles.horsefetch";
const string HorseWhere = "myvehicles.horsewhere";
const string HorseCooldown = "myvehicles.horsecooldown";
const string ChinookSpawn = "myvehicles.chinookspawn";
const string PianoChinookSpawn = "myvehicles.pianochinookspawn";
const string ChinookFetch = "myvehicles.chinookfetch";
const string ChinookWhere = "myvehicles.chinookwhere";
const string ChinookCooldown = "myvehicles.chinookcooldown";
const string SedanSpawn = "myvehicles.sedanspawn";
const string PianoSedanSpawn = "myvehicles.pianosedanspawn";
const string CombatSedanSpawn = "myvehicles.combatsedanspawn";
const string CombatSedan2Spawn = "myvehicles.combatsedan2spawn";
const string SedanFetch = "myvehicles.sedanfetch";
const string SedanWhere = "myvehicles.sedanwhere";
const string SedanCooldown = "myvehicles.sedancooldown";
static LayerMask layerMask = LayerMask.GetMask("Terrain", "World", "Construction");
double cooldownmini = 60;
double cooldownscrap = 60;
double cooldownboat = 30;
double cooldownrhib = 45;
double cooldownhab = 30;
double cooldownhorse = 15;
double cooldownchinook = 90;
double cooldownsedan = 90;
private Dictionary<ulong, ulong> currentMounts = new Dictionary<ulong, ulong>();
public Dictionary<ulong, BaseVehicle> baseplayerminicop = new Dictionary<ulong, BaseVehicle>();
public Dictionary<ulong, BaseVehicle> baseplayerscrapcop = new Dictionary<ulong, BaseVehicle>();
public Dictionary<ulong, BaseVehicle> baseplayerboatcop = new Dictionary<ulong, BaseVehicle>();
public Dictionary<ulong, BaseVehicle> baseplayerrhibcop = new Dictionary<ulong, BaseVehicle>();
public Dictionary<ulong, HotAirBalloon> baseplayerhabcop = new Dictionary<ulong, HotAirBalloon>();
public Dictionary<ulong, BaseVehicle> baseplayerhorsecop = new Dictionary<ulong, BaseVehicle>();
public Dictionary<ulong, BaseVehicle> baseplayerchinookcop = new Dictionary<ulong, BaseVehicle>();
public Dictionary<ulong, BaseVehicle> baseplayersedancop = new Dictionary<ulong, BaseVehicle>();
private static DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
class StoredData {
public Dictionary<ulong, FrankenVehicle> playerminiID = new Dictionary<ulong, FrankenVehicle>();
public Dictionary<ulong, double> playerminicounter = new Dictionary<ulong, double>();
public Dictionary<ulong, FrankenVehicle> playerscrapID = new Dictionary<ulong, FrankenVehicle>();
public Dictionary<ulong, double> playerscrapcounter = new Dictionary<ulong, double>();
public Dictionary<ulong, FrankenVehicle> playerboatID = new Dictionary<ulong, FrankenVehicle>();
public Dictionary<ulong, double> playerboatcounter = new Dictionary<ulong, double>();
public Dictionary<ulong, FrankenVehicle> playerrhibID = new Dictionary<ulong, FrankenVehicle>();
public Dictionary<ulong, double> playerrhibcounter = new Dictionary<ulong, double>();
public Dictionary<ulong, FrankenVehicle> playerhabID = new Dictionary<ulong, FrankenVehicle>();
public Dictionary<ulong, double> playerhabcounter = new Dictionary<ulong, double>();
public Dictionary<ulong, FrankenVehicle> playerhorseID = new Dictionary<ulong, FrankenVehicle>();
public Dictionary<ulong, double> playerhorsecounter = new Dictionary<ulong, double>();
public Dictionary<ulong, FrankenVehicle> playerchinookID = new Dictionary<ulong, FrankenVehicle>();
public Dictionary<ulong, double> playerchinookcounter = new Dictionary<ulong, double>();
public Dictionary<ulong, FrankenVehicle> playersedanID = new Dictionary<ulong, FrankenVehicle>();
public Dictionary<ulong, double> playersedancounter = new Dictionary<ulong, double>();
public StoredData() {
}
}
class FrankenVehicle {
public uint vehicleId;
public bool turret;
public bool turret2;
public bool cctv;
public bool piano;
public bool sideSeats;
public bool backSeats;
public FrankenVehicle(uint vehicleId) {
this.vehicleId = vehicleId;
}
public FrankenVehicle() {
}
public FrankenVehicle EnableTurret() {
turret = true;
return this;
}
public FrankenVehicle EnableTurret2() {
turret = true;
return this;
}
public FrankenVehicle EnableCCTV() {
cctv = true;
return this;
}
public FrankenVehicle EnablePiano() {
piano = true;
return this;
}
public FrankenVehicle EnableSideSeats() {
sideSeats = true;
return this;
}
public FrankenVehicle EnableRotorSeats() {
backSeats = true;
return this;
}
public FrankenVehicle EnableAllSeats() {
backSeats = true;
sideSeats = true;
return this;
}
}
private StoredData storedData;
private bool HasPermission(ConsoleSystem.Arg arg, string permname) => (arg.Connection.player as BasePlayer) == null ? true : permission.UserHasPermission((arg.Connection.player as BasePlayer).UserIDString, permname);
#region loadunload
void OnNewSave() {
storedData = new StoredData();
SaveData();
}
void Loaded() {
LoadVariables();
permission.RegisterPermission(MyVehiclesAdmin, this);
permission.RegisterPermission(MinicopterSpawn, this);
permission.RegisterPermission(CombatMinicopterSpawn, this);
permission.RegisterPermission(CCTVMinicopterSpawn, this);
permission.RegisterPermission(Minicopter1Spawn, this);
permission.RegisterPermission(Minicopter2Spawn, this);
permission.RegisterPermission(Minicopter3Spawn, this);
permission.RegisterPermission(MinicopterFetch, this);
permission.RegisterPermission(MinicopterWhere, this);
permission.RegisterPermission(MinicopterCooldown, this);
permission.RegisterPermission(MinicopterUnlimited, this);
permission.RegisterPermission(ScrapSpawn, this);
permission.RegisterPermission(PianoScrapSpawn, this);
permission.RegisterPermission(ScrapFetch, this);
permission.RegisterPermission(ScrapWhere, this);
permission.RegisterPermission(ScrapCooldown, this);
permission.RegisterPermission(ScrapUnlimited, this);
permission.RegisterPermission(BoatSpawn, this);
permission.RegisterPermission(BoatFetch, this);
permission.RegisterPermission(BoatWhere, this);
permission.RegisterPermission(BoatCooldown, this);
permission.RegisterPermission(BoatUnlimited, this);
permission.RegisterPermission(RHIBSpawn, this);
permission.RegisterPermission(PianoRHIBSpawn, this);
permission.RegisterPermission(RHIBFetch, this);
permission.RegisterPermission(RHIBWhere, this);
permission.RegisterPermission(RHIBCooldown, this);
permission.RegisterPermission(RHIBUnlimited, this);
permission.RegisterPermission(HABSpawn, this);
permission.RegisterPermission(HABFetch, this);
permission.RegisterPermission(HABWhere, this);
permission.RegisterPermission(HABCooldown, this);
permission.RegisterPermission(HABUnlimited, this);
permission.RegisterPermission(HorseSpawn, this);
// permission.RegisterPermission(Horse1Spawn, this);
permission.RegisterPermission(HorseFetch, this);
permission.RegisterPermission(HorseWhere, this);
permission.RegisterPermission(HorseCooldown, this);
permission.RegisterPermission(ChinookSpawn, this);
permission.RegisterPermission(PianoChinookSpawn, this);
permission.RegisterPermission(ChinookFetch, this);
permission.RegisterPermission(ChinookWhere, this);
permission.RegisterPermission(ChinookCooldown, this);
permission.RegisterPermission(SedanSpawn, this);
permission.RegisterPermission(PianoSedanSpawn, this);
permission.RegisterPermission(CombatSedanSpawn, this);
permission.RegisterPermission(CombatSedan2Spawn, this);
permission.RegisterPermission(SedanFetch, this);
permission.RegisterPermission(SedanWhere, this);
permission.RegisterPermission(SedanCooldown, this);
storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>(Name);
}
void Unload() {
SaveData();
}
#endregion
#region MESSAGES
protected override void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string>
{
{"AlreadyMiniMsg", "You already have a Minicopter.\nUse command '/nomini' to remove it."},
{"SpawnedMiniMsg", "Your Minicopter has spawned !\nUse command '/nomini' to remove it."},
{"KilledMiniMsg", "Your Minicopter has been removed/killed."},
{"NoFoundMiniMsg", "You do not have an active Minicopter."},
{"FoundMiniMsg", "Your Minicopter is located at {0}."},
{"CooldownMiniMsg", "You must wait {0} seconds before spawning a new Minicopter."},
{"DistanceMiniMsg", "You must be within {0} meters of your Minicopter."},
{"AlreadyScrapMsg", "You already have a Scrap Helicopter.\nUse command '/noheli' to remove it."},
{"SpawnedScrapMsg", "Your Scrap Helicopter has spawned !\nUse command '/noheli' to remove it."},
{"KilledScrapMsg", "Your Scrap Helicopter has been removed/killed."},
{"NoFoundScrapMsg", "You do not have an active Scrap Helicopter."},
{"FoundScrapMsg", "Your Scrap Helicopter is located at {0}."},
{"CooldownScrapMsg", "You must wait {0} seconds before spawning a new Scrap Helicopter."},
{"DistanceScrapMsg", "You must be within {0} meters of your Scrap Helicopter."},
{"AlreadyBoatMsg", "You already have a Row Boat.\nUse command '/noboat' to remove it."},
{"SpawnedBoatMsg", "Your Row Boat has spawned !\nUse command '/noboat' to remove it."},
{"KilledBoatMsg", "Your Row Boat has been removed/killed."},
{"NoFoundBoatMsg", "You do not have an active Row Boat."},
{"FoundBoatMsg", "Your Row Boat is located at {0}."},
{"CooldownBoatMsg", "You must wait {0} seconds before spawning a new Row Boat."},
{"DistanceBoatMsg", "You must be within {0} meters of your Row Boat."},
{"AlreadyRHIBMsg", "You already have a RHIB.\nUse command '/norhib' to remove it."},
{"SpawnedRHIBMsg", "Your RHIB has spawned !\nUse command '/norhib' to remove it."},
{"KilledRHIBMsg", "Your RHIB has been removed/killed."},
{"NoFoundRHIBMsg", "You do not have an active RHIB."},
{"FoundRHIBMsg", "Your RHIB is located at {0}."},
{"CooldownRHIBMsg", "You must wait {0} seconds before spawning a new RHIB."},
{"DistanceRHIBMsg", "You must be within {0} meters of your RHIB."},
{"AlreadyHABMsg", "You already have a Hot Air Balloon.\nUse command '/nohab' to remove it."},
{"SpawnedHABMsg", "Your Hot Air Balloon has spawned !\nUse command '/nohab' to remove it."},
{"KilledHABMsg", "Your Hot Air Balloon has been removed/killed."},
{"NoFoundHABMsg", "You do not have an active Hot Air Balloon."},
{"FoundHABMsg", "Your Hot Air Balloon is located at {0}."},
{"CooldownHABMsg", "You must wait {0} seconds before spawning a new Hot Air Balloon."},
{"DistanceHABMsg", "You must be within {0} meters of your Hot Air Balloon."},
{"AlreadyHorseMsg", "You already have a Ridable Horse.\nUse command '/nohorse' to remove it."},
{"SpawnedHorseMsg", "Your Ridable Horse has spawned !\nUse command '/nohorse' to remove it."},
{"KilledHorseMsg", "Your Ridable Horse has been removed/killed."},
{"NoFoundHorseMsg", "You do not have an active Ridable Horse."},
{"FoundHorseMsg", "Your Ridable Horse is located at {0}."},
{"CooldownHorseMsg", "You must wait {0} seconds before spawning a new Ridable Horse."},
{"DistanceHorseMsg", "You must be within {0} meters of your Ridable Horse."},
{"AlreadyChinookMsg", "You already have a Chinook.\nUse command '/noch47' to remove it."},
{"SpawnedChinookMsg", "Your Chinook has spawned !\nUse command '/noch47' to remove it."},
{"KilledChinookMsg", "Your Chinook has been removed/killed."},
{"NoFoundChinookMsg", "You do not have an active Chinook."},
{"FoundChinookMsg", "Your Chinook is located at {0}."},
{"CooldownChinookMsg", "You must wait {0} seconds before spawning a new Chinook."},
{"DistanceChinookMsg", "You must be within {0} meters of your Chinook."},
{"AlreadySedanMsg", "You already have a Sedan.\nUse command '/nosedan' to remove it."},
{"SpawnedSedanMsg", "Your Sedan has spawned !\nUse command '/nosedan' to remove it."},
{"KilledSedanMsg", "Your Sedan has been removed/killed."},
{"NoFoundSedanMsg", "You do not have an active Sedan."},
{"FoundSedanMsg", "Your Sedan is located at {0}."},
{"CooldownSedanMsg", "You must wait {0} seconds before spawning a new Sedan."},
{"DistanceSedanMsg", "You must be within {0} meters of your Sedan."},
{"FlyingMsg", "You cannot spawn or fetch Horses while flying."},
{"MountedOrParentedMsg", "You cannot spawn or fetch vehicles while mounted or parented to another vehicle."},
{"BlockedMsg", "You cannot spawn or fetch vehicles while building blocked."},
{"NotInWaterMsg", "You cannot spawn or fetch boats out of the water."},
{"InWaterMsg", "You cannot spawn or fetch Horses in the water."},
{"NoPermMsg", "You are not allowed to do this."},
{"SpawnUsage", "You need to supply a valid SteamID."}
}, this, "en");
}
private string _(string msgId, BasePlayer player, params object[] args) {
var msg = lang.GetMessage(msgId, this, player?.UserIDString);
return args.Length > 0 ? string.Format(msg, args) : msg;
}
private void PrintMsgL(BasePlayer player, string msgId, params object[] args) {
if (player == null) return;
PrintMsg(player, _(msgId, player, args));
}
private void PrintMsg(BasePlayer player, string msg) {
if (player == null) return;
SendReply(player, $"{Prefix}{msg}");
}
// Chat message to online player with ulong
private void ChatPlayerOnline(ulong ailldi, string message) {
BasePlayer player = BasePlayer.FindByID(ailldi);
if (player != null) {
if (message == "killedmini") PrintMsgL(player, "KilledMiniMsg");
if (message == "killedscrap") PrintMsgL(player, "KilledScrapMsg");
if (message == "killedboat") PrintMsgL(player, "KilledBoatMsg");
if (message == "killedrhib") PrintMsgL(player, "KilledRHIBMsg");
if (message == "killedhab") PrintMsgL(player, "KilledHABMsg");
if (message == "killedhorse") PrintMsgL(player, "KilledHorseMsg");
if (message == "killedchinook") PrintMsgL(player, "KilledChinookMsg");
if (message == "killedsedan") PrintMsgL(player, "KilledSedanMsg");
}
}
#endregion
#region CONFIG
protected override void LoadDefaultConfig() {
LoadVariables();
}
private void LoadVariables() {
allowWhenBlocked = Convert.ToBoolean(GetConfig("Global", "Allow spawn when building blocked", false));
allowSpawnIfAlreadyOwnsVehicle = Convert.ToBoolean(GetConfig("Global", "Allow spawning new vehicle if player already owns one", false));
miniHealth = (float)Convert.ToSingle(GetConfig("Health", "Minicopter", 750));
scrapHealth = (float)Convert.ToSingle(GetConfig("Health", "Scrap Helicopter", 1000));
boatHealth = (float)Convert.ToSingle(GetConfig("Health", "Row Boat", 400));
rhibHealth = (float)Convert.ToSingle(GetConfig("Health", "RHIB", 500));
habHealth = (float)Convert.ToSingle(GetConfig("Health", "Hot Air Balloon", 1500));
horseHealth = (float)Convert.ToSingle(GetConfig("Health", "Ridable Horse", 400));
chinookHealth = (float)Convert.ToSingle(GetConfig("Health", "Chinook", 1000));
sedanHealth = (float)Convert.ToSingle(GetConfig("Health", "Sedan", 300));
miniFuelConsumption = (float)Convert.ToSingle(GetConfig("Fuel consumption (per second)", "Minicopter", 0.5));
scrapFuelConsumption = (float)Convert.ToSingle(GetConfig("Fuel consumption (per second)", "Scrap Helicopter", 0.5));
boatFuelConsumption = (float)Convert.ToSingle(GetConfig("Fuel consumption (per second)", "Row Boat", 0.1));
rhibFuelConsumption = (float)Convert.ToSingle(GetConfig("Fuel consumption (per second)", "RHIB", 0.25));
habFuelConsumption = (float)Convert.ToSingle(GetConfig("Fuel consumption (per second)", "Hot Air Balloon", 0.25));
Prefix = Convert.ToString(GetConfig("Global", "Chat prefix", "[My Vehicles]: "));
cooldownmini = Convert.ToSingle(GetConfig("Cooldown (minutes)", "Minicopter", "60"));
cooldownscrap = Convert.ToSingle(GetConfig("Cooldown (minutes)", "Scrap Helicopter", "60"));
cooldownboat = Convert.ToSingle(GetConfig("Cooldown (minutes)", "Row Boat", "30"));
cooldownrhib = Convert.ToSingle(GetConfig("Cooldown (minutes)", "RHIB", "45"));
cooldownhab = Convert.ToSingle(GetConfig("Cooldown (minutes)", "Hot Air Balloon", "30"));
cooldownhorse = Convert.ToSingle(GetConfig("Cooldown (minutes)", "Ridable Horse", "15"));
cooldownchinook = Convert.ToSingle(GetConfig("Cooldown (minutes)", "Chinook", "90"));
cooldownsedan = Convert.ToSingle(GetConfig("Cooldown (minutes)", "Sedan", "90"));
useCooldown = Convert.ToBoolean(GetConfig("Cooldown (minutes)", "Use cooldown (on permission)", true));
vehicleDecay = Convert.ToBoolean(GetConfig("Global", "Vehicle decay", true));
maxdistancemini = Convert.ToSingle(GetConfig("Maximum distance for killing vehicle (meters)", "Minicopter", "50"));
maxdistancescrap = Convert.ToSingle(GetConfig("Maximum distance for killing vehicle (meters)", "Scrap Helicopter", "50"));
maxdistanceboat = Convert.ToSingle(GetConfig("Maximum distance for killing vehicle (meters)", "Row Boat", "50"));
maxdistancerhib = Convert.ToSingle(GetConfig("Maximum distance for killing vehicle (meters)", "RHIB", "50"));
maxdistancehab = Convert.ToSingle(GetConfig("Maximum distance for killing vehicle (meters)", "Hot Air Balloon", "50"));
maxdistancehorse = Convert.ToSingle(GetConfig("Maximum distance for killing vehicle (meters)", "Ridable Horse", "100"));
maxdistancechinook = Convert.ToSingle(GetConfig("Maximum distance for killing vehicle (meters)", "Chinook", "50"));
maxdistancesedan = Convert.ToSingle(GetConfig("Maximum distance for killing vehicle (meters)", "Sedan", "100"));
fetchdistancemini = Convert.ToSingle(GetConfig("Maximum distance for fetching vehicle (meters)", "Minicopter", "50"));
fetchdistancescrap = Convert.ToSingle(GetConfig("Maximum distance for fetching vehicle (meters)", "Scrap Helicopter", "50"));
fetchdistanceboat = Convert.ToSingle(GetConfig("Maximum distance for fetching vehicle (meters)", "Row Boat", "50"));
fetchdistancerhib = Convert.ToSingle(GetConfig("Maximum distance for fetching vehicle (meters)", "RHIB", "50"));
fetchdistancehab = Convert.ToSingle(GetConfig("Maximum distance for fetching vehicle (meters)", "Hot Air Balloon", "50"));
fetchdistancehorse = Convert.ToSingle(GetConfig("Maximum distance for fetching vehicle (meters)", "Ridable Horse", "100"));
fetchdistancechinook = Convert.ToSingle(GetConfig("Maximum distance for fetching vehicle (meters)", "Chinook", "50"));
fetchdistancesedan = Convert.ToSingle(GetConfig("Maximum distance for fetching vehicle (meters)", "Sedan", "100"));
killOnSleep = Convert.ToBoolean(GetConfig("Global", "Kill vehicle on player disconnect", false));
allowFuelIfUnlimited = Convert.ToBoolean(GetConfig("Global", "Allow unlimited to use fuel tank", false));
ShowChinookMapMarker = Convert.ToBoolean(GetConfig("Global", "Show Chinook map marker", false));
allowDriverDismountWhileFlying = Convert.ToBoolean(GetConfig("Global", "Allow driver dismount while flying", true));
allowPassengerDismountWhileFlying = Convert.ToBoolean(GetConfig("Global", "Allow passenger dismount while flying", true));
maxDismountHeight = Convert.ToSingle(GetConfig("Maximum height for dismount", "Value in meters", "7"));
if (!ConfigChanged) return;
SaveConfig();
ConfigChanged = false;
}
private object GetConfig(string menu, string datavalue, object defaultValue) {
var data = Config[menu] as Dictionary<string, object>;
if (data == null) {
data = new Dictionary<string, object>();
Config[menu] = data;
ConfigChanged = true;
}
object value;
if (!data.TryGetValue(datavalue, out value)) {
value = defaultValue;
data[datavalue] = value;
ConfigChanged = true;
}
return value;
}
void SaveData() {
// Save the data file as we add/remove vehicles.Interface.Oxide.DataFileSystem.WriteObject(Name, storedData);
}
#endregion
#region bools
private bool IsInWater(BasePlayer player) {
var modelState = player.modelState;
return modelState != null && modelState.waterLevel > 0;
}
#endregion
private object OnEntityTakeDamage(StaticInstrument piano, HitInfo info) {
if (piano != null) {
var scrapTransport = piano.GetComponentInParent<ScrapTransportHelicopter>();
if (scrapTransport != null) {
scrapTransport.Hurt(info);
return true;
}
var rhib = piano.GetComponentInParent<RHIB>();
if (rhib != null) {
rhib.Hurt(info);
return true;
}
var chinook = piano.GetComponentInParent<CH47Helicopter>();
if (chinook != null) {
chinook.Hurt(info);
return true;
}
var sedan = piano.GetComponentInParent<BaseCar>();
if (sedan != null) {
sedan.Hurt(info);
return true;
}
}
return null;
}
private object OnEntityTakeDamage(CCTV_RC cctv, HitInfo info) {
if (cctv != null) {
var miniCopter = cctv.GetComponentInParent<MiniCopter>();
if (miniCopter != null) {
miniCopter.Hurt(info);
return true;
}
}
return null;
}
#region Hooks
bool OnMiniCanCreateSideSeats(BaseVehicle entity) {
if (storedData.playerminiID.Any(x => x.Value.vehicleId == entity.net.ID)) {
FrankenVehicle fc = storedData.playerminiID.First(x => x.Value.vehicleId == entity.net.ID).Value;
return fc.sideSeats;
}
return false;
}
bool OnMiniCanCreateRotorSeat(BaseVehicle entity) {
if (storedData.playerminiID.Any(x => x.Value.vehicleId == entity.net.ID)) {
FrankenVehicle fc = storedData.playerminiID.First(x => x.Value.vehicleId == entity.net.ID).Value;
return fc.backSeats;
}
return false;
}
// bool OnHorseCanCreateBackSeat(BaseVehicle entity) {
// bool makeit = createHorseBackSeat;
// createHorseBackSeat = false;
// return makeit;
// }
/*
bool CreatePianoOnVehicle(BaseVehicle entity) {
bool makeit = createPiano;
createPiano = false;
return makeit;
}
bool CreateCCTVOnVehicle(BaseVehicle entity) {
bool makeit = createCCTV;
createCCTV = false;
return makeit;
}
bool CreateAutoTurretOnVehicle(BaseVehicle entity) {
bool makeit = createAutoTurret;
createAutoTurret = false;
return makeit;
}
bool CreateAutoTurret2OnVehicle(BaseVehicle entity) {
bool makeit = createAutoTurret2;
createAutoTurret2 = false;
return makeit;
}
*/
#endregion
#region chatcommands
// Chat spawn Combat Minicopter
[ChatCommand("mycombatmini")]
private void SpawnMyCombatMinicopterChatCommand(BasePlayer player, string command, string[] args) {
bool canspawn = permission.UserHasPermission(player.UserIDString, CombatMinicopterSpawn);
if (!(canspawn)) {
PrintMsgL(player, "NoPermMsg");
return;
}
SpawnMini(player, new FrankenVehicle().EnableTurret());
}
// Chat spawn CCTV Minicopter
[ChatCommand("mycctvmini")]
private void SpawnMyCCTVMinicopterChatCommand(BasePlayer player, string command, string[] args) {
bool canspawn = permission.UserHasPermission(player.UserIDString, CCTVMinicopterSpawn);
if (!(canspawn)) {
PrintMsgL(player, "NoPermMsg");
return;
}
SpawnMini(player, new FrankenVehicle().EnableCCTV());
}
FrankenVehicle GetFrankenVehicle(Dictionary<ulong, FrankenVehicle> fvs, BaseEntity entity) {
if (fvs.ContainsKey(entity.OwnerID)) {
return storedData.playerminiID[entity.OwnerID];
}
return new FrankenVehicle();
}
private void OnEntitySpawned(MiniCopter miniCopter) {
FrankenVehicle fv = GetFrankenVehicle(storedData.playerminiID, miniCopter);
if (fv.turret) {
//miniCopter.liftFraction = 0.25f;
//miniCopter.torqueScale = new Vector3(400f, 400f, 200f);
var autoturret = GameManager.server.CreateEntity(prefabautoturret, miniCopter.transform.position) as AutoTurret;
if (autoturret == null) return;
autoturret.Spawn();
autoturret.pickup.enabled = false;
autoturret.sightRange = 50f;
UnityEngine.Object.Destroy(autoturret.GetComponent<DestroyOnGroundMissing>());
autoturret.SetParent(miniCopter);
autoturret.transform.localPosition = new Vector3(0, 0.001f, 2.47f);
autoturret.transform.localRotation = Quaternion.Euler(0, 0, 0);
autoturret.authorizedPlayers.Add(new ProtoBuf.PlayerNameID { userid = miniCopter.OwnerID, username = BasePlayer.FindByID(miniCopter.OwnerID)?.displayName });
timer.Once(1f, () => {
AddSwitch(autoturret);
});
}
if (fv.cctv) {
var cctv = GameManager.server.CreateEntity(prefabcctv, miniCopter.transform.position) as CCTV_RC;
if (cctv == null) return;
cctv.Spawn();
cctv.pickup.enabled = false;
UnityEngine.Object.Destroy(cctv.GetComponent<DestroyOnGroundMissing>());
cctv.SetParent(miniCopter);
cctv.transform.localPosition = new Vector3(0, 1.9f, 0);
cctv.transform.localRotation = Quaternion.Euler(0, 0, 0);
cctv.UpdateIdentifier(RandomString(3));
cctv.UpdateHasPower(25, 1);
}
}
private void OnEntitySpawned(ScrapTransportHelicopter scrapTransport) {
FrankenVehicle fv = GetFrankenVehicle(storedData.playerscrapID, scrapTransport);
if (!fv.piano) return;
var piano = GameManager.server.CreateEntity(prefabpiano, scrapTransport.transform.position) as StaticInstrument;
if (piano == null) return;
piano.Spawn();
piano.pickup.enabled = false;
UnityEngine.Object.Destroy(piano.GetComponent<DestroyOnGroundMissing>());
piano.SetParent(scrapTransport);
piano.transform.localPosition = new Vector3(0, 0.85f, 0.5f);
piano.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
private string RandomString(int length) {
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
var stringChars = new char[length];
var random = new System.Random();
for (int i = 0; i < stringChars.Length; i++) {
stringChars[i] = chars[random.Next(chars.Length)];
}
return new String(stringChars);
}
private void AddSwitch(AutoTurret autoturret) {
var autoturretSwitch = autoturret.GetComponentInChildren<ElectricSwitch>();
if (autoturretSwitch != null) {
UnityEngine.Object.Destroy(autoturretSwitch.GetComponent<DestroyOnGroundMissing>());
UnityEngine.Object.Destroy(autoturretSwitch.GetComponent<GroundWatch>());
autoturretSwitch.pickup.enabled = false;
return;
}
autoturretSwitch = GameManager.server.CreateEntity(prefabswitch, autoturret.transform.position)?.GetComponent<ElectricSwitch>();
if (autoturretSwitch == null) {
return;
}
autoturretSwitch.pickup.enabled = false;
autoturretSwitch.SetParent(autoturret);
autoturretSwitch.transform.localPosition = new Vector3(0f, -0.65f, 0.325f);
autoturretSwitch.transform.localRotation = Quaternion.Euler(0, 0, 0);
autoturretSwitch.Spawn();
UnityEngine.Object.Destroy(autoturretSwitch.GetComponent<DestroyOnGroundMissing>());
UnityEngine.Object.Destroy(autoturretSwitch.GetComponent<GroundWatch>());
}
private object OnEntityTakeDamage(ElectricSwitch autoturretSwitch, HitInfo info) {
if (autoturretSwitch != null) {
var autoturret = autoturretSwitch.GetComponentInParent<AutoTurret>();
if (autoturret != null) {
autoturret.Hurt(info);
return true;
}
}
return null;
}
private void OnSwitchToggle(ElectricSwitch autoturretSwitch, BasePlayer player) {
var autoturret = autoturretSwitch.GetComponentInParent<AutoTurret>();
if (autoturret == null) {
return;
}
if (autoturret.authorizedPlayers.Any(x => x.userid == player.userID) == false) {
player.ChatMessage("No permission");
autoturretSwitch.SetSwitch(!autoturretSwitch.IsOn());
return;
}
if (autoturret.GetParentEntity() is MiniCopter) {
ToggleTurret(autoturret);
}
if (autoturret.GetParentEntity() is BaseCar) {
ToggleTurret(autoturret);
}
}
private void ToggleTurret(AutoTurret autoturret) {
if (autoturret.IsOnline()) {
PowerTurretOff(autoturret);
} else {
PowerTurretOn(autoturret);
}
}
private void PowerTurretOn(AutoTurret autoturret) {
autoturret.SetFlag(BaseEntity.Flags.Reserved8, true);
autoturret.SetIsOnline(true);
}
private void PowerTurretOff(AutoTurret autoturret) {
autoturret.SetFlag(BaseEntity.Flags.Reserved8, false);
autoturret.SetIsOnline(false);
}
// Chat spawn Minicopter1
[ChatCommand("mymini1")]
private void SpawnMyMinicopter1ChatCommand(BasePlayer player, string command, string[] args) {
bool canspawn = permission.UserHasPermission(player.UserIDString, Minicopter1Spawn);
if (!(canspawn)) {
PrintMsgL(player, "NoPermMsg");
return;
}
SpawnMini(player, new FrankenVehicle().EnableRotorSeats());
}
// Chat spawn Minicopter2
[ChatCommand("mymini2")]
private void SpawnMyMinicopter2ChatCommand(BasePlayer player, string command, string[] args) {
bool canspawn = permission.UserHasPermission(player.UserIDString, Minicopter2Spawn);
if (!(canspawn)) {
PrintMsgL(player, "NoPermMsg");
return;
}
SpawnMini(player, new FrankenVehicle().EnableSideSeats());
}
// Chat spawn Minicopter3
[ChatCommand("mymini3")]
private void SpawnMyMinicopter3ChatCommand(BasePlayer player, string command, string[] args) {
bool canspawn = permission.UserHasPermission(player.UserIDString, Minicopter3Spawn);
if (!(canspawn)) {
PrintMsgL(player, "NoPermMsg");
return;
}
SpawnMini(player, new FrankenVehicle().EnableRotorSeats());
}
// Chat spawn Minicopter
[ChatCommand("mymini")]
private void SpawnMyMinicopterChatCommand(BasePlayer player, string command, string[] args) {
bool isspawner = permission.UserHasPermission(player.UserIDString, MinicopterSpawn);
if (isspawner == false) {
PrintMsgL(player, "NoPermMsg");
return;
}
if (player.IsBuildingBlocked() & !allowWhenBlocked) {
PrintMsgL(player, "BlockedMsg");
return;
}
if (player.GetMountedVehicle() || player.GetParentEntity()) {
PrintMsgL(player, "MountedOrParentedMsg");
return;
}
if (!allowSpawnIfAlreadyOwnsVehicle) {
if (storedData.playerminiID.ContainsKey(player.userID) == true) {
PrintMsgL(player, "AlreadyMiniMsg");
return;
}
}
SpawnMini(player, new FrankenVehicle());
}
void SpawnMini(BasePlayer player, FrankenVehicle fc) {
double secondsSinceEpoch = DateTime.UtcNow.Subtract(epoch).TotalSeconds;
bool hascooldown = permission.UserHasPermission(player.UserIDString, MinicopterCooldown);
if (!useCooldown) hascooldown = false;
int secsleft = 0;
if (hascooldown == true) {
if (storedData.playerminicounter.ContainsKey(player.userID) == false) {
storedData.playerminicounter.Add(player.userID, secondsSinceEpoch);
SaveData();
} else {
double count;
storedData.playerminicounter.TryGetValue(player.userID, out count);
if ((secondsSinceEpoch - count) > (cooldownmini * 60)) {
#if DEBUG
Puts($"Player reached cooldown.Clearing data.");
#endif
storedData.playerminicounter.Remove(player.userID);
SaveData();
} else {
secsleft = Math.Abs((int)((cooldownmini * 60) - (secondsSinceEpoch - count)));
if (secsleft > 0) {
#if DEBUG
Puts($"Player DID NOT reach cooldown.Still {secsleft.ToString()} secs left.");
#endif
PrintMsgL(player, "CooldownMiniMsg", secsleft.ToString());
return;
}
}
}
} else {
if (storedData.playerminicounter.ContainsKey(player.userID)) {
storedData.playerminicounter.Remove(player.userID);
SaveData();
}
}
SpawnMyMinicopter(player, fc);
}
// Fetch Minicopter
[ChatCommand("gmini")]
private void GetMyMinicopterChatCommand(BasePlayer player, string command, string[] args) {
if (player.IsBuildingBlocked() & !allowWhenBlocked) {
PrintMsgL(player, "BlockedMsg");
return;
}
if (player.GetMountedVehicle() || player.GetParentEntity()) {
PrintMsgL(player, "MountedOrParentedMsg");
return;
}
bool canspawn = permission.UserHasPermission(player.UserIDString, MinicopterSpawn);
bool canfetch = permission.UserHasPermission(player.UserIDString, MinicopterFetch);
if (!(canspawn & canfetch)) {
PrintMsgL(player, "NoPermMsg");
return;
}
if (storedData.playerminiID.ContainsKey(player.userID) == true) {
FrankenVehicle findme;
storedData.playerminiID.TryGetValue(player.userID, out findme);
var foundit = BaseNetworkable.serverEntities.Find(findme.vehicleId);
if (foundit != null) {
// Distance check
if (fetchdistancemini > 0f) {
if (Vector3.Distance(player.transform.position, foundit.transform.position) > fetchdistancemini) {
PrintMsgL(player, "DistanceMiniMsg", fetchdistancemini);
return;
}
}
// Check for and dismount all players before moving the vehicle
var vehicle = foundit as BaseVehicle;
BaseVehicle.MountPointInfo[] mountpoints = vehicle.mountPoints;
for (int i = 0; i < (int)mountpoints.Length; i++) {
BaseVehicle.MountPointInfo mountPointInfo = mountpoints[i];
if (mountPointInfo.mountable != null) {
BasePlayer mounted = mountPointInfo.mountable.GetMounted();
if (mounted) {
Vector3 player_pos = mounted.transform.position + new Vector3(1, 0, 1);
mounted.DismountObject();
mounted.MovePosition(player_pos);
mounted.SendNetworkUpdateImmediate(false);
mounted.ClientRPCPlayer(null, player, "ForcePositionTo", player_pos);
mountPointInfo.mountable._mounted = null;
}
}
}
var newLoc = new Vector3((float)(player.transform.position.x + 1.5f), player.transform.position.y + 1f, (float)(player.transform.position.z + 0f));
foundit.transform.position = newLoc;
PrintMsgL(player, "FoundMiniMsg", newLoc);
}
return;
} else {
PrintMsgL(player, "NoFoundMiniMsg");
return;
}
}
// Find Minicopter
[ChatCommand("wmini")]
private void WhereIsMyMinicopterChatCommand(BasePlayer player, string command, string[] args) {
bool canspawn = permission.UserHasPermission(player.UserIDString, MinicopterWhere);
if (canspawn == false) {
PrintMsgL(player, "NoPermMsg");
return;
}
if (storedData.playerminiID.ContainsKey(player.userID) == true) {
FrankenVehicle findme;
storedData.playerminiID.TryGetValue(player.userID, out findme);
var foundit = BaseNetworkable.serverEntities.Find(findme.vehicleId);
if (foundit != null) {
var loc = foundit.transform.position.ToString();
PrintMsgL(player, "FoundMiniMsg", loc);
}
return;
} else {
PrintMsgL(player, "NoFoundMiniMsg");
return;
}
}
// Chat despawn Minicopter
[ChatCommand("nomini")]
private void KillMyMinicopterChatCo
// ... [Code preview truncated due to length. Full source in attached file] ...