C#:
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Libraries;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Rust;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.AI;
using System.Text.RegularExpressions;
///Скачано с дискорд сервера Rust Edit [PRO+]
///discord.gg/9vyTXsJyKR
namespace Oxide.Plugins {
[Info("Heli Signals", "discord.gg/9vyTXsJyKR", "1.0.9")]
[Description("Call Patrol Helicopters to your location with custom supply signals.")]
public class HeliSignals : CovalencePlugin {
#region Plugin References
[PluginReference]
private Plugin Friends, Clans, FancyDrop, RewardPlugin;
#endregion Plugin References
#region Constants
private static HeliSignals plugin;
public const string permAdmin = "helisignals.admin";
public const string permBuy = "helisignals.buy";
public const string permBypasscooldown = "helisignals.bypasscooldown";
public const string heliPrefab = "assets/prefabs/npc/patrol helicopter/patrolhelicopter.prefab";
public const string heliExplosion = "assets/prefabs/npc/patrol helicopter/effects/heli_explosion.prefab";
public const int supplySignalId = 1397052267;
public const int scrapId = -932201673;
// Default config item skins
public const ulong easySkinID = 2920175997;
public const ulong medSkinID = 2920176079;
public const ulong hardSkinID = 2920176050;
public const ulong eliteSkinID = 2920176024;
// Default config item names
public const string easyHeli = "Heli Signal (Easy)";
public const string medHeli = "Heli Signal (Medium)";
public const string hardHeli = "Heli Signal (Hard)";
public const string eliteHeli = "Heli Signal (Elite)";
#endregion Constants
#region Language
protected override void LoadDefaultMessages() {
lang.RegisterMessages(new Dictionary<string, string> {
["SyntaxPlayer"]
= "<color=red>Invalid syntax</color>, use:\n\n<color=green>/hsgive <type> <SteamID/PlayerName> <amount></color>", ["Receive"] = "You received <color=orange>{0}</color> x <color=orange>{1}</color>!", ["PlayerReceive"] = "Player {0} ({1}) received {2} x {3}!", ["Permission"] = "You do not have permission to use <color=orange>{0}</color>!", ["CooldownTime"] = "Cooldown active! You can call another in {0} seconds!", ["GlobalLimit"] = "Global limit of {0} active helicopters is reached, please try again later", ["NotAdmin"] = "You do not have permission to use that command!", ["PlayerNotFound"] = "Can't find a player with the name or ID: {0}", ["InGameOnly"] = "Error: This command is only for use in game!", ["PlayerDead"] = "Player with name or ID {0} is dead, try again when they have respawned", ["InSafeZone"] = "<color=orange>{0}</color> was thrown in a <color=green>Safe Zone</color> and was refunded, check inventory.", ["SyntaxConsole"] = "Invalid syntax, use: hsgive <type> <SteamID/PlayerName> <amount>", ["InvalidDrop"] = "Signal type \"{0}\" not recognised, please check and try again!", ["CannotLoot"] = "You cannot loot this because it is not yours!", ["CannotHarvest"] = "You cannot harvest this because it is not yours!", ["BuySyntax"] = "Useage:\n\n/hsbuy {0}", ["NoBuy"] = "Buy Command for <color=orange>{0}</color> Is Not Enabled!", ["BuyPermission"] = "You do not have permission to buy Heli Signal \"<color=orange>{0}</color>\".", ["PriceList"] = "Heli Signal Prices:\n\n{0}", ["HeliKilled"] = "<color=orange>{0}</color> killed by <color=green>{1}</color> in grid <color=green>{2}</color>", ["HeliCalled"] = "<color=green>{0}</color> just called in a <color=orange>{1}</color> to their location in grid <color=green>{2}</color>", ["PointsGiven"] = "<color=green>{0} {1}</color> received for destroying <color=orange>{2}</color>!", ["ScrapGiven"] = "<color=green>{0}</color> Scrap received for destroying <color=orange>{1}</color>!", ["CannotDamage"] = "You <color=red>Cannot</color> damage this <color=orange>{0}</color>!", ["TooFarAway"] = "You are <color=red>Too Far</color> away to engage this <color=orange>{0}</color> ({1} m)", ["CantAfford"] = "You <color=red>Cannot</color> afford this! Cost: <color=orange>{0}</color> Required: <color=orange>{1}</color>", ["HeliReportTitle"] = "There is currently <color=orange>{0}</color> active Helicopters", ["HeliReportItem"] = "<size=9><color=orange>{0}/{1}</color> - <color=green>{2}</color> (Owner: <color=orange>{3}</color> Grid: <color=orange>{4}</color> Health: <color=orange>{5}</color> Rotors: <color=orange>{6}/{7}</color> State: <color=orange>{8}</color>)\n</size>", ["HeliReportTitleCon"] = "There is currently {0} active Helicopters", ["HeliReportItemCon"] = "{0}/{1} - {2} (Owner: {3} Grid: {4} Health: {5} Rotors: {6}/{7} State: {8})\n", ["HeliReportList"] = "{0}"
}
, this, "en");
}
private string Lang(string messageKey, string playerID, params object[] args) {
return string.Format(lang.GetMessage(messageKey, this, playerID), args);
}
private void Message(IPlayer player, string messageKey, params object[] args) {
var message = Lang(messageKey, player.Id, args);
if (config.options.usePrefix && config.options.chatPrefix != string.Empty) {
if (player.IsServer) {
Regex regex = new Regex(@"(\[.*?\])");
Match match = regex.Match(config.options.chatPrefix);
player.Reply($"{match}: {message}");
}
else {
player.Reply($"{config.options.chatPrefix}: {message}");
}
}
else {
player.Reply(message);
}
}
private void Message(BasePlayer player, string messageKey, params object[] args) {
if (player is NPCPlayer) {
return;
}
var message = Lang(messageKey, player.UserIDString, args);
if (config.options.usePrefix && config.options.chatPrefix != string.Empty) {
player.ChatMessage($"{config.options.chatPrefix}: {message}");
}
else {
player.ChatMessage(message);
}
}
#endregion Language
#region Oxide Hooks
private void OnServerInitialized() {
plugin = this;
CheckRewardPlugin();
}
private void Init() {
permission.RegisterPermission(permAdmin, this);
permission.RegisterPermission(permBuy, this);
permission.RegisterPermission(permBypasscooldown, this);
config.rewards.RegisterPermissions(permission, this);
config.heli.RegisterPermissions(permission, this);
foreach (var key in config.heli.heliConfig.Keys) {
var permSuffix = config.heli.heliConfig[key].GiveItemCommand.ToLower();
var perm = $"{Name.ToLower()}.{permSuffix}";
permission.RegisterPermission(perm, this);
HeliTypes.Add(config.heli.heliConfig[key].GiveItemCommand);
}
}
private void Unload() {
foreach (var netId in HeliSignalData.Keys) {
var heli = BaseNetworkable.serverEntities.Find(netId) as BaseHelicopter;
if (heli != null) {
if (IsHeliDrop(heli.skinID)) {
heli.Kill();
}
}
}
HeliSignalData.Clear();
PlayerCooldowns.Clear();
HeliTypes.Clear();
RewardPlugin = null;
plugin = null;
}
private void OnItemAddedToContainer(ItemContainer container, Item item) {
if (IsHeliDrop(item.skin)) {
FixSignalInfo(item);
}
}
private void OnExplosiveThrown(BasePlayer player, SupplySignal entity, ThrownWeapon item) {
var signal = item.GetItem();
if (signal != null) {
var skinId = signal.skin;
if (IsHeliDrop(skinId)) {
entity.EntityToCreate = null;
entity.CancelInvoke(entity.Explode);
if (signal.name == null || !config.heli.heliConfig.ContainsKey(signal.name)) {
FixSignalInfo(signal);
}
var heliProfile = signal.name;
var permSuffix = config.heli.heliConfig[heliProfile].GiveItemCommand.ToLower();
var perm = $"{Name.ToLower()}.{permSuffix}";
if (!player.IPlayer.HasPermission(perm)) {
Message(player, "Permission", heliProfile);
GiveHeliDrop(player, skinId, heliProfile, 1, "refund");
entity.Kill();
return;
}
else if (config.heli.playerCooldown > 0f && !player.IPlayer.HasPermission(permBypasscooldown)) {
float cooldown;
if (PlayerCooldowns.TryGetValue(player.userID, out cooldown)) {
TimeSpan time = TimeSpan.FromSeconds(cooldown - UnityEngine.Time.time);
Message(player, "CooldownTime", time.ToString(@"hh\:mm\:ss"));
GiveHeliDrop(player, skinId, heliProfile, 1, "refund");
entity.Kill();
return;
}
else {
cooldown = config.heli.playerCooldown;
foreach (KeyValuePair<string, float> keyPair in config.heli.vipCooldowns) {
if (player.IPlayer.HasPermission(keyPair.Key)) {
cooldown = keyPair.Value;
}
}
ulong userId = player.userID;
PlayerCooldowns[userId] = UnityEngine.Time.time + cooldown;
timer.Once(cooldown, () => {
if (PlayerCooldowns.ContainsKey(userId)) {
PlayerCooldowns.Remove(userId);
}
}
);
}
}
entity.gameObject.AddComponent<HeliSignalComponent>();
var signalComponent = entity.gameObject.GetComponent<HeliSignalComponent>();
if (signalComponent != null) {
signalComponent.signal = entity;
signalComponent.position = entity.transform.position;
signalComponent.player = player;
signalComponent.skinId = skinId;
signalComponent.heliProfile = heliProfile;
}
}
}
}
private void OnExplosiveDropped(BasePlayer player, SupplySignal entity, ThrownWeapon item) => OnExplosiveThrown(player, entity, item);
private object OnEntityTakeDamage(BaseHelicopter heli, HitInfo info) {
if (heli?._name == null || heli?._name == string.Empty) {
return null;
}
else if (IsHeliDrop(heli.skinID)) {
var heliProfile = heli._name;
if (!config.heli.heliConfig.ContainsKey(heliProfile)) return null;
var attacker = info?.Initiator as BasePlayer;
if (attacker != null) {
var heliDisplayName = config.heli.heliConfig[heliProfile].HeliName;
if (config.heli.heliConfig[heliProfile].OwnerDamage) {
if (config.options.useFriends || config.options.useClans || config.options.useTeams) {
if (attacker.userID != heli.OwnerID && !IsFriend(attacker.userID, heli.OwnerID)) {
Message(attacker, "CannotDamage", heliDisplayName);
CancelHit(info);
return true;
}
}
else {
if (attacker.userID != heli.OwnerID) {
Message(attacker, "CannotDamage", heliDisplayName);
CancelHit(info);
return true;
}
}
}
var dist = Vector3.Distance(heli.transform.position, attacker.transform.position);
var maxDist = config.heli.maxHitDistance;
if (maxDist > 0 && dist > maxDist) {
Message(attacker, "TooFarAway", heliDisplayName, maxDist);
CancelHit(info);
return true;
}
var heliId = heli.net.ID;
if (!HeliSignalData.ContainsKey(heliId)) HeliSignalData.Add(heliId, new HeliStats());
if (!HeliSignalData[heliId].Attackers.ContainsKey(attacker.userID)) HeliSignalData[heliId].Attackers.Add(attacker.userID, 0f);
HeliSignalData[heliId].Attackers[attacker.userID] += info.damageTypes.Total();
var heliAI = heli.GetComponent<PatrolHelicopterAI>();
if (!(heliAI._currentState == PatrolHelicopterAI.aiState.DEATH)) HeliSignalData[heliId].LastAttacker = attacker;
var heliComp = heli.GetComponent<HeliComponent>();
NextTick(() => {
if (heliAI._currentState == PatrolHelicopterAI.aiState.DEATH && !heliComp.IsDying) {
heliComp.IsDying = true;
if (config.rewards.enableRewards && config.heli.heliConfig[heliProfile].RewardPoints > 0) {
if (plugins.Find(config.rewards.rewardPlugin)) {
foreach (var playerId in HeliSignalData[heliId].Attackers) {
if (playerId.Value >= config.heli.heliConfig[heliProfile].DamageThreshold) {
var amount = config.heli.heliConfig[heliProfile].RewardPoints / HeliSignalData[heliId].Attackers.Count;
GiveReward(playerId.Key, amount, heliProfile);
}
}
}
}
if (config.rewards.enableScrap && config.heli.heliConfig[heliProfile].ScrapReward > 0) {
foreach (var playerId in HeliSignalData[heliId].Attackers) {
if (playerId.Value >= config.heli.heliConfig[heliProfile].DamageThreshold) {
var amount = config.heli.heliConfig[heliProfile].ScrapReward / HeliSignalData[heliId].Attackers.Count;
GiveScrap(playerId.Key, amount, heliProfile);
}
}
}
}
}
);
}
}
return null;
}
private object OnEntityKill(BaseHelicopter heli) {
var skinId = heli.skinID;
if (IsHeliDrop(skinId)) {
var position = heli.transform.position;
var ownerId = heli.OwnerID;
var heliProfile = heli._name;
var heliId = heli.net.ID;
var gridPos = PositionToGrid(heli.transform.position);
BasePlayer player = HeliSignalData[heliId].LastAttacker;
if (player == null || !player.IsAlive()) return null;
if (config.announce.killGlobal && gridPos != null) {
var heliDisplayName = config.heli.heliConfig[heliProfile].HeliName;
var message = string.Format(lang.GetMessage("HeliKilled", this, player.UserIDString), heliDisplayName, player.displayName, gridPos);
server.Broadcast(message, config.options.usePrefix ? config.options.chatPrefix : null, 0);
}
List<BaseEntity> ents = new List<BaseEntity>();
Vis.Entities(position, 20f, ents);
foreach (var ent in ents) {
if ((ent is HelicopterDebris) || (ent is LockedByEntCrate) || (ent is FireBall)) {
ent.OwnerID = ownerId;
ent.skinID = skinId;
ent._name = heliProfile;
ProcessHeliEnt(ent);
}
}
timer.Once(1f, () => {
if (HeliSignalData.ContainsKey(heliId)) HeliSignalData.Remove(heliId);
}
);
}
return null;
}
private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info) {
if (info == null || entity == null) {
return null;
}
var damageType = info.damageTypes.GetMajorityDamageType();
if (damageType == DamageType.Bullet && (entity is BasePlayer) && (info.Initiator is BaseHelicopter)) {
var heli = info.Initiator;
if (IsHeliDrop(heli.skinID)) {
string heliProfile = heli._name;
if (heliProfile != null || heliProfile != string.Empty) {
if (config.heli.heliConfig.ContainsKey(heliProfile)) {
System.Random random = new System.Random();
float hitProb = (float)random.Next(1, 100);
if (config.heli.heliConfig[heliProfile].BulletAccuracy < hitProb) {
CancelHit(info);
return true;
}
}
}
}
}
return null;
}
private object CanLootEntity(BasePlayer player, LockedByEntCrate entity) {
if (entity?._name == null || entity._name == string.Empty) {
return null;
}
else if (IsHeliDrop(entity.skinID)) {
string heliProfile = entity._name;
if (heliProfile != null || heliProfile != string.Empty) {
if (config.heli.heliConfig.ContainsKey(heliProfile)) {
if (config.heli.heliConfig[heliProfile].ProtectCrates && entity.OwnerID != 0) {
if (config.options.useFriends || config.options.useClans || config.options.useTeams) {
if (player.userID != entity.OwnerID && !IsFriend(player.userID, entity.OwnerID)) {
Message(player, "CannotLoot");
return true;
}
}
else {
if (player.userID != entity.OwnerID) {
Message(player, "CannotLoot");
return true;
}
}
}
}
}
}
return null;
}
private object OnPlayerAttack(BasePlayer attacker, HitInfo info) {
if (attacker == null || info == null) {
return null;
}
BaseEntity entity = info.HitEntity;
if (entity != null) {
if (entity is ServerGib && IsHeliDrop(entity.skinID)) {
var heliProfile = entity._name;
if (heliProfile != null || heliProfile != string.Empty) {
if (config.heli.heliConfig.ContainsKey(heliProfile)) {
if (config.heli.heliConfig[heliProfile].ProtectGibs && entity.OwnerID != 0) {
if (config.options.useFriends || config.options.useClans || config.options.useTeams) {
if (attacker.userID != entity.OwnerID && !IsFriend(attacker.userID, entity.OwnerID)) {
Message(attacker, "CannotHarvest");
CancelHit(info);
return false;
}
}
else {
if (attacker.userID != entity.OwnerID) {
Message(attacker, "CannotHarvest");
CancelHit(info);
return false;
}
}
}
}
}
}
}
return null;
}
private void OnLootSpawn(LootContainer lootContainer) {
NextTick(() => {
var skinId = lootContainer.skinID;
if (IsHeliDrop(skinId)) {
var heliProfile = lootContainer._name;
if (heliProfile == null || heliProfile == string.Empty) return;
lootContainer.inventory.capacity = 12;
// unlock all slots
SpawnLoot(lootContainer, heliProfile);
}
}
);
}
private string PositionToGrid(Vector3 position) => PhoneController.PositionToGridCoord(position);
#endregion Oxide Hooks
private void SpawnLoot(LootContainer lootContainer, string heliProfile) {
if (heliProfile == null || heliProfile == string.Empty) return;
timer.Once(1f, () => {
if (config.heli.heliConfig[heliProfile].Loot.UseCustomLoot) {
lootContainer.inventory.Clear();
ItemManager.DoRemoves();
List<LootItem> lootTable = new List<LootItem>(config.heli.heliConfig[heliProfile].Loot.LootTable);
List<LootItem> items = lootTable;
if (items == null || lootTable == null) return;
var minItems = config.heli.heliConfig[heliProfile].Loot.MinCrateItems;
var maxItems = config.heli.heliConfig[heliProfile].Loot.MaxCrateItems;
int count = UnityEngine.Random.Range(minItems, maxItems + 1);
for (int i = 0; i < count; i++) {
LootItem lootItem = items.GetRandom();
if (lootItem == null) {
i--;
continue;
}
if (lootItem.Chance < UnityEngine.Random.Range(0f, 100f)) {
i--;
continue;
}
if (!config.heli.heliConfig[heliProfile].Loot.AllowDupes) items.Remove(lootItem);
if (items.Count == 0) items.AddRange(lootTable);
var amount = UnityEngine.Random.Range(lootItem.AmountMin, lootItem.AmountMax + 1);
Item item = ItemManager.CreateByName(lootItem.ShortName, amount, lootItem.SkinId);
if (item != null) {
item.name = lootItem.DisplayName;
if (item.MoveToContainer(lootContainer.inventory)) {
lootContainer.inventory.MarkDirty();
continue;
}
item.Remove(0f);
}
}
}
if (config.heli.heliConfig[heliProfile].ExtraLoot.UseExtraLoot) {
AddExtraLoot(lootContainer, heliProfile);
}
}
);
}
private void AddExtraLoot (LootContainer lootContainer, string heliProfile) {
if (lootContainer == null) return;
if (heliProfile == null || heliProfile == string.Empty) return;
List<LootItem> lootTable = new List<LootItem>(config.heli.heliConfig[heliProfile].ExtraLoot.LootTable);
List<LootItem> items = lootTable;
if (items == null || lootTable == null) return;
var minItems = config.heli.heliConfig[heliProfile].ExtraLoot.MinExtraItems;
var maxItems = config.heli.heliConfig[heliProfile].ExtraLoot.MaxExtraItems;
int count = UnityEngine.Random.Range(minItems, maxItems + 1);
for (int i = 0; i < count; i++) {
LootItem lootItem = items.GetRandom();
if (lootItem == null) {
i--;
continue;
}
if (lootItem.Chance < UnityEngine.Random.Range(0f, 100f)) {
i--;
continue;
}
if (!config.heli.heliConfig[heliProfile].ExtraLoot.AllowDupes) items.Remove(lootItem);
if (items.Count == 0) items.AddRange(lootTable);
var amount = UnityEngine.Random.Range(lootItem.AmountMin, lootItem.AmountMax + 1);
Item item = ItemManager.CreateByName(lootItem.ShortName, amount, lootItem.SkinId);
if (item != null) {
item.name = lootItem.DisplayName;
if (item.MoveToContainer(lootContainer.inventory)) {
lootContainer.inventory.MarkDirty();
continue;
}
item.Remove(0f);
}
}
}
#region API
// Other devs can call these hooks to help with compatability with their plugins if needed
object IsHeliSignalObject(ulong skinId) => IsHeliDrop(skinId) ? true : (object)null;
// Play nice with fancyDrop
object ShouldFancyDrop(uint netId) {
var signal = BaseNetworkable.serverEntities.Find(netId) as BaseEntity;
if (signal != null) {
if (IsHeliDrop(signal.skinID)) return true;
}
return null;
}
#endregion API
#region Rewards
private void CheckRewardPlugin() {
RewardPlugin = plugins.Find(config.rewards.rewardPlugin);
if (RewardPlugin == null) Puts($"{config.rewards.rewardPlugin} not found, giving rewards is not possible until loaded.");
}
private void GiveReward(ulong playerId, double amount, string heliProfile) {
foreach (KeyValuePair<string, float> keyPair in config.rewards.rewardMultipliers) {
if (permission.UserHasPermission(playerId.ToString(), keyPair.Key)) {
if (keyPair.Value > 1.0f) amount *= keyPair.Value;
}
}
BasePlayer player = FindPlayer(playerId.ToString())?.Object as BasePlayer;
if (player) {
switch (config.rewards.rewardPlugin.ToLower()) {
case "serverrewards" : RewardPlugin?.Call("AddPoints", playerId, (int)amount);
Message(player, "PointsGiven", (int)amount, config.rewards.rewardUnit, heliProfile);
break;
case "economics" : RewardPlugin?.Call("Deposit", playerId, amount);
Message(player, "PointsGiven", config.rewards.rewardUnit, (int)amount, heliProfile);
break;
default : break;
}
}
}
private void GiveScrap(ulong playerId, int amount, string heliProfile) {
foreach (KeyValuePair<string, float> keyPair in config.rewards.rewardMultipliers) {
if (permission.UserHasPermission(playerId.ToString(), keyPair.Key)) {
if (keyPair.Value > 1.0f) amount = (int)(amount * keyPair.Value);
}
}
BasePlayer player = FindPlayer(playerId.ToString())?.Object as BasePlayer;
if (player) {
Item scrap = ItemManager.CreateByItemID(scrapId, amount, 0);
player.inventory.GiveItem(scrap);
Message(player, "ScrapGiven", amount, heliProfile);
}
}
#endregion Rewards
#region Helpers
private object FixSignalInfo(Item signal) {
if (signal.name == null || !config.heli.heliConfig.ContainsKey(signal.name)) {
foreach (var key in config.heli.heliConfig.Keys) {
if (signal.skin == config.heli.heliConfig[key].SignalSkinID) {
signal.name = key;
signal.skin = config.heli.heliConfig[key].SignalSkinID;
return signal;
}
}
}
return signal;
}
private void ProcessHeliEnt (BaseEntity entity) {
if (entity != null) {
NextTick(() => {
var heliProfile = entity._name;
if (heliProfile != null || heliProfile != string.Empty) {
if (entity is HelicopterDebris) {
var debris = entity?.GetComponent<HelicopterDebris>() ?? null;
if (debris != null) {
debris.InitializeHealth(config.heli.heliConfig[heliProfile].GibsHealth, config.heli.heliConfig[heliProfile].GibsHealth);
debris.SendNetworkUpdate();
if (config.heli.heliConfig[heliProfile].KillGibs) entity.Kill();
else if (config.heli.heliConfig[heliProfile].DisableFire) debris.tooHotUntil = UnityEngine.Time.realtimeSinceStartup;
else if (config.heli.heliConfig[heliProfile].GibsHotTime > 0) debris.tooHotUntil = UnityEngine.Time.realtimeSinceStartup + config.heli.heliConfig[heliProfile].GibsHotTime;
if (config.heli.heliConfig[heliProfile].ProtectGibs && config.heli.heliConfig[heliProfile].UnlockGibs > 0) {
float unlockTime = config.heli.heliConfig[heliProfile].DisableFire ? config.heli.heliConfig[heliProfile].UnlockGibs : (config.heli.heliConfig[heliProfile].FireDuration + config.heli.heliConfig[heliProfile].UnlockGibs);
RemoveHeliOwner(entity, unlockTime);
}
debris.SendNetworkUpdateImmediate();
}
}
else if (entity is FireBall) {
var fireball = entity?.GetComponent<FireBall>() ?? null;
if (fireball != null) {
if (config.heli.heliConfig[heliProfile].DisableFire) {
fireball.enableSaving = false;
entity.Kill();
}
else {
timer.Once(config.heli.heliConfig[heliProfile].FireDuration, () => {
if (entity != null || !entity.IsDestroyed || fireball != null) {
fireball.enableSaving = false;
entity.Kill();
}
}
);
}
fireball.SendNetworkUpdateImmediate();
}
}
else if (entity is LockedByEntCrate) {
var crate = entity?.GetComponent<LockedByEntCrate>();
if (crate != null) {
if (config.heli.heliConfig[heliProfile].FireDuration > 0 && !config.heli.heliConfig[heliProfile].DisableFire) {
timer.Once(config.heli.heliConfig[heliProfile].FireDuration, () => {
if (crate != null) {
if (crate.lockingEnt != null) {
var lockingEnt = crate.lockingEnt.GetComponent<FireBall>();
if (lockingEnt != null) {
lockingEnt.enableSaving = false;
lockingEnt.Kill();
}
}
crate.CancelInvoke(crate.Think);
crate.SetLocked(false);
crate.lockingEnt = null;
}
}
);
}
else {
if (crate.lockingEnt != null) {
var lockingEnt = crate?.lockingEnt.GetComponent<FireBall>();
if (lockingEnt != null) {
lockingEnt.enableSaving = false;
lockingEnt.Kill();
}
}
crate.CancelInvoke(crate.Think);
crate.SetLocked(false);
crate.lockingEnt = null;
}
if (config.heli.heliConfig[heliProfile].ProtectCrates && config.heli.heliConfig[heliProfile].UnlockCrates > 0) {
float unlockTime = config.heli.heliConfig[heliProfile].DisableFire ? config.heli.heliConfig[heliProfile].UnlockCrates : (config.heli.heliConfig[heliProfile].FireDuration + config.heli.heliConfig[heliProfile].UnlockCrates);
RemoveHeliOwner(entity, unlockTime);
}
}
}
}
}
);
}
}
private bool IsHeliDrop(ulong skinId) {
if (skinId != 0) {
foreach (var key in config.heli.heliConfig.Keys) {
if (skinId == config.heli.heliConfig[key].SignalSkinID) return true;
}
}
return false;
}
private void CancelHit(HitInfo info) {
if (info != null) {
info.damageTypes = new DamageTypeList();
info.DoHitEffects = false;
info.DidHit = false;
}
}
private void RemoveHeliOwner(BaseNetworkable entity, float time) {
timer.Once(time, () => {
if (entity != null || !entity.IsDestroyed) {
(entity as BaseEntity).OwnerID = 0;
entity.SendNetworkUpdateImmediate();
}
}
);
}
private void DespawnHeli(PatrolHelicopterAI heli, float despawnTime) {
timer.Once(despawnTime, () => {
if (heli != null) {
heli.Retire();
return;
}
}
);
}
private void GiveHeliDrop(BasePlayer player, ulong skinId, string dropName, int dropAmount, string reason) {
if (player != null && player.IsAlive()) {
Item heliDrop = ItemManager.CreateByItemID(supplySignalId, dropAmount, skinId);
heliDrop.name = dropName;
player.inventory.GiveItem(heliDrop);
}
}
private bool IsInSafeZone(Vector3 position) {
int loop = Physics.OverlapSphereNonAlloc(position, 1f, Vis.colBuffer, 1 << 18, QueryTriggerInteraction.Collide);
for (int i = 0; i < loop; i++) {
Collider collider = Vis.colBuffer[i];
if (collider.GetComponent<TriggerSafeZone>()) return true;
}
return false;
}
private IPlayer FindPlayer(string nameOrIdOrIp) {
foreach (var activePlayer in covalence.Players.Connected) {
if (activePlayer.Id == nameOrIdOrIp) return activePlayer;
if (activePlayer.Name.Contains(nameOrIdOrIp)) return activePlayer;
if (activePlayer.Name.ToLower().Contains(nameOrIdOrIp.ToLower())) return activePlayer;
if (activePlayer.Address == nameOrIdOrIp) return activePlayer;
}
return null;
}
private bool IsFriend(ulong playerId, ulong targetId) {
if (playerId == 0 || targetId == 0) return false;
if (playerId == targetId) return true;
if (Clans) {
var result = Clans?.Call("IsMemberOrAlly", playerId, targetId);
if (result != null && Convert.ToBoolean(result)) return true;
}
if (Friends) {
var result = Friends?.Call("AreFriends", playerId, targetId);
if (result != null && Convert.ToBoolean(result)) return true;
}
RelationshipManager.PlayerTeam team;
RelationshipManager.ServerInstance.playerToTeam.TryGetValue(playerId, out team);
if (team == null) return false;
if (team.members.Contains(targetId)) return true;
return false;
}
#endregion Helpers
#region Commands
[Command("helisignals.report", "hsreport")]
private void CmdReport(IPlayer player, string command, string[] args) {
string activeHelis = String.Empty;
int count = 0;
int total = HeliSignalData.Count;
if (total == 0) {
Message(player, "HeliReportTitleCon", "NO");
return;
}
if (player.IsServer) Message(player, "HeliReportTitleCon", total);
else Message(player, "HeliReportTitle", total);
foreach (var netId in HeliSignalData.Keys) {
var heli = BaseNetworkable.serverEntities.Find(netId) as BaseHelicopter;
if (heli != null) {
if (IsHeliDrop(heli.skinID)) {
count++;
Vector3 position = heli.transform.position;
var gridPos = PositionToGrid(position);
if (gridPos == null) return;
HeliComponent heliComp = heli.GetComponent<HeliComponent>();
if (heliComp == null) return;
BasePlayer owner = heliComp.owner;
if (owner == null) return;
string heliProfile = heliComp.heliProfile;
if (heliProfile == null) return;
var message = String.Empty;
if (player.IsServer) message = Lang("HeliReportItemCon", player.Id, count, total, config.heli.heliConfig[heliProfile].HeliName, owner.displayName, gridPos, heli.health, heli.weakspots[0].health, heli.weakspots[1].health, heliComp.heliAI._currentState);
else message = Lang("HeliReportItem", player.Id, count, total, config.heli.heliConfig[heliProfile].HeliName, owner.displayName, gridPos, heli.health, heli.weakspots[0].health, heli.weakspots[1].health, heliComp.heliAI._currentState);
activeHelis += ($"{message}");
message = String.Empty;
}
}
}
config.options.usePrefix = false;
Message(player, "HeliReportList", activeHelis);
activeHelis = String.Empty;
config.options.usePrefix = true;
}
[Command("helisignals.buy", "hsbuy")]
private void CmdBuy(IPlayer player, string command, string[] args) {
if (player.IsServer) {
Message(player, "InGameOnly");
return;
}
else if (args?.Length < 1 || args?.Length > 1) {
Message(player, "BuySyntax", string.Join("|", HeliTypes));
return;
}
string currencyItem = config.purchasing.defaultCurrency;
string priceFormat;
string priceUnit;
if (args?[0].ToLower() == "list") {
string list = String.Empty;
foreach (var key in config.heli.heliConfig.Keys) {
switch (currencyItem) {
case "ServerRewards" : {
priceFormat = $"{config.heli.heliConfig[key].CostToBuy} {config.purchasing.purchaseUnit}";
}
break;
case "Economics" : {
priceFormat = $"{config.purchasing.purchaseUnit}{config.heli.heliConfig[key].CostToBuy}";
}
break;
default : {
priceFormat = $"{config.heli.heliConfig[key].CostToBuy} {config.purchasing.customCurrency[0].DisplayName}";
}
break;
}
list += ($"{config.heli.heliConfig[key].HeliName} : {priceFormat}\n");
}
Message(player, "PriceList", list);
return;
}
string type = args[0].ToLower();
ulong skinId = 0;
string heliProfile = string.Empty;
foreach (var key in config.heli.heliConfig.Keys) {
if (type == config.heli.heliConfig[key].GiveItemCommand.ToLower()) {
skinId = config.heli.heliConfig[key].SignalSkinID;
heliProfile = key;
break;
}
}
if (!HeliTypes.Contains(type)) {
Message(player, "InvalidDrop", type);
return;
}
if (!player.HasPermission(permBuy)) {
Message(player, "BuyPermission", type);
return;
}
if (!config.heli.heliConfig[heliProfile].UseBuyCommand) {
Message(player, "NoBuy", type);
return;
}
BasePlayer basePlayer = player.Object as BasePlayer;
if (basePlayer == null) return;
switch (currencyItem) {
case "ServerRewards" : {
var cost = config.heli.heliConfig[heliProfile].CostToBuy;
var balance = RewardPlugin?.Call("CheckPoints", basePlayer.userID);
if (balance != null) {
if (cost <= Convert.ToInt32(balance)) {
RewardPlugin?.Call("TakePoints", basePlayer.userID, cost);
GiveHeliDrop(basePlayer, skinId, heliProfile, 1, "give");
Message(player, "Receive", 1, heliProfile);
return;
}
else {
Message(player, "CantAfford", $"{cost} {config.purchasing.purchaseUnit}", $"{cost - Convert.ToDouble(balance)} {config.purchasing.purchaseUnit}");
return;
}
}
}
break;
case "Economics" : {
var cost = Convert.ToDouble(config.heli.heliConfig[heliProfile].CostToBuy);
var balance = RewardPlugin?.Call("Balance", basePlayer.userID);
if (balance != null) {
if (cost <= Convert.ToDouble(balance)) {
RewardPlugin?.Call("Withdraw", basePlayer.userID, cost);
GiveHeliDrop(basePlayer, skinId, heliProfile, 1, "give");
Message(player, "Receive", 1, heliProfile);
return;
}
else {
Message(player, "CantAfford", $"{config.purchasing.purchaseUnit}{cost}", $"{config.purchasing.purchaseUnit}{cost - Convert.ToDouble(balance)}");
return;
}
}
}
break;
default : {
var shortName = config.purchasing.customCurrency[0].ShortName;
var displayName = config.purchasing.customCurrency[0].DisplayName;
var currencySkin = config.purchasing.customCurrency[0].SkinId;
var cost = config.heli.heliConfig[heliProfile].CostToBuy;
int balance = 0;
ItemDefinition itemDef = ItemManager.FindItemDefinition(shortName);
ItemContainer[] inventories = {
basePlayer.inventory.containerMain, basePlayer.inventory.containerWear, basePlayer.inventory.containerBelt
}
;
for (int i = 0; i < inventories.Length; i++) {
foreach (var item in inventories[i].itemList) {
if (item.info.shortname == shortName && item.skin == currencySkin) {
balance = item.amount;
if (cost <= balance) {
item.amount -= cost;
item.MarkDirty();
if (item.amount < 1) item.Remove();
GiveHeliDrop(basePlayer, skinId, heliProfile, 1, "give");
Message(player, "Receive", 1, heliProfile);
return;
}
}
}
}
Message(player, "CantAfford", $"{cost} {displayName}", $"{cost - balance} {displayName}");
return;
}
break;
}
}
[Command("helisignals.give", "hsgive")]
private void CmdGiveNpcNade(IPlayer player, string command, string[] args) {
if (!player.HasPermission(permAdmin)) {
// ... [Code preview truncated due to length. Full source in attached file] ...