Stopped running after Rust update...
Stopped running after Rust updateSolved
same here
Error while compiling: BarrellessOil.cs(358,34): error CS1501: No overload for method `Init' takes `14' arguments
This is not my plugin, but I changed the npc.Brain.Senses.Init under _UseBrain() to
npc.Brain.Senses.Init(npc, npc.Brain, 5f, 30f, 40f, 135f, true, true, true, 60f, false, false, true, EntityType.Player, true); for Zombies
and
npc.Brain.Senses.Init(npc, npc.Brain, 5f, 50f, 50f, -1f, true, false, true, 60f, false, false, false, EntityType.Player, false); for Scientists and that got it to compile.
Merged post
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using Oxide.Core;
using Oxide.Core.Plugins;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Facepunch;
using Rust;
using Rust.Ai;
#region Changelogs and ToDo
/**********************************************************************
*
* 1.0.0 - initial release
* 2.0.0 - Rewrite V2
* 2.1.0 - Patched for compile after Rust Update removing various AI
* 3.0.0 - Rewrite V3
* - Added Scarecrow Attack Behaviour to be less stuck on targets
* - Added scientist and scarecrows Roaming Behaviour
* - Added support for kits for scientist and scarecrows
* - Added spawn amount for for scientist and scarecrows
* - Added scientist and scarecrows to get their prefix(title) + random name assigned
* - Added Seperate prefix for scarecrow with a chainsaw
* - Airdrops skips spawn if the barrel is not outside
* and will gives the player a supply.signal or drops it on the floor
* if player inventory is full
* - Added amount of animals spawning per animal type
* - Added Health settings per animal type
* - If more then 1 npc or animal are set to spawn they will give a different chat message
* - Added F1Grenade to the explosives spawn list
* 3.0.1 - Added support for PolarBears
* 3.0.2 - Added Global setting to only spawn outside
* Added animal life duration
* Added permission system
* 3.0.3 - Added Max range to trigger events to the config
* 3.0.4 - My hacked up attempt to fix the npc.Brain.Senses (Wayward)
*
* Todo - Readd Fires and their behaviour/spawn area
* - Add Mono for animals (roam and other stuff)
* - Add day/night spawnrates
*
**********************************************************************/
#endregion
namespace Oxide.Plugins
{
[Info("Barrelless", "Krungh Crow", "3.0.3")]
[Description("various events after barrel kills")]
class Barrelless : RustPlugin
{
[PluginReference] Plugin Kits;
#region Variables
#region Plugin
bool BlockSpawn;
bool Signaldropped;
ulong chaticon;
string prefix;
System.Random rnd = new System.Random();
private ConfigData configData;
public static Barrelless instance;
#endregion
#region Permissions
const string GlobalTrigger_Perm = "barrelless.globaltrigger";
const string SciTrigger_Perm = "barrelless.scientist";
const string ScareTrigger_Perm = "barrelless.scarecrow";
const string BearTrigger_Perm = "barrelless.bear";
const string PBearTrigger_Perm = "barrelless.polarbear";
const string BoarTrigger_Perm = "barrelless.boar";
const string ChickenTrigger_Perm = "barrelless.chicken";
const string WolfTrigger_Perm = "barrelless.wolf";
const string ExploTrigger_Perm = "barrelless.explosive";
const string AirdropTrigger_Perm = "barrelless.airdrop";
#endregion
#region NPC
const string zombie = "assets/prefabs/npc/scarecrow/scarecrow.prefab";
const string _scientist = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_roam.prefab";
float SciDamageScale;
int SciHealth;
List<string> SciKit;
float SciLifetime;
string SciName;
bool _UseKit;
bool _FromHell;
#endregion
#region Animals
const string bearString = "assets/rust.ai/agents/bear/bear.prefab";
const string PBearString = "assets/rust.ai/agents/bear/polarbear.prefab";
const string boarstring = "assets/rust.ai/agents/boar/boar.prefab";
const string chickenString = "assets/rust.ai/agents/chicken/chicken.prefab";
const string wolfString = "assets/rust.ai/agents/wolf/wolf.prefab";
int _AnimalHealth;
string _AnimalString;
float _AnimalLife;
#endregion
#region Fires
const string fireString = "assets/prefabs/npc/m2bradley/oilfireball2.prefab";
const string fire2String = "assets/bundled/prefabs/oilfireballsmall.prefab";
const string fire3String = "assets/bundled/prefabs/fireball.prefab";
const string fireball1 = "assets/bundled/prefabs/fireball.prefab";//convert to fire3string
#endregion
#region Drops
const string airdropString = "assets/prefabs/misc/supply drop/supply_drop.prefab";
const string beancanString = "assets/prefabs/weapons/beancan grenade/grenade.beancan.deployed.prefab";
const string grenadeString = "assets/prefabs/weapons/f1 grenade/grenade.f1.deployed.prefab";
#endregion
#region Data
const string file_main = "barrelless_players/";
#endregion
#endregion
#region Behaviours
#region Scarecrow
private class Zombies : FacepunchBehaviour
{
private ScarecrowNPC npc;
public bool ReturningToHome = false;
public bool isRoaming = true;
public Vector3 SpawnPoint;
private void Awake()
{
npc = GetComponent<ScarecrowNPC>();
Invoke(nameof(_UseBrain), 0.1f);
InvokeRepeating(Attack, 0.1f, 1.5f);
InvokeRepeating(GoHome, 2.0f, 4.5f);
}
private void Attack()
{
BaseEntity entity = npc.Brain.Senses.GetNearestThreat(40);
Chainsaw heldEntity = npc.GetHeldEntity() as Chainsaw;
if (entity == null || Vector3.Distance(entity.transform.position, npc.transform.position) > 40.0f)
{
npc.Brain.Navigator.ClearFacingDirectionOverride();
GoHome();
}
if (entity != null && Vector3.Distance(entity.transform.position, npc.transform.position) < 2.0f)
{
npc.StartAttacking(entity);
npc.Brain.Navigator.SetFacingDirectionEntity(entity);
if (heldEntity is Chainsaw)
{
if (!(heldEntity as Chainsaw).EngineOn())
{
(heldEntity as Chainsaw).ServerNPCStart();
}
heldEntity.SetFlag(BaseEntity.Flags.Busy, true, false, true);
heldEntity.SetFlag(BaseEntity.Flags.Reserved8, true, false, true);
}
}
if (entity != null && Vector3.Distance(entity.transform.position, npc.transform.position) > 1.5f)
{
if (heldEntity is Chainsaw)
{
if (!(heldEntity as Chainsaw).EngineOn())
{
(heldEntity as Chainsaw).ServerNPCStart();
}
heldEntity.SetFlag(BaseEntity.Flags.Busy, false, false, true);
heldEntity.SetFlag(BaseEntity.Flags.Reserved8, false, false, true);
}
}
if (entity != null && Vector3.Distance(entity.transform.position, npc.transform.position) > 2.0f)
{
npc.Brain.Navigator.SetFacingDirectionEntity(entity);
}
}
public void _UseBrain()
{
#region navigation
npc.Brain.Navigator.Agent.agentTypeID = -1372625422;
npc.Brain.Navigator.DefaultArea = "Walkable";
npc.Brain.Navigator.Agent.autoRepath = true;
npc.Brain.Navigator.enabled = true;
npc.Brain.Navigator.CanUseNavMesh = true;
npc.Brain.Navigator.BestRoamPointMaxDistance = instance.configData.NPCData.NPCRoamMax;
npc.Brain.Navigator.MaxRoamDistanceFromHome = instance.configData.NPCData.NPCRoamMax;
npc.Brain.Navigator.Init(npc, npc.Brain.Navigator.Agent);
npc.Brain.Navigator.SetDestination(SpawnPoint, BaseNavigator.NavigationSpeed.Slow, 0f, 0f);
#endregion
#region senses & Targeting
npc.Brain.ForceSetAge(0);
npc.Brain.AllowedToSleep = false;
npc.Brain.sleeping = false;
npc.Brain.SenseRange = 30f;
npc.Brain.ListenRange = 40f;
npc.Brain.Senses.Init(npc, npc.Brain, 5f, 30f, 40f, 135f, true, true, true, 60f, false, false, true, EntityType.Player, true);
npc.Brain.TargetLostRange = 20f;
npc.Brain.HostileTargetsOnly = false;
npc.Brain.IgnoreSafeZonePlayers = true;
#endregion
}
void GoHome()
{
if (npc == null || npc.IsDestroyed || npc.isMounted)
return;
if (!npc.HasBrain)
return;
if (npc.Brain.Senses.Memory.Targets.Count > 0)
{
for (var i = 0; i < npc.Brain.Senses.Memory.Targets.Count; i++)
{
BaseEntity target = npc.Brain.Senses.Memory.Targets[i];
BasePlayer player = target as BasePlayer;
if (target == null || !player.IsAlive() || player.IsSleeping() || player.IsFlying)
{
WipeMemory();
ReturningToHome = true;
isRoaming = false;
return;
}
if (npc.Distance(player.transform.position) > 25f)
{
WipeMemory();
ReturningToHome = true;
isRoaming = false;
return;
}
if (player.IsSleeping() || player.IsFlying)
{
WipeMemory();
ReturningToHome = true;
isRoaming = false;
return;
}
}
}
var distanceHome = Vector3.Distance(npc.transform.position, SpawnPoint);
if (ReturningToHome == false)
{
if (isRoaming == true && distanceHome > instance.configData.NPCData.NPCRoamMax)
{
ReturningToHome = true;
isRoaming = false;
return;
}
if (isRoaming == true && distanceHome < instance.configData.NPCData.NPCRoamMax)
{
Vector3 random = UnityEngine.Random.insideUnitCircle.normalized * instance.configData.NPCData.NPCRoamMax;
Vector3 newPos = instance.GetNavPoint(SpawnPoint + new Vector3(random.x, 0f, random.y));
SettargetDestination(newPos);
return;
}
}
if (ReturningToHome && distanceHome > 2)
{
if (npc.Brain.Navigator.Destination == SpawnPoint)
{
return;
}
WipeMemory();
SettargetDestination(SpawnPoint);
return;
}
ReturningToHome = false;
isRoaming = true;
}
private void SettargetDestination(Vector3 position)
{
npc.Brain.Navigator.Destination = position;
npc.Brain.Navigator.SetDestination(position, BaseNavigator.NavigationSpeed.Slow, 0f, 0f);
}
void WipeMemory()
{
if (!npc.HasBrain)
{
return;
}
npc.Brain.Senses.Players.Clear();
npc.Brain.Senses.Memory.Players.Clear();
npc.Brain.Senses.Memory.Targets.Clear();
npc.Brain.Senses.Memory.Threats.Clear();
npc.Brain.Senses.Memory.LOS.Clear();
npc.Brain.Senses.Memory.All.Clear();
}
void OnDestroy()
{
if (npc != null && !npc.IsDestroyed)
{
npc.Kill();
}
CancelInvoke(GoHome);
CancelInvoke(Attack);
CancelInvoke(nameof(_UseBrain));
}
}
#endregion
#region Scientist
public class Scientists : FacepunchBehaviour
{
public global::HumanNPC npc;
public bool ReturningToHome = false;
public bool isRoaming = true;
public Vector3 SpawnPoint;
void Start()
{
npc = GetComponent<global::HumanNPC>();
InvokeRepeating("GoHome", 2.0f, 4.5f);
Invoke(nameof(_UseBrain), 0.1f);
}
public void _UseBrain()
{
#region navigation
npc.Brain.Navigator.Agent.agentTypeID = -1372625422;
npc.Brain.Navigator.DefaultArea = "Walkable";
npc.Brain.Navigator.Agent.autoRepath = true;
npc.Brain.Navigator.enabled = true;
npc.Brain.Navigator.CanUseNavMesh = true;
npc.Brain.Navigator.BestRoamPointMaxDistance = instance.configData.SCIData.NPCRoamMax;
npc.Brain.Navigator.MaxRoamDistanceFromHome = instance.configData.SCIData.NPCRoamMax;
npc.Brain.Navigator.Init(npc, npc.Brain.Navigator.Agent);
npc.Brain.Navigator.SetDestination(SpawnPoint, BaseNavigator.NavigationSpeed.Slow, 0f, 0f);
#endregion
#region senses & Targeting
npc.Brain.ForceSetAge(0);
npc.Brain.AllowedToSleep = false;
npc.Brain.sleeping = false;
npc.Brain.SenseRange = 30f;
npc.Brain.ListenRange = 40f;
npc.Brain.Senses.Init(npc, npc.Brain, 5f, 50f, 50f, -1f, true, false, true, 60f, false, false, false, EntityType.Player, false);
npc.Brain.TargetLostRange = 25f;
npc.Brain.HostileTargetsOnly = false;
npc.Brain.IgnoreSafeZonePlayers = true;
#endregion
}
void GoHome()
{
if (npc == null || npc.IsDestroyed || npc.isMounted)
return;
if (!npc.HasBrain)
return;
if (npc.Brain.Senses.Memory.Targets.Count > 0)
{
for (var i = 0; i < npc.Brain.Senses.Memory.Targets.Count; i++)
{
BaseEntity target = npc.Brain.Senses.Memory.Targets[i];
BasePlayer player = target as BasePlayer;
if (target == null || !player.IsAlive())
{
WipeMemory();
ReturningToHome = true;
isRoaming = false;
return;
}
if (npc.Distance(player.transform.position) > 40f)
{
WipeMemory();
ReturningToHome = true;
isRoaming = false;
return;
}
}
}
var distanceHome = Vector3.Distance(npc.transform.position, SpawnPoint);
if (ReturningToHome == false)
{
if (isRoaming == true && distanceHome > instance.configData.SCIData.NPCRoamMax)
{
ReturningToHome = true;
isRoaming = false;
return;
}
if (isRoaming == true && distanceHome < instance.configData.SCIData.NPCRoamMax)
{
Vector3 random = UnityEngine.Random.insideUnitCircle.normalized * instance.configData.SCIData.NPCRoamMax;
Vector3 newPos = instance.GetNavPoint(SpawnPoint + new Vector3(random.x, 0f, random.y));
SettargetDestination(newPos);
return;
}
}
if (ReturningToHome && distanceHome > 2)
{
if (npc.Brain.Navigator.Destination == SpawnPoint)
{
return;
}
WipeMemory();
SettargetDestination(SpawnPoint);
return;
}
ReturningToHome = false;
isRoaming = true;
}
private void SettargetDestination(Vector3 position)
{
npc.Brain.Navigator.Destination = position;
npc.Brain.Navigator.SetDestination(position, BaseNavigator.NavigationSpeed.Slow, 0f, 0f);
}
void WipeMemory()
{
if (!npc.HasBrain)
{
return;
}
npc.Brain.Senses.Players.Clear();
npc.Brain.Senses.Memory.Players.Clear();
npc.Brain.Senses.Memory.Targets.Clear();
npc.Brain.Senses.Memory.Threats.Clear();
npc.Brain.Senses.Memory.LOS.Clear();
npc.Brain.Senses.Memory.All.Clear();
}
void OnDestroy()
{
if (npc != null && !npc.IsDestroyed)
{
npc.Kill();
}
CancelInvoke("GoHome");
CancelInvoke(nameof(_UseBrain));
}
}
#endregion
#endregion
#region Configuration
class ConfigData
{
[JsonProperty(PropertyName = "Plugin Settings")]
public SettingsDrop DropData = new SettingsDrop();
[JsonProperty(PropertyName = "Airdrop Settings")]
public SettingsAirdrop AirdropData = new SettingsAirdrop();
[JsonProperty(PropertyName = "Scarecrow Settings")]
public NPCSettings NPCData = new NPCSettings();
[JsonProperty(PropertyName = "Scientist Settings")]
public SCISettings SCIData = new SCISettings();
[JsonProperty(PropertyName = "Animal Settings")]
public SettingsAnimal AnimalData = new SettingsAnimal();
[JsonProperty(PropertyName = "Explosives Settings")]
public SettingsExplosives ExplosivesData = new SettingsExplosives();
}
#region Plugin settings
class SettingsDrop
{
[JsonProperty(PropertyName = "Chat Prefix")]
public string Prefix = "[<color=green>Barrelles</color>] ";
[JsonProperty(PropertyName = "Drop : Count random per x barrels")]
public int Barrelcountdrop { get; set; } = 1;
[JsonProperty(PropertyName = "Drop : Max range to trigger events")]
public int RangeTrigger { get; set; } = 10;
[JsonProperty(PropertyName = "Drop : Spawn only 1 entity on trigger")]
public bool Trigger = false;
[JsonProperty(PropertyName = "Only allow spawning outside")]
public bool TriggerOut = false;
[JsonProperty(PropertyName = "Show messages")]
public bool ShowMsg = true;
}
#endregion
#region Airdrop
class SettingsAirdrop
{
[JsonProperty(PropertyName = "Spawn chance (0-100)")]
public int AirdropRate { get; set; } = 1;
[JsonProperty(PropertyName = "Drop height")]
public int AirdropHeight { get; set; } = 120;
}
#endregion
#region Scarecrow
class NPCSettings
{
[JsonProperty(PropertyName = "Spawn chance (0-100)")]
public int SpawnRate = 10;
[JsonProperty(PropertyName = "Spawn Amount")]
public int NPCAmount = 1;
[JsonProperty(PropertyName = "NPC Spawns on fire")]
public bool FromHell = false;
[JsonProperty(PropertyName = "Max Roam Distance")]
public int NPCRoamMax= 15;
[JsonProperty(PropertyName = "Prefix (Title)")]
public string NPCName = "Scarecrow";
[JsonProperty(PropertyName = "Prefix (Title) if chainsaw equiped")]
public string NPCName2 = "Chainsaw Murderer";
[JsonProperty(PropertyName = "Health (HP)")]
public int NPCHealth = 250;
[JsonProperty(PropertyName = "Life Duration (minutes)")]
public float NPCLife = 5f;
[JsonProperty(PropertyName = "Damage multiplier")]
public float NPCDamageScale = 0.6f;
[JsonProperty(PropertyName = "Use kit (clothing)")]
public bool UseKit = false;
[JsonProperty(PropertyName = "Kit ID")]
public List<string> KitName = new List<string>();
}
#endregion
#region Scientist
class SCISettings
{
[JsonProperty(PropertyName = "Spawn chance (0-100)")]
public int SpawnRate = 10;
[JsonProperty(PropertyName = "Spawn Amount")]
public int NPCAmount = 1;
[JsonProperty(PropertyName = "NPC Spawns on fire")]
public bool FromHell = false;
[JsonProperty(PropertyName = "Max Roam Distance")]
public int NPCRoamMax = 15;
[JsonProperty(PropertyName = "Prefix (Title)")]
public string NPCName = "BarrelScientist";
[JsonProperty(PropertyName = "Health (HP)")]
public int NPCHealth = 250;
[JsonProperty(PropertyName = "Life Duration (minutes)")]
public float NPCLife = 5f;
[JsonProperty(PropertyName = "Damage multiplier")]
public float NPCDamageScale = 0.6f;
[JsonProperty(PropertyName = "Use kit (clothing)")]
public bool UseKit = false;
[JsonProperty(PropertyName = "Kit ID")]
public List<string> KitName = new List<string>();
}
#endregion
#region Animals
class SettingsAnimal
{
[JsonProperty(PropertyName = "Bear Settings")]
public BearSettings Bear = new BearSettings();
[JsonProperty(PropertyName = "PolarBear Settings")]
public PBearSettings PBear = new PBearSettings();
[JsonProperty(PropertyName = "Boar Settings")]
public BoarSettings Boar = new BoarSettings();
[JsonProperty(PropertyName = "Chicken Settings")]
public ChickenSettings Chicken = new ChickenSettings();
[JsonProperty(PropertyName = "Wolf Settings")]
public WolfSettings Wolf = new WolfSettings();
}
class BearSettings
{
[JsonProperty(PropertyName = "Chance on spawn (0-100)")]
public int BearRate = 5;
[JsonProperty(PropertyName = "Amount")]
public int BearAmount = 1;
[JsonProperty(PropertyName = "Health")]
public int BearHealth = 450;
[JsonProperty(PropertyName = "Life Duration (minutes)")]
public float Life = 5f;
}
class PBearSettings
{
[JsonProperty(PropertyName = "Chance on spawn (0-100)")]
public int PBearRate = 5;
[JsonProperty(PropertyName = "Amount")]
public int PBearAmount = 1;
[JsonProperty(PropertyName = "Health")]
public int PBearHealth = 450;
[JsonProperty(PropertyName = "Life Duration (minutes)")]
public float Life = 5f;
}
class BoarSettings
{
[JsonProperty(PropertyName = "Chance on spawn (0-100)")]
public int BoarRate = 10;
[JsonProperty(PropertyName = "Amount")]
public int BoarAmount = 1;
[JsonProperty(PropertyName = "Health")]
public int BoarHealth = 250;
[JsonProperty(PropertyName = "Life Duration (minutes)")]
public float Life = 5f;
}
class ChickenSettings
{
[JsonProperty(PropertyName = "Chance on spawn (0-100)")]
public int ChickenRate = 10;
[JsonProperty(PropertyName = "Amount")]
public int ChickenAmount = 1;
[JsonProperty(PropertyName = "Health")]
public int ChickenHealth = 40;
[JsonProperty(PropertyName = "Life Duration (minutes)")]
public float Life = 5f;
}
class WolfSettings
{
[JsonProperty(PropertyName = "Chance on spawn (0-100)")]
public int WolfRate = 10;
[JsonProperty(PropertyName = "Amount")]
public int WolfAmount = 1;
[JsonProperty(PropertyName = "Health")]
public int WolfHealth = 250;
[JsonProperty(PropertyName = "Life Duration (minutes)")]
public float Life = 5f;
}
#endregion
#region Explosives
class SettingsExplosives
{
[JsonProperty(PropertyName = "Beancan : Chance on spawn (0-100)")]
public int BeancanRate = 5;
[JsonProperty(PropertyName = "F1 Grenade : Chance on spawn (0-100)")]
public int GrenadeRate = 3;
}
#endregion
#region cfg save/load
private bool LoadConfigVariables()
{
try
{
configData = Config.ReadObject<ConfigData>();
}
catch
{
return false;
}
SaveConf();
return true;
}
protected override void LoadDefaultConfig()
{
Puts("Fresh install detected Creating a new config file.");
configData = new ConfigData();
SaveConf();
}
void SaveConf() => Config.WriteObject(configData, true);
#endregion
#endregion
#region LanguageApi
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["AirdropSpawned"] = "You lucky bastard a Airdrop is comming to your location",
["AirdropSpawned"] = "You lucky bastard a Airdrop is comming to your location",
["Beancanspawned"] = "A small explosive fell out of the barrel",
["Grenadespawned"] = "A Grenade fell out of the barrel",
["Bearspawned"] = "A wild bear just apeared",
["MoreBearspawned"] = "Runnn... a sleuth of Bears apeared",
["PBearspawned"] = "A wild PolarBear just apeared",
["MorePBearspawned"] = "Runnn... they hungry",
["Boarspawned"] = "Oink...",
["MoreBoarspawned"] = "Oinks...A Sounder of boars apeared",
["Chickenspawned"] = "tok tok...",
["MoreChickenspawned"] = "tok...toktoktok!",
["Scientistspawned"] = "A Scientist was freed from his barrel prison",
["MoreScientistsSpawned"] = "Multiple Scientists where freed from their barrel prison",
["SignalDropped"] = "You found a supply signal but you dropped it on the floor",
["SignalRecieved"] = "Your recieved a supply signal in your inventory",
["Wolfspawned"] = "A wild wolf just apeared",
["MoreWolvesspawned"] = "Runnn... it is a pack of wolves",
["Zombiespawned"] = "A Zombie was freed from his barrel prison",
["MoreZombiesSpawned"] = "Multiple Zombies where freed from their barrel prison"
}, this);
}
#endregion
#region Hooks
void OnServerInitialized()
{
instance = this;
}
void Unload()
{
Zombies[] zombies = UnityEngine.Object.FindObjectsOfType<Zombies>();
if (zombies != null)
{
foreach (Zombies zombie in zombies)
UnityEngine.Object.Destroy(zombie);
}
Scientists[] scientists = UnityEngine.Object.FindObjectsOfType<Scientists>();
if (scientists != null)
{
foreach (Scientists scientist in scientists)
UnityEngine.Object.Destroy(scientist);
}
}
void Init()
{
if (!LoadConfigVariables())
{
Puts("Config file issue detected. Please delete file, or check syntax and fix.");
return;
}
prefix = configData.DropData.Prefix;
chaticon = 76561############;
permission.RegisterPermission(GlobalTrigger_Perm, this);
permission.RegisterPermission(SciTrigger_Perm, this);
permission.RegisterPermission(ScareTrigger_Perm, this);
permission.RegisterPermission(BearTrigger_Perm, this);
permission.RegisterPermission(PBearTrigger_Perm, this);
permission.RegisterPermission(BoarTrigger_Perm, this);
permission.RegisterPermission(ChickenTrigger_Perm, this);
permission.RegisterPermission(WolfTrigger_Perm, this);
permission.RegisterPermission(ExploTrigger_Perm, this);
permission.RegisterPermission(AirdropTrigger_Perm, this);
}
void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
{
if (info?.Initiator == null) return;
if (!entity.ShortPrefabName.StartsWith("loot-barrel")
&& !entity.ShortPrefabName.StartsWith("loot_barrel")
&& entity.ShortPrefabName != "oil_barrel"
&& entity.ShortPrefabName != "diesel_barrel_world")
return;
if (!entity.IsOutside() && configData.DropData.TriggerOut == true) return;
BasePlayer player = info.InitiatorPlayer;
if (player == null || !player.IsValid()) return;
var BarrelDistance = Vector3.Distance(entity.transform.position, player.transform.position);
if (BarrelDistance > configData.DropData.RangeTrigger)
{
//Puts($"distance ({BarrelDistance}m) was higher then {configData.DropData.RangeTrigger}m");
return;
}
if (CheckPlayer(info) == false ) return;
if (!permission.UserHasPermission(player.UserIDString, GlobalTrigger_Perm)) return;
else
{
Playerinfo user = get_user(info.InitiatorPlayer);
if (user.barrelCount < configData.DropData.Barrelcountdrop)
{
user.barrelCount += 1;
update_user(info.InitiatorPlayer, user);
}
else
{
user.barrelCount = 0;
update_user(info.InitiatorPlayer, user);
if (entity.transform.position != null)
{
#region Scarecrow
if (SpawnRate(configData.NPCData.SpawnRate) == true)
{
if (!permission.UserHasPermission(player.UserIDString, ScareTrigger_Perm)) return;
for (int i = 0; i < configData.NPCData.NPCAmount; i++)
{
Spawnnpc(entity.transform.position);
}
if (configData.NPCData.NPCAmount == 1 && configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Zombiespawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
else if (configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MoreZombiesSpawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
if (configData.DropData.Trigger) return;
}
#endregion
#region Scientists
if (SpawnRate(configData.SCIData.SpawnRate) == true)
{
if (!permission.UserHasPermission(player.UserIDString, SciTrigger_Perm)) return;
for (int i = 0; i < configData.SCIData.NPCAmount; i++)
{
_FromHell = configData.SCIData.FromHell;
SciHealth = configData.SCIData.NPCHealth;
SciDamageScale = configData.SCIData.NPCDamageScale;
SciLifetime = configData.SCIData.NPCLife;
SciName = configData.SCIData.NPCName;
_UseKit = configData.SCIData.UseKit;
SciKit = configData.SCIData.KitName;
SpawnScientist(entity.transform.position);
}
if (configData.SCIData.NPCAmount == 1 && configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Scientistspawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
else if (configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MoreScientistsSpawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
if (configData.DropData.Trigger) return;
}
#endregion
#region Airdrop
if (SpawnRate(configData.AirdropData.AirdropRate) == true && entity.IsOutside())
{
if (!permission.UserHasPermission(player.UserIDString, AirdropTrigger_Perm)) return;
SpawnSupplyCrate(airdropString, entity.transform.position);
if (configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("AirdropSpawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
if (configData.DropData.Trigger) return;
}
if (SpawnRate(configData.AirdropData.AirdropRate) == true && !entity.IsOutside())
{
var _signal = ItemManager.CreateByName("supply.signal", 1, 0);
player.inventory.GiveItem(_signal, null);
if (player.inventory.containerMain.IsFull())
{
_signal.DropAndTossUpwards(player.transform.position);
if (configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("SignalDropped", info.InitiatorPlayer.UserIDString)), chaticon);
}
Signaldropped = true;
}
if (Signaldropped == false && configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("SignalRecieved", info.InitiatorPlayer.UserIDString)), chaticon);
}
if (configData.DropData.Trigger) return;
}
#endregion
#region Animals
if (SpawnRate(configData.AnimalData.Bear.BearRate) == true)
{
if (!permission.UserHasPermission(player.UserIDString, BearTrigger_Perm)) return;
for (int i = 0; i < configData.AnimalData.Bear.BearAmount; i++)
{
_AnimalHealth = configData.AnimalData.Bear.BearHealth;
_AnimalLife = configData.AnimalData.Bear.Life;
_AnimalString = bearString;
SpawnAnimal(entity.transform.position);
}
if (configData.AnimalData.Bear.BearAmount == 1 && configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Bearspawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
else if (configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MoreBearspawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
if (configData.DropData.Trigger) return;
}
if (SpawnRate(configData.AnimalData.PBear.PBearRate) == true)
{
if (!permission.UserHasPermission(player.UserIDString, PBearTrigger_Perm)) return;
for (int i = 0; i < configData.AnimalData.PBear.PBearAmount; i++)
{
_AnimalHealth = configData.AnimalData.PBear.PBearHealth;
_AnimalLife = configData.AnimalData.PBear.Life;
_AnimalString = PBearString;
SpawnAnimal(entity.transform.position);
}
if (configData.AnimalData.PBear.PBearAmount == 1 && configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("PBearspawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
else if (configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MorePBearspawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
if (configData.DropData.Trigger) return;
}
if (SpawnRate(configData.AnimalData.Boar.BoarRate) == true)
{
if (!permission.UserHasPermission(player.UserIDString, BoarTrigger_Perm)) return;
for (int i = 0; i < configData.AnimalData.Boar.BoarAmount; i++)
{
_AnimalHealth = configData.AnimalData.Boar.BoarHealth;
_AnimalLife = configData.AnimalData.Boar.Life;
_AnimalString = boarstring;
SpawnAnimal(entity.transform.position);
}
if (configData.AnimalData.Boar.BoarAmount == 1 && configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Boarspawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
else if (configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MoreBoarspawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
if (configData.DropData.Trigger) return;
}
if (SpawnRate(configData.AnimalData.Chicken.ChickenRate) == true)
{
if (!permission.UserHasPermission(player.UserIDString, ChickenTrigger_Perm)) return;
for (int i = 0; i < configData.AnimalData.Chicken.ChickenAmount; i++)
{
_AnimalHealth = configData.AnimalData.Chicken.ChickenHealth;
_AnimalLife = configData.AnimalData.Chicken.Life;
_AnimalString = chickenString;
SpawnAnimal(entity.transform.position);
}
if (configData.AnimalData.Chicken.ChickenAmount == 1 && configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Chickenspawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
else if (configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MoreChickenspawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
if (configData.DropData.Trigger) return;
}
if (SpawnRate(configData.AnimalData.Wolf.WolfRate) == true)
{
if (!permission.UserHasPermission(player.UserIDString, WolfTrigger_Perm)) return;
for (int i = 0; i < configData.AnimalData.Wolf.WolfAmount; i++)
{
_AnimalHealth = configData.AnimalData.Wolf.WolfHealth;
_AnimalLife = configData.AnimalData.Wolf.Life;
_AnimalString = wolfString;
SpawnAnimal(entity.transform.position);
}
if (configData.AnimalData.Wolf.WolfAmount == 1 && configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Wolfspawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
else if (configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MoreWolvesspawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
if (configData.DropData.Trigger)
return;
}
#endregion
#region explosives
if (SpawnRate(configData.ExplosivesData.BeancanRate) == true)
{
if (!permission.UserHasPermission(player.UserIDString, ExploTrigger_Perm)) return;
SpawnBeancan(beancanString, entity.transform.position);
if (configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Beancanspawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
if (configData.DropData.Trigger) return;
}
if (SpawnRate(configData.ExplosivesData.GrenadeRate) == true)
{
if (!permission.UserHasPermission(player.UserIDString, ExploTrigger_Perm)) return;
SpawnGrenade(grenadeString, entity.transform.position);
if (configData.DropData.ShowMsg == true)
{
Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Grenadespawned", info.InitiatorPlayer.UserIDString)), chaticon);
}
if (configData.DropData.Trigger) return;
}
#endregion
}
}
}
}
object OnNpcKits(BasePlayer player)
{
if (player?.gameObject?.GetComponent<Zombies>() != null)
return true;
return null;
}
private object OnNpcTarget(BaseEntity attacker, BaseEntity target)
{
if (attacker?.gameObject?.GetComponent<Zombies>())
{
if (target is ScarecrowNPC|| target is BaseNpc)
{
return true;
}
if (target is TunnelDweller || target is UnderwaterDweller)
{
return true;
}
return null;
}
if (target?.gameObject?.GetComponent<Zombies>())
{
return true;
}
return null;
}
private object OnNpcTarget(BaseEntity attacker, BasePlayer target)
{
if (attacker?.gameObject?.GetComponent<Zombies>())
{
if (target.IsSleeping() || target.IsFlying || !(target.userID.IsSteamId()))
return false;
}
return null;
}
private void OnFireBallDamage(FireBall fire, ScarecrowNPC npc, HitInfo info)
{
if (!(npc?.gameObject?.GetComponent<Zombies>() && info.Initiator is FireBall))
{
return;
}
info.damageTypes = new DamageTypeList();
info.DoHitEffects = false;
info.damageTypes.ScaleAll(0f);
}
#endregion
#region Event Helpers
#region Nav & Checks
public Vector3 GetNavPoint(Vector3 position)
{
NavMeshHit hit;
if (!NavMesh.SamplePosition(position, out hit, 5, -1))
{
return position;
}
else if (Physics.RaycastAll(hit.position + new Vector3(0, 100, 0), Vector3.down, 99f, 1235288065).Any())
{
return position;
}
else if (hit.position.y < TerrainMeta.WaterMap.GetHeight(hit.position))
{
return position;
}
position = hit.position;
return position;
}
private bool SpawnRate(int npcRate)
{
if (rnd.Next(1, 101) <= npcRate)
{
return true;
}
return false;
}
private bool CheckPlayer(HitInfo info)
{
bool Checker = false;
BasePlayer player = info.InitiatorPlayer;
if (player != null || player.IsValid() || info?.Initiator != null)
{
Checker = true;
}
return Checker;
}
#endregion
#region Scarecrow
private void Spawnnpc(Vector3 position)
{
Vector3 pos = position + UnityEngine.Random.onUnitSphere * 1.5f;
pos.y = TerrainMeta.HeightMap.GetHeight(pos);
ScarecrowNPC npc = (ScarecrowNPC)GameManager.server.CreateEntity(zombie, pos, new Quaternion(), true);
npc.Spawn();
NextTick(() =>
{
if (npc == null)
return;
var mono = npc.gameObject.AddComponent<Zombies>();
mono.SpawnPoint = pos;
npc.startHealth = configData.NPCData.NPCHealth;
npc.InitializeHealth(configData.NPCData.NPCHealth, configData.NPCData.NPCHealth);
npc.CanAttack();
timer.Once(0.5f, () =>
{
Chainsaw heldEntity = npc.GetHeldEntity() as Chainsaw;
if (heldEntity != null)
{
npc.displayName = configData.NPCData.NPCName2 + " " + RandomUsernames.Get((int)npc.userID);
heldEntity.SetFlag(Chainsaw.Flags.On, true);
heldEntity.SendNetworkUpdateImmediate();
}
else
{
npc.displayName = configData.NPCData.NPCName + " " + RandomUsernames.Get((int)npc.userID);
}
});
if (configData.NPCData.FromHell)
{
var Fire = GameManager.server.CreateEntity(fireball1, new Vector3(0, 1, 0), Quaternion.Euler(0, 0, 0));
Fire.gameObject.Identity();
Fire.SetParent(npc);
Fire.Spawn();
timer.Once(1f, () =>
{
if (Fire != null) Fire.Kill();
Puts($"{npc} spawned From Hell (on Fire)");
});
}
npc.damageScale = configData.NPCData.NPCDamageScale;
if (configData.NPCData.UseKit && configData.NPCData.KitName.Count > 0)
{
object checkKit = Kits?.CallHook("GetKitInfo", configData.NPCData.KitName[new System.Random().Next(configData.NPCData.KitName.Count())]);
if (checkKit == null)
NextTick(() =>
{
var inv_belt = npc.inventory.containerBelt;
var inv_wear = npc.inventory.containerWear;
Item eyes = ItemManager.CreateByName("gloweyes", 1, 0);
if (eyes != null) eyes.MoveToContainer(inv_wear);
/*
npc.inventory.Strip();
Item mask = ItemManager.CreateByName("hat.gas.mask", 1, 0);
Item boots = ItemManager.CreateByName("shoes.boots", 1, 0);
Item gloves = ItemManager.CreateByName("burlap.gloves", 1, 0);
switch (UnityEngine.Random.Range(0, 2))
{
case 0:
ItemManager.CreateByName("jumpsuit.suit.blue", 1, 0).MoveToContainer(inv_wear, 0);
break;
default:
ItemManager.CreateByName("jumpsuit.suit", 1, 0).MoveToContainer(inv_wear, 0);
break;
}
switch (UnityEngine.Random.Range(0, 4))
{
case 0:
ItemManager.CreateByName("machete", 1, 0).MoveToContainer(inv_belt, 0);
break;
case 1:
ItemManager.CreateByName("pitchfork", 1, 0).MoveToContainer(inv_belt, 0);
break;
case 2:
ItemManager.CreateByName("mace", 1, 0).MoveToContainer(inv_belt, 0);
break;
default:
ItemManager.CreateByName("salvaged.cleaver", 1, 0).MoveToContainer(inv_belt, 0);
break;
}
if (mask != null) mask.MoveToContainer(inv_wear);
if (boots != null) boots.MoveToContainer(inv_wear);
if (gloves != null) gloves.MoveToContainer(inv_wear);
*/
PrintWarning($"Kit for {npc} does not exist - Using a default outfit.");
});
else
{
npc.inventory.Strip();
Kits?.Call($"GiveKit", npc, configData.NPCData.KitName[new System.Random().Next(configData.NPCData.KitName.Count())]);
}
}
if (!configData.NPCData.UseKit || configData.NPCData.KitName.Count == 0)
{
var inv_belt = npc.inventory.containerBelt;
var inv_wear = npc.inventory.containerWear;
Item eyes = ItemManager.CreateByName("gloweyes", 1, 0);
if (eyes != null) eyes.MoveToContainer(inv_wear);
}
});
if (npc.IsHeadUnderwater())
{
npc.Kill();
Puts($"{npc} got destroyed for being under water!!!");
return;
}
timer.Once(configData.NPCData.NPCLife * 60, () =>
{
if (npc != null)
{
npc.Kill();
Puts($"{npc} Died of old age");
}
return;
});
}
#endregion
#region Scientist
private void SpawnScientist(Vector3 position)
{
Vector3 pos = position + UnityEngine.Random.onUnitSphere * 1.5f;
pos.y = TerrainMeta.HeightMap.GetHeight(pos);
NPCPlayer npc = (NPCPlayer)GameManager.server.CreateEntity(_scientist, pos, new Quaternion(), true);
npc.Spawn();
NextTick(() =>
{
if (npc == null)
return;
var mono = npc.gameObject.AddComponent<Scientists>();
mono.SpawnPoint = pos;
npc.startHealth = SciHealth;
npc.InitializeHealth(SciHealth, SciHealth);
npc.CanAttack();
timer.Once(0.5f, () =>
{
npc.displayName = SciName + " " + RandomUsernames.Get((int)npc.userID);
});
if (_FromHell)
{
var Fire = GameManager.server.CreateEntity(fireball1, new Vector3(0, 1, 0), Quaternion.Euler(0, 0, 0));
Fire.gameObject.Identity();
Fire.SetParent(npc);
Fire.Spawn();
timer.Once(1f, () =>
{
if (Fire != null) Fire.Kill();
Puts($"{npc} spawned From Hell (on Fire)");
});
}
npc.damageScale = SciDamageScale;
if (_UseKit && SciKit.Count > 0)
{
object checkKit = Kits?.CallHook("GetKitInfo", SciKit[new System.Random().Next(SciKit.Count())]);
if (checkKit == null)
timer.Once(1f, () =>
{
PrintWarning($"Kit for {npc} does not exist - Using a default outfit.");
});
else
{
npc.inventory.Strip();
Kits?.Call($"GiveKit", npc, SciKit[new System.Random().Next(SciKit.Count())]);
timer.Once(1f, () =>
{
PrintWarning($"Kit for {npc} succesfully equiped.");
});
}
}
if (!_UseKit || SciKit.Count == 0)
{
timer.Once(1f, () =>
{
PrintWarning($"{npc} spawned Using a default outfit.");
});
}
});
if (npc.IsHeadUnderwater())
{
npc.Kill();
timer.Once(1f, () =>
{
PrintWarning($"{npc} got destroyed for being under water!!!");
});
return;
}
timer.Once(SciLifetime * 60, () =>
{
if (npc != null)
{
npc.Kill();
Puts($"{npc} Died of old age");
}
return;
});
}
#endregion
#region Airdrop
private void SpawnSupplyCrate(string prefab, Vector3 position)
{
Vector3 newPosition = position + new Vector3(0, configData.AirdropData.AirdropHeight, 0);
BaseEntity SupplyCrateEntity = GameManager.server.CreateEntity(prefab, newPosition);
if (SupplyCrateEntity != null)
{
SupplyDrop Drop = SupplyCrateEntity.GetComponent<SupplyDrop>();
Drop.Spawn();
}
}
#endregion
#region Animals
private void SpawnAnimal(Vector3 position)
{
Vector3 pos = position + UnityEngine.Random.onUnitSphere * 1.5f;
pos.y = TerrainMeta.HeightMap.GetHeight(pos);
BaseNpc Animal = (BaseNpc)GameManager.server.CreateEntity(_AnimalString, pos, new Quaternion(), true);
if (Animal != null)
{
Animal.Spawn();
Animal.startHealth = _AnimalHealth;
Animal.InitializeHealth(_AnimalHealth, _AnimalHealth);
}
timer.Once(_AnimalLife * 60, () =>
{
if (Animal != null)
{
Animal.Kill();
Puts($"The {Animal.ShortPrefabName.ToString()} Died of old age");
}
return;
});
}
#endregion
#region Explosives
private void SpawnBeancan(string prefab, Vector3 position)
{
Vector3 newPosition = position + new Vector3(0, 1.4f, 0);
BaseEntity Beancan = GameManager.server.CreateEntity(prefab, newPosition);
if (Beancan != null)
{
Beancan.Spawn();
}
}
private void SpawnGrenade(string prefab, Vector3 position)
{
Vector3 newPosition = position + new Vector3(0, 1.4f, 0);
BaseEntity Grenade = GameManager.server.CreateEntity(prefab, newPosition);
if (Grenade != null)
{
Grenade.Spawn();
}
}
#endregion
#endregion
#region Message helper
private string msg(string key, string id = null) => lang.GetMessage(key, this, id);
#endregion
#region Data helpers
Playerinfo get_user(BasePlayer player)
{
if (!Interface.Oxide.DataFileSystem.ExistsDatafile(file_main + player.UserIDString))
{
Playerinfo user = new Playerinfo();
user.userName = player.displayName.ToString();
user.barrelCount = 0;
update_user(player, user);
return user;
}
else
{
string raw_player_file = Interface.Oxide.DataFileSystem.ReadObject<string>(file_main + player.UserIDString);
return JsonConvert.DeserializeObject<Playerinfo>(raw_player_file);
}
}
void update_user(BasePlayer player, Playerinfo user)
{
Interface.Oxide.DataFileSystem.WriteObject<string>(file_main + player.UserIDString, JsonConvert.SerializeObject(user));
}
public class Playerinfo
{
private string _userName;
private int _barrelCount;
public Playerinfo()
{
}
public int barrelCount
{
get { return _barrelCount; }
set { _barrelCount = value; }
}
public string userName
{
get { return _userName; }
set { _userName = value; }
}
}
#endregion
}
}
Show, it worked for me, very grateful, thanks...
WaywardThis is not my plugin, but I changed the npc.Brain.Senses.Init under _UseBrain() to
npc.Brain.Senses.Init(npc, npc.Brain, 5f, 30f, 40f, 135f, true, true, true, 60f, false, false, true, EntityType.Player, true); for Zombies
and
npc.Brain.Senses.Init(npc, npc.Brain, 5f, 50f, 50f, -1f, true, false, true, 60f, false, false, false, EntityType.Player, false); for Scientists and that got it to compile.
Merged postusing System; using System.Linq; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; using Oxide.Core; using Oxide.Core.Plugins; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Facepunch; using Rust; using Rust.Ai; #region Changelogs and ToDo /********************************************************************** * * 1.0.0 - initial release * 2.0.0 - Rewrite V2 * 2.1.0 - Patched for compile after Rust Update removing various AI * 3.0.0 - Rewrite V3 * - Added Scarecrow Attack Behaviour to be less stuck on targets * - Added scientist and scarecrows Roaming Behaviour * - Added support for kits for scientist and scarecrows * - Added spawn amount for for scientist and scarecrows * - Added scientist and scarecrows to get their prefix(title) + random name assigned * - Added Seperate prefix for scarecrow with a chainsaw * - Airdrops skips spawn if the barrel is not outside * and will gives the player a supply.signal or drops it on the floor * if player inventory is full * - Added amount of animals spawning per animal type * - Added Health settings per animal type * - If more then 1 npc or animal are set to spawn they will give a different chat message * - Added F1Grenade to the explosives spawn list * 3.0.1 - Added support for PolarBears * 3.0.2 - Added Global setting to only spawn outside * Added animal life duration * Added permission system * 3.0.3 - Added Max range to trigger events to the config * 3.0.4 - My hacked up attempt to fix the npc.Brain.Senses (Wayward) * * Todo - Readd Fires and their behaviour/spawn area * - Add Mono for animals (roam and other stuff) * - Add day/night spawnrates * **********************************************************************/ #endregion namespace Oxide.Plugins { [Info("Barrelless", "Krungh Crow", "3.0.3")] [Description("various events after barrel kills")] class Barrelless : RustPlugin { [PluginReference] Plugin Kits; #region Variables #region Plugin bool BlockSpawn; bool Signaldropped; ulong chaticon; string prefix; System.Random rnd = new System.Random(); private ConfigData configData; public static Barrelless instance; #endregion #region Permissions const string GlobalTrigger_Perm = "barrelless.globaltrigger"; const string SciTrigger_Perm = "barrelless.scientist"; const string ScareTrigger_Perm = "barrelless.scarecrow"; const string BearTrigger_Perm = "barrelless.bear"; const string PBearTrigger_Perm = "barrelless.polarbear"; const string BoarTrigger_Perm = "barrelless.boar"; const string ChickenTrigger_Perm = "barrelless.chicken"; const string WolfTrigger_Perm = "barrelless.wolf"; const string ExploTrigger_Perm = "barrelless.explosive"; const string AirdropTrigger_Perm = "barrelless.airdrop"; #endregion #region NPC const string zombie = "assets/prefabs/npc/scarecrow/scarecrow.prefab"; const string _scientist = "assets/rust.ai/agents/npcplayer/humannpc/scientist/scientistnpc_roam.prefab"; float SciDamageScale; int SciHealth; List<string> SciKit; float SciLifetime; string SciName; bool _UseKit; bool _FromHell; #endregion #region Animals const string bearString = "assets/rust.ai/agents/bear/bear.prefab"; const string PBearString = "assets/rust.ai/agents/bear/polarbear.prefab"; const string boarstring = "assets/rust.ai/agents/boar/boar.prefab"; const string chickenString = "assets/rust.ai/agents/chicken/chicken.prefab"; const string wolfString = "assets/rust.ai/agents/wolf/wolf.prefab"; int _AnimalHealth; string _AnimalString; float _AnimalLife; #endregion #region Fires const string fireString = "assets/prefabs/npc/m2bradley/oilfireball2.prefab"; const string fire2String = "assets/bundled/prefabs/oilfireballsmall.prefab"; const string fire3String = "assets/bundled/prefabs/fireball.prefab"; const string fireball1 = "assets/bundled/prefabs/fireball.prefab";//convert to fire3string #endregion #region Drops const string airdropString = "assets/prefabs/misc/supply drop/supply_drop.prefab"; const string beancanString = "assets/prefabs/weapons/beancan grenade/grenade.beancan.deployed.prefab"; const string grenadeString = "assets/prefabs/weapons/f1 grenade/grenade.f1.deployed.prefab"; #endregion #region Data const string file_main = "barrelless_players/"; #endregion #endregion #region Behaviours #region Scarecrow private class Zombies : FacepunchBehaviour { private ScarecrowNPC npc; public bool ReturningToHome = false; public bool isRoaming = true; public Vector3 SpawnPoint; private void Awake() { npc = GetComponent<ScarecrowNPC>(); Invoke(nameof(_UseBrain), 0.1f); InvokeRepeating(Attack, 0.1f, 1.5f); InvokeRepeating(GoHome, 2.0f, 4.5f); } private void Attack() { BaseEntity entity = npc.Brain.Senses.GetNearestThreat(40); Chainsaw heldEntity = npc.GetHeldEntity() as Chainsaw; if (entity == null || Vector3.Distance(entity.transform.position, npc.transform.position) > 40.0f) { npc.Brain.Navigator.ClearFacingDirectionOverride(); GoHome(); } if (entity != null && Vector3.Distance(entity.transform.position, npc.transform.position) < 2.0f) { npc.StartAttacking(entity); npc.Brain.Navigator.SetFacingDirectionEntity(entity); if (heldEntity is Chainsaw) { if (!(heldEntity as Chainsaw).EngineOn()) { (heldEntity as Chainsaw).ServerNPCStart(); } heldEntity.SetFlag(BaseEntity.Flags.Busy, true, false, true); heldEntity.SetFlag(BaseEntity.Flags.Reserved8, true, false, true); } } if (entity != null && Vector3.Distance(entity.transform.position, npc.transform.position) > 1.5f) { if (heldEntity is Chainsaw) { if (!(heldEntity as Chainsaw).EngineOn()) { (heldEntity as Chainsaw).ServerNPCStart(); } heldEntity.SetFlag(BaseEntity.Flags.Busy, false, false, true); heldEntity.SetFlag(BaseEntity.Flags.Reserved8, false, false, true); } } if (entity != null && Vector3.Distance(entity.transform.position, npc.transform.position) > 2.0f) { npc.Brain.Navigator.SetFacingDirectionEntity(entity); } } public void _UseBrain() { #region navigation npc.Brain.Navigator.Agent.agentTypeID = -1372625422; npc.Brain.Navigator.DefaultArea = "Walkable"; npc.Brain.Navigator.Agent.autoRepath = true; npc.Brain.Navigator.enabled = true; npc.Brain.Navigator.CanUseNavMesh = true; npc.Brain.Navigator.BestRoamPointMaxDistance = instance.configData.NPCData.NPCRoamMax; npc.Brain.Navigator.MaxRoamDistanceFromHome = instance.configData.NPCData.NPCRoamMax; npc.Brain.Navigator.Init(npc, npc.Brain.Navigator.Agent); npc.Brain.Navigator.SetDestination(SpawnPoint, BaseNavigator.NavigationSpeed.Slow, 0f, 0f); #endregion #region senses & Targeting npc.Brain.ForceSetAge(0); npc.Brain.AllowedToSleep = false; npc.Brain.sleeping = false; npc.Brain.SenseRange = 30f; npc.Brain.ListenRange = 40f; npc.Brain.Senses.Init(npc, npc.Brain, 5f, 30f, 40f, 135f, true, true, true, 60f, false, false, true, EntityType.Player, true); npc.Brain.TargetLostRange = 20f; npc.Brain.HostileTargetsOnly = false; npc.Brain.IgnoreSafeZonePlayers = true; #endregion } void GoHome() { if (npc == null || npc.IsDestroyed || npc.isMounted) return; if (!npc.HasBrain) return; if (npc.Brain.Senses.Memory.Targets.Count > 0) { for (var i = 0; i < npc.Brain.Senses.Memory.Targets.Count; i++) { BaseEntity target = npc.Brain.Senses.Memory.Targets[i]; BasePlayer player = target as BasePlayer; if (target == null || !player.IsAlive() || player.IsSleeping() || player.IsFlying) { WipeMemory(); ReturningToHome = true; isRoaming = false; return; } if (npc.Distance(player.transform.position) > 25f) { WipeMemory(); ReturningToHome = true; isRoaming = false; return; } if (player.IsSleeping() || player.IsFlying) { WipeMemory(); ReturningToHome = true; isRoaming = false; return; } } } var distanceHome = Vector3.Distance(npc.transform.position, SpawnPoint); if (ReturningToHome == false) { if (isRoaming == true && distanceHome > instance.configData.NPCData.NPCRoamMax) { ReturningToHome = true; isRoaming = false; return; } if (isRoaming == true && distanceHome < instance.configData.NPCData.NPCRoamMax) { Vector3 random = UnityEngine.Random.insideUnitCircle.normalized * instance.configData.NPCData.NPCRoamMax; Vector3 newPos = instance.GetNavPoint(SpawnPoint + new Vector3(random.x, 0f, random.y)); SettargetDestination(newPos); return; } } if (ReturningToHome && distanceHome > 2) { if (npc.Brain.Navigator.Destination == SpawnPoint) { return; } WipeMemory(); SettargetDestination(SpawnPoint); return; } ReturningToHome = false; isRoaming = true; } private void SettargetDestination(Vector3 position) { npc.Brain.Navigator.Destination = position; npc.Brain.Navigator.SetDestination(position, BaseNavigator.NavigationSpeed.Slow, 0f, 0f); } void WipeMemory() { if (!npc.HasBrain) { return; } npc.Brain.Senses.Players.Clear(); npc.Brain.Senses.Memory.Players.Clear(); npc.Brain.Senses.Memory.Targets.Clear(); npc.Brain.Senses.Memory.Threats.Clear(); npc.Brain.Senses.Memory.LOS.Clear(); npc.Brain.Senses.Memory.All.Clear(); } void OnDestroy() { if (npc != null && !npc.IsDestroyed) { npc.Kill(); } CancelInvoke(GoHome); CancelInvoke(Attack); CancelInvoke(nameof(_UseBrain)); } } #endregion #region Scientist public class Scientists : FacepunchBehaviour { public global::HumanNPC npc; public bool ReturningToHome = false; public bool isRoaming = true; public Vector3 SpawnPoint; void Start() { npc = GetComponent<global::HumanNPC>(); InvokeRepeating("GoHome", 2.0f, 4.5f); Invoke(nameof(_UseBrain), 0.1f); } public void _UseBrain() { #region navigation npc.Brain.Navigator.Agent.agentTypeID = -1372625422; npc.Brain.Navigator.DefaultArea = "Walkable"; npc.Brain.Navigator.Agent.autoRepath = true; npc.Brain.Navigator.enabled = true; npc.Brain.Navigator.CanUseNavMesh = true; npc.Brain.Navigator.BestRoamPointMaxDistance = instance.configData.SCIData.NPCRoamMax; npc.Brain.Navigator.MaxRoamDistanceFromHome = instance.configData.SCIData.NPCRoamMax; npc.Brain.Navigator.Init(npc, npc.Brain.Navigator.Agent); npc.Brain.Navigator.SetDestination(SpawnPoint, BaseNavigator.NavigationSpeed.Slow, 0f, 0f); #endregion #region senses & Targeting npc.Brain.ForceSetAge(0); npc.Brain.AllowedToSleep = false; npc.Brain.sleeping = false; npc.Brain.SenseRange = 30f; npc.Brain.ListenRange = 40f; npc.Brain.Senses.Init(npc, npc.Brain, 5f, 50f, 50f, -1f, true, false, true, 60f, false, false, false, EntityType.Player, false); npc.Brain.TargetLostRange = 25f; npc.Brain.HostileTargetsOnly = false; npc.Brain.IgnoreSafeZonePlayers = true; #endregion } void GoHome() { if (npc == null || npc.IsDestroyed || npc.isMounted) return; if (!npc.HasBrain) return; if (npc.Brain.Senses.Memory.Targets.Count > 0) { for (var i = 0; i < npc.Brain.Senses.Memory.Targets.Count; i++) { BaseEntity target = npc.Brain.Senses.Memory.Targets[i]; BasePlayer player = target as BasePlayer; if (target == null || !player.IsAlive()) { WipeMemory(); ReturningToHome = true; isRoaming = false; return; } if (npc.Distance(player.transform.position) > 40f) { WipeMemory(); ReturningToHome = true; isRoaming = false; return; } } } var distanceHome = Vector3.Distance(npc.transform.position, SpawnPoint); if (ReturningToHome == false) { if (isRoaming == true && distanceHome > instance.configData.SCIData.NPCRoamMax) { ReturningToHome = true; isRoaming = false; return; } if (isRoaming == true && distanceHome < instance.configData.SCIData.NPCRoamMax) { Vector3 random = UnityEngine.Random.insideUnitCircle.normalized * instance.configData.SCIData.NPCRoamMax; Vector3 newPos = instance.GetNavPoint(SpawnPoint + new Vector3(random.x, 0f, random.y)); SettargetDestination(newPos); return; } } if (ReturningToHome && distanceHome > 2) { if (npc.Brain.Navigator.Destination == SpawnPoint) { return; } WipeMemory(); SettargetDestination(SpawnPoint); return; } ReturningToHome = false; isRoaming = true; } private void SettargetDestination(Vector3 position) { npc.Brain.Navigator.Destination = position; npc.Brain.Navigator.SetDestination(position, BaseNavigator.NavigationSpeed.Slow, 0f, 0f); } void WipeMemory() { if (!npc.HasBrain) { return; } npc.Brain.Senses.Players.Clear(); npc.Brain.Senses.Memory.Players.Clear(); npc.Brain.Senses.Memory.Targets.Clear(); npc.Brain.Senses.Memory.Threats.Clear(); npc.Brain.Senses.Memory.LOS.Clear(); npc.Brain.Senses.Memory.All.Clear(); } void OnDestroy() { if (npc != null && !npc.IsDestroyed) { npc.Kill(); } CancelInvoke("GoHome"); CancelInvoke(nameof(_UseBrain)); } } #endregion #endregion #region Configuration class ConfigData { [JsonProperty(PropertyName = "Plugin Settings")] public SettingsDrop DropData = new SettingsDrop(); [JsonProperty(PropertyName = "Airdrop Settings")] public SettingsAirdrop AirdropData = new SettingsAirdrop(); [JsonProperty(PropertyName = "Scarecrow Settings")] public NPCSettings NPCData = new NPCSettings(); [JsonProperty(PropertyName = "Scientist Settings")] public SCISettings SCIData = new SCISettings(); [JsonProperty(PropertyName = "Animal Settings")] public SettingsAnimal AnimalData = new SettingsAnimal(); [JsonProperty(PropertyName = "Explosives Settings")] public SettingsExplosives ExplosivesData = new SettingsExplosives(); } #region Plugin settings class SettingsDrop { [JsonProperty(PropertyName = "Chat Prefix")] public string Prefix = "[<color=green>Barrelles</color>] "; [JsonProperty(PropertyName = "Drop : Count random per x barrels")] public int Barrelcountdrop { get; set; } = 1; [JsonProperty(PropertyName = "Drop : Max range to trigger events")] public int RangeTrigger { get; set; } = 10; [JsonProperty(PropertyName = "Drop : Spawn only 1 entity on trigger")] public bool Trigger = false; [JsonProperty(PropertyName = "Only allow spawning outside")] public bool TriggerOut = false; [JsonProperty(PropertyName = "Show messages")] public bool ShowMsg = true; } #endregion #region Airdrop class SettingsAirdrop { [JsonProperty(PropertyName = "Spawn chance (0-100)")] public int AirdropRate { get; set; } = 1; [JsonProperty(PropertyName = "Drop height")] public int AirdropHeight { get; set; } = 120; } #endregion #region Scarecrow class NPCSettings { [JsonProperty(PropertyName = "Spawn chance (0-100)")] public int SpawnRate = 10; [JsonProperty(PropertyName = "Spawn Amount")] public int NPCAmount = 1; [JsonProperty(PropertyName = "NPC Spawns on fire")] public bool FromHell = false; [JsonProperty(PropertyName = "Max Roam Distance")] public int NPCRoamMax= 15; [JsonProperty(PropertyName = "Prefix (Title)")] public string NPCName = "Scarecrow"; [JsonProperty(PropertyName = "Prefix (Title) if chainsaw equiped")] public string NPCName2 = "Chainsaw Murderer"; [JsonProperty(PropertyName = "Health (HP)")] public int NPCHealth = 250; [JsonProperty(PropertyName = "Life Duration (minutes)")] public float NPCLife = 5f; [JsonProperty(PropertyName = "Damage multiplier")] public float NPCDamageScale = 0.6f; [JsonProperty(PropertyName = "Use kit (clothing)")] public bool UseKit = false; [JsonProperty(PropertyName = "Kit ID")] public List<string> KitName = new List<string>(); } #endregion #region Scientist class SCISettings { [JsonProperty(PropertyName = "Spawn chance (0-100)")] public int SpawnRate = 10; [JsonProperty(PropertyName = "Spawn Amount")] public int NPCAmount = 1; [JsonProperty(PropertyName = "NPC Spawns on fire")] public bool FromHell = false; [JsonProperty(PropertyName = "Max Roam Distance")] public int NPCRoamMax = 15; [JsonProperty(PropertyName = "Prefix (Title)")] public string NPCName = "BarrelScientist"; [JsonProperty(PropertyName = "Health (HP)")] public int NPCHealth = 250; [JsonProperty(PropertyName = "Life Duration (minutes)")] public float NPCLife = 5f; [JsonProperty(PropertyName = "Damage multiplier")] public float NPCDamageScale = 0.6f; [JsonProperty(PropertyName = "Use kit (clothing)")] public bool UseKit = false; [JsonProperty(PropertyName = "Kit ID")] public List<string> KitName = new List<string>(); } #endregion #region Animals class SettingsAnimal { [JsonProperty(PropertyName = "Bear Settings")] public BearSettings Bear = new BearSettings(); [JsonProperty(PropertyName = "PolarBear Settings")] public PBearSettings PBear = new PBearSettings(); [JsonProperty(PropertyName = "Boar Settings")] public BoarSettings Boar = new BoarSettings(); [JsonProperty(PropertyName = "Chicken Settings")] public ChickenSettings Chicken = new ChickenSettings(); [JsonProperty(PropertyName = "Wolf Settings")] public WolfSettings Wolf = new WolfSettings(); } class BearSettings { [JsonProperty(PropertyName = "Chance on spawn (0-100)")] public int BearRate = 5; [JsonProperty(PropertyName = "Amount")] public int BearAmount = 1; [JsonProperty(PropertyName = "Health")] public int BearHealth = 450; [JsonProperty(PropertyName = "Life Duration (minutes)")] public float Life = 5f; } class PBearSettings { [JsonProperty(PropertyName = "Chance on spawn (0-100)")] public int PBearRate = 5; [JsonProperty(PropertyName = "Amount")] public int PBearAmount = 1; [JsonProperty(PropertyName = "Health")] public int PBearHealth = 450; [JsonProperty(PropertyName = "Life Duration (minutes)")] public float Life = 5f; } class BoarSettings { [JsonProperty(PropertyName = "Chance on spawn (0-100)")] public int BoarRate = 10; [JsonProperty(PropertyName = "Amount")] public int BoarAmount = 1; [JsonProperty(PropertyName = "Health")] public int BoarHealth = 250; [JsonProperty(PropertyName = "Life Duration (minutes)")] public float Life = 5f; } class ChickenSettings { [JsonProperty(PropertyName = "Chance on spawn (0-100)")] public int ChickenRate = 10; [JsonProperty(PropertyName = "Amount")] public int ChickenAmount = 1; [JsonProperty(PropertyName = "Health")] public int ChickenHealth = 40; [JsonProperty(PropertyName = "Life Duration (minutes)")] public float Life = 5f; } class WolfSettings { [JsonProperty(PropertyName = "Chance on spawn (0-100)")] public int WolfRate = 10; [JsonProperty(PropertyName = "Amount")] public int WolfAmount = 1; [JsonProperty(PropertyName = "Health")] public int WolfHealth = 250; [JsonProperty(PropertyName = "Life Duration (minutes)")] public float Life = 5f; } #endregion #region Explosives class SettingsExplosives { [JsonProperty(PropertyName = "Beancan : Chance on spawn (0-100)")] public int BeancanRate = 5; [JsonProperty(PropertyName = "F1 Grenade : Chance on spawn (0-100)")] public int GrenadeRate = 3; } #endregion #region cfg save/load private bool LoadConfigVariables() { try { configData = Config.ReadObject<ConfigData>(); } catch { return false; } SaveConf(); return true; } protected override void LoadDefaultConfig() { Puts("Fresh install detected Creating a new config file."); configData = new ConfigData(); SaveConf(); } void SaveConf() => Config.WriteObject(configData, true); #endregion #endregion #region LanguageApi protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary<string, string> { ["AirdropSpawned"] = "You lucky bastard a Airdrop is comming to your location", ["AirdropSpawned"] = "You lucky bastard a Airdrop is comming to your location", ["Beancanspawned"] = "A small explosive fell out of the barrel", ["Grenadespawned"] = "A Grenade fell out of the barrel", ["Bearspawned"] = "A wild bear just apeared", ["MoreBearspawned"] = "Runnn... a sleuth of Bears apeared", ["PBearspawned"] = "A wild PolarBear just apeared", ["MorePBearspawned"] = "Runnn... they hungry", ["Boarspawned"] = "Oink...", ["MoreBoarspawned"] = "Oinks...A Sounder of boars apeared", ["Chickenspawned"] = "tok tok...", ["MoreChickenspawned"] = "tok...toktoktok!", ["Scientistspawned"] = "A Scientist was freed from his barrel prison", ["MoreScientistsSpawned"] = "Multiple Scientists where freed from their barrel prison", ["SignalDropped"] = "You found a supply signal but you dropped it on the floor", ["SignalRecieved"] = "Your recieved a supply signal in your inventory", ["Wolfspawned"] = "A wild wolf just apeared", ["MoreWolvesspawned"] = "Runnn... it is a pack of wolves", ["Zombiespawned"] = "A Zombie was freed from his barrel prison", ["MoreZombiesSpawned"] = "Multiple Zombies where freed from their barrel prison" }, this); } #endregion #region Hooks void OnServerInitialized() { instance = this; } void Unload() { Zombies[] zombies = UnityEngine.Object.FindObjectsOfType<Zombies>(); if (zombies != null) { foreach (Zombies zombie in zombies) UnityEngine.Object.Destroy(zombie); } Scientists[] scientists = UnityEngine.Object.FindObjectsOfType<Scientists>(); if (scientists != null) { foreach (Scientists scientist in scientists) UnityEngine.Object.Destroy(scientist); } } void Init() { if (!LoadConfigVariables()) { Puts("Config file issue detected. Please delete file, or check syntax and fix."); return; } prefix = configData.DropData.Prefix; chaticon = 76561############; permission.RegisterPermission(GlobalTrigger_Perm, this); permission.RegisterPermission(SciTrigger_Perm, this); permission.RegisterPermission(ScareTrigger_Perm, this); permission.RegisterPermission(BearTrigger_Perm, this); permission.RegisterPermission(PBearTrigger_Perm, this); permission.RegisterPermission(BoarTrigger_Perm, this); permission.RegisterPermission(ChickenTrigger_Perm, this); permission.RegisterPermission(WolfTrigger_Perm, this); permission.RegisterPermission(ExploTrigger_Perm, this); permission.RegisterPermission(AirdropTrigger_Perm, this); } void OnEntityDeath(BaseCombatEntity entity, HitInfo info) { if (info?.Initiator == null) return; if (!entity.ShortPrefabName.StartsWith("loot-barrel") && !entity.ShortPrefabName.StartsWith("loot_barrel") && entity.ShortPrefabName != "oil_barrel" && entity.ShortPrefabName != "diesel_barrel_world") return; if (!entity.IsOutside() && configData.DropData.TriggerOut == true) return; BasePlayer player = info.InitiatorPlayer; if (player == null || !player.IsValid()) return; var BarrelDistance = Vector3.Distance(entity.transform.position, player.transform.position); if (BarrelDistance > configData.DropData.RangeTrigger) { //Puts($"distance ({BarrelDistance}m) was higher then {configData.DropData.RangeTrigger}m"); return; } if (CheckPlayer(info) == false ) return; if (!permission.UserHasPermission(player.UserIDString, GlobalTrigger_Perm)) return; else { Playerinfo user = get_user(info.InitiatorPlayer); if (user.barrelCount < configData.DropData.Barrelcountdrop) { user.barrelCount += 1; update_user(info.InitiatorPlayer, user); } else { user.barrelCount = 0; update_user(info.InitiatorPlayer, user); if (entity.transform.position != null) { #region Scarecrow if (SpawnRate(configData.NPCData.SpawnRate) == true) { if (!permission.UserHasPermission(player.UserIDString, ScareTrigger_Perm)) return; for (int i = 0; i < configData.NPCData.NPCAmount; i++) { Spawnnpc(entity.transform.position); } if (configData.NPCData.NPCAmount == 1 && configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Zombiespawned", info.InitiatorPlayer.UserIDString)), chaticon); } else if (configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MoreZombiesSpawned", info.InitiatorPlayer.UserIDString)), chaticon); } if (configData.DropData.Trigger) return; } #endregion #region Scientists if (SpawnRate(configData.SCIData.SpawnRate) == true) { if (!permission.UserHasPermission(player.UserIDString, SciTrigger_Perm)) return; for (int i = 0; i < configData.SCIData.NPCAmount; i++) { _FromHell = configData.SCIData.FromHell; SciHealth = configData.SCIData.NPCHealth; SciDamageScale = configData.SCIData.NPCDamageScale; SciLifetime = configData.SCIData.NPCLife; SciName = configData.SCIData.NPCName; _UseKit = configData.SCIData.UseKit; SciKit = configData.SCIData.KitName; SpawnScientist(entity.transform.position); } if (configData.SCIData.NPCAmount == 1 && configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Scientistspawned", info.InitiatorPlayer.UserIDString)), chaticon); } else if (configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MoreScientistsSpawned", info.InitiatorPlayer.UserIDString)), chaticon); } if (configData.DropData.Trigger) return; } #endregion #region Airdrop if (SpawnRate(configData.AirdropData.AirdropRate) == true && entity.IsOutside()) { if (!permission.UserHasPermission(player.UserIDString, AirdropTrigger_Perm)) return; SpawnSupplyCrate(airdropString, entity.transform.position); if (configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("AirdropSpawned", info.InitiatorPlayer.UserIDString)), chaticon); } if (configData.DropData.Trigger) return; } if (SpawnRate(configData.AirdropData.AirdropRate) == true && !entity.IsOutside()) { var _signal = ItemManager.CreateByName("supply.signal", 1, 0); player.inventory.GiveItem(_signal, null); if (player.inventory.containerMain.IsFull()) { _signal.DropAndTossUpwards(player.transform.position); if (configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("SignalDropped", info.InitiatorPlayer.UserIDString)), chaticon); } Signaldropped = true; } if (Signaldropped == false && configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("SignalRecieved", info.InitiatorPlayer.UserIDString)), chaticon); } if (configData.DropData.Trigger) return; } #endregion #region Animals if (SpawnRate(configData.AnimalData.Bear.BearRate) == true) { if (!permission.UserHasPermission(player.UserIDString, BearTrigger_Perm)) return; for (int i = 0; i < configData.AnimalData.Bear.BearAmount; i++) { _AnimalHealth = configData.AnimalData.Bear.BearHealth; _AnimalLife = configData.AnimalData.Bear.Life; _AnimalString = bearString; SpawnAnimal(entity.transform.position); } if (configData.AnimalData.Bear.BearAmount == 1 && configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Bearspawned", info.InitiatorPlayer.UserIDString)), chaticon); } else if (configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MoreBearspawned", info.InitiatorPlayer.UserIDString)), chaticon); } if (configData.DropData.Trigger) return; } if (SpawnRate(configData.AnimalData.PBear.PBearRate) == true) { if (!permission.UserHasPermission(player.UserIDString, PBearTrigger_Perm)) return; for (int i = 0; i < configData.AnimalData.PBear.PBearAmount; i++) { _AnimalHealth = configData.AnimalData.PBear.PBearHealth; _AnimalLife = configData.AnimalData.PBear.Life; _AnimalString = PBearString; SpawnAnimal(entity.transform.position); } if (configData.AnimalData.PBear.PBearAmount == 1 && configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("PBearspawned", info.InitiatorPlayer.UserIDString)), chaticon); } else if (configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MorePBearspawned", info.InitiatorPlayer.UserIDString)), chaticon); } if (configData.DropData.Trigger) return; } if (SpawnRate(configData.AnimalData.Boar.BoarRate) == true) { if (!permission.UserHasPermission(player.UserIDString, BoarTrigger_Perm)) return; for (int i = 0; i < configData.AnimalData.Boar.BoarAmount; i++) { _AnimalHealth = configData.AnimalData.Boar.BoarHealth; _AnimalLife = configData.AnimalData.Boar.Life; _AnimalString = boarstring; SpawnAnimal(entity.transform.position); } if (configData.AnimalData.Boar.BoarAmount == 1 && configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Boarspawned", info.InitiatorPlayer.UserIDString)), chaticon); } else if (configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MoreBoarspawned", info.InitiatorPlayer.UserIDString)), chaticon); } if (configData.DropData.Trigger) return; } if (SpawnRate(configData.AnimalData.Chicken.ChickenRate) == true) { if (!permission.UserHasPermission(player.UserIDString, ChickenTrigger_Perm)) return; for (int i = 0; i < configData.AnimalData.Chicken.ChickenAmount; i++) { _AnimalHealth = configData.AnimalData.Chicken.ChickenHealth; _AnimalLife = configData.AnimalData.Chicken.Life; _AnimalString = chickenString; SpawnAnimal(entity.transform.position); } if (configData.AnimalData.Chicken.ChickenAmount == 1 && configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Chickenspawned", info.InitiatorPlayer.UserIDString)), chaticon); } else if (configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MoreChickenspawned", info.InitiatorPlayer.UserIDString)), chaticon); } if (configData.DropData.Trigger) return; } if (SpawnRate(configData.AnimalData.Wolf.WolfRate) == true) { if (!permission.UserHasPermission(player.UserIDString, WolfTrigger_Perm)) return; for (int i = 0; i < configData.AnimalData.Wolf.WolfAmount; i++) { _AnimalHealth = configData.AnimalData.Wolf.WolfHealth; _AnimalLife = configData.AnimalData.Wolf.Life; _AnimalString = wolfString; SpawnAnimal(entity.transform.position); } if (configData.AnimalData.Wolf.WolfAmount == 1 && configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Wolfspawned", info.InitiatorPlayer.UserIDString)), chaticon); } else if (configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("MoreWolvesspawned", info.InitiatorPlayer.UserIDString)), chaticon); } if (configData.DropData.Trigger) return; } #endregion #region explosives if (SpawnRate(configData.ExplosivesData.BeancanRate) == true) { if (!permission.UserHasPermission(player.UserIDString, ExploTrigger_Perm)) return; SpawnBeancan(beancanString, entity.transform.position); if (configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Beancanspawned", info.InitiatorPlayer.UserIDString)), chaticon); } if (configData.DropData.Trigger) return; } if (SpawnRate(configData.ExplosivesData.GrenadeRate) == true) { if (!permission.UserHasPermission(player.UserIDString, ExploTrigger_Perm)) return; SpawnGrenade(grenadeString, entity.transform.position); if (configData.DropData.ShowMsg == true) { Player.Message(info.InitiatorPlayer, prefix + string.Format(msg("Grenadespawned", info.InitiatorPlayer.UserIDString)), chaticon); } if (configData.DropData.Trigger) return; } #endregion } } } } object OnNpcKits(BasePlayer player) { if (player?.gameObject?.GetComponent<Zombies>() != null) return true; return null; } private object OnNpcTarget(BaseEntity attacker, BaseEntity target) { if (attacker?.gameObject?.GetComponent<Zombies>()) { if (target is ScarecrowNPC|| target is BaseNpc) { return true; } if (target is TunnelDweller || target is UnderwaterDweller) { return true; } return null; } if (target?.gameObject?.GetComponent<Zombies>()) { return true; } return null; } private object OnNpcTarget(BaseEntity attacker, BasePlayer target) { if (attacker?.gameObject?.GetComponent<Zombies>()) { if (target.IsSleeping() || target.IsFlying || !(target.userID.IsSteamId())) return false; } return null; } private void OnFireBallDamage(FireBall fire, ScarecrowNPC npc, HitInfo info) { if (!(npc?.gameObject?.GetComponent<Zombies>() && info.Initiator is FireBall)) { return; } info.damageTypes = new DamageTypeList(); info.DoHitEffects = false; info.damageTypes.ScaleAll(0f); } #endregion #region Event Helpers #region Nav & Checks public Vector3 GetNavPoint(Vector3 position) { NavMeshHit hit; if (!NavMesh.SamplePosition(position, out hit, 5, -1)) { return position; } else if (Physics.RaycastAll(hit.position + new Vector3(0, 100, 0), Vector3.down, 99f, 1235288065).Any()) { return position; } else if (hit.position.y < TerrainMeta.WaterMap.GetHeight(hit.position)) { return position; } position = hit.position; return position; } private bool SpawnRate(int npcRate) { if (rnd.Next(1, 101) <= npcRate) { return true; } return false; } private bool CheckPlayer(HitInfo info) { bool Checker = false; BasePlayer player = info.InitiatorPlayer; if (player != null || player.IsValid() || info?.Initiator != null) { Checker = true; } return Checker; } #endregion #region Scarecrow private void Spawnnpc(Vector3 position) { Vector3 pos = position + UnityEngine.Random.onUnitSphere * 1.5f; pos.y = TerrainMeta.HeightMap.GetHeight(pos); ScarecrowNPC npc = (ScarecrowNPC)GameManager.server.CreateEntity(zombie, pos, new Quaternion(), true); npc.Spawn(); NextTick(() => { if (npc == null) return; var mono = npc.gameObject.AddComponent<Zombies>(); mono.SpawnPoint = pos; npc.startHealth = configData.NPCData.NPCHealth; npc.InitializeHealth(configData.NPCData.NPCHealth, configData.NPCData.NPCHealth); npc.CanAttack(); timer.Once(0.5f, () => { Chainsaw heldEntity = npc.GetHeldEntity() as Chainsaw; if (heldEntity != null) { npc.displayName = configData.NPCData.NPCName2 + " " + RandomUsernames.Get((int)npc.userID); heldEntity.SetFlag(Chainsaw.Flags.On, true); heldEntity.SendNetworkUpdateImmediate(); } else { npc.displayName = configData.NPCData.NPCName + " " + RandomUsernames.Get((int)npc.userID); } }); if (configData.NPCData.FromHell) { var Fire = GameManager.server.CreateEntity(fireball1, new Vector3(0, 1, 0), Quaternion.Euler(0, 0, 0)); Fire.gameObject.Identity(); Fire.SetParent(npc); Fire.Spawn(); timer.Once(1f, () => { if (Fire != null) Fire.Kill(); Puts($"{npc} spawned From Hell (on Fire)"); }); } npc.damageScale = configData.NPCData.NPCDamageScale; if (configData.NPCData.UseKit && configData.NPCData.KitName.Count > 0) { object checkKit = Kits?.CallHook("GetKitInfo", configData.NPCData.KitName[new System.Random().Next(configData.NPCData.KitName.Count())]); if (checkKit == null) NextTick(() => { var inv_belt = npc.inventory.containerBelt; var inv_wear = npc.inventory.containerWear; Item eyes = ItemManager.CreateByName("gloweyes", 1, 0); if (eyes != null) eyes.MoveToContainer(inv_wear); /* npc.inventory.Strip(); Item mask = ItemManager.CreateByName("hat.gas.mask", 1, 0); Item boots = ItemManager.CreateByName("shoes.boots", 1, 0); Item gloves = ItemManager.CreateByName("burlap.gloves", 1, 0); switch (UnityEngine.Random.Range(0, 2)) { case 0: ItemManager.CreateByName("jumpsuit.suit.blue", 1, 0).MoveToContainer(inv_wear, 0); break; default: ItemManager.CreateByName("jumpsuit.suit", 1, 0).MoveToContainer(inv_wear, 0); break; } switch (UnityEngine.Random.Range(0, 4)) { case 0: ItemManager.CreateByName("machete", 1, 0).MoveToContainer(inv_belt, 0); break; case 1: ItemManager.CreateByName("pitchfork", 1, 0).MoveToContainer(inv_belt, 0); break; case 2: ItemManager.CreateByName("mace", 1, 0).MoveToContainer(inv_belt, 0); break; default: ItemManager.CreateByName("salvaged.cleaver", 1, 0).MoveToContainer(inv_belt, 0); break; } if (mask != null) mask.MoveToContainer(inv_wear); if (boots != null) boots.MoveToContainer(inv_wear); if (gloves != null) gloves.MoveToContainer(inv_wear); */ PrintWarning($"Kit for {npc} does not exist - Using a default outfit."); }); else { npc.inventory.Strip(); Kits?.Call($"GiveKit", npc, configData.NPCData.KitName[new System.Random().Next(configData.NPCData.KitName.Count())]); } } if (!configData.NPCData.UseKit || configData.NPCData.KitName.Count == 0) { var inv_belt = npc.inventory.containerBelt; var inv_wear = npc.inventory.containerWear; Item eyes = ItemManager.CreateByName("gloweyes", 1, 0); if (eyes != null) eyes.MoveToContainer(inv_wear); } }); if (npc.IsHeadUnderwater()) { npc.Kill(); Puts($"{npc} got destroyed for being under water!!!"); return; } timer.Once(configData.NPCData.NPCLife * 60, () => { if (npc != null) { npc.Kill(); Puts($"{npc} Died of old age"); } return; }); } #endregion #region Scientist private void SpawnScientist(Vector3 position) { Vector3 pos = position + UnityEngine.Random.onUnitSphere * 1.5f; pos.y = TerrainMeta.HeightMap.GetHeight(pos); NPCPlayer npc = (NPCPlayer)GameManager.server.CreateEntity(_scientist, pos, new Quaternion(), true); npc.Spawn(); NextTick(() => { if (npc == null) return; var mono = npc.gameObject.AddComponent<Scientists>(); mono.SpawnPoint = pos; npc.startHealth = SciHealth; npc.InitializeHealth(SciHealth, SciHealth); npc.CanAttack(); timer.Once(0.5f, () => { npc.displayName = SciName + " " + RandomUsernames.Get((int)npc.userID); }); if (_FromHell) { var Fire = GameManager.server.CreateEntity(fireball1, new Vector3(0, 1, 0), Quaternion.Euler(0, 0, 0)); Fire.gameObject.Identity(); Fire.SetParent(npc); Fire.Spawn(); timer.Once(1f, () => { if (Fire != null) Fire.Kill(); Puts($"{npc} spawned From Hell (on Fire)"); }); } npc.damageScale = SciDamageScale; if (_UseKit && SciKit.Count > 0) { object checkKit = Kits?.CallHook("GetKitInfo", SciKit[new System.Random().Next(SciKit.Count())]); if (checkKit == null) timer.Once(1f, () => { PrintWarning($"Kit for {npc} does not exist - Using a default outfit."); }); else { npc.inventory.Strip(); Kits?.Call($"GiveKit", npc, SciKit[new System.Random().Next(SciKit.Count())]); timer.Once(1f, () => { PrintWarning($"Kit for {npc} succesfully equiped."); }); } } if (!_UseKit || SciKit.Count == 0) { timer.Once(1f, () => { PrintWarning($"{npc} spawned Using a default outfit."); }); } }); if (npc.IsHeadUnderwater()) { npc.Kill(); timer.Once(1f, () => { PrintWarning($"{npc} got destroyed for being under water!!!"); }); return; } timer.Once(SciLifetime * 60, () => { if (npc != null) { npc.Kill(); Puts($"{npc} Died of old age"); } return; }); } #endregion #region Airdrop private void SpawnSupplyCrate(string prefab, Vector3 position) { Vector3 newPosition = position + new Vector3(0, configData.AirdropData.AirdropHeight, 0); BaseEntity SupplyCrateEntity = GameManager.server.CreateEntity(prefab, newPosition); if (SupplyCrateEntity != null) { SupplyDrop Drop = SupplyCrateEntity.GetComponent<SupplyDrop>(); Drop.Spawn(); } } #endregion #region Animals private void SpawnAnimal(Vector3 position) { Vector3 pos = position + UnityEngine.Random.onUnitSphere * 1.5f; pos.y = TerrainMeta.HeightMap.GetHeight(pos); BaseNpc Animal = (BaseNpc)GameManager.server.CreateEntity(_AnimalString, pos, new Quaternion(), true); if (Animal != null) { Animal.Spawn(); Animal.startHealth = _AnimalHealth; Animal.InitializeHealth(_AnimalHealth, _AnimalHealth); } timer.Once(_AnimalLife * 60, () => { if (Animal != null) { Animal.Kill(); Puts($"The {Animal.ShortPrefabName.ToString()} Died of old age"); } return; }); } #endregion #region Explosives private void SpawnBeancan(string prefab, Vector3 position) { Vector3 newPosition = position + new Vector3(0, 1.4f, 0); BaseEntity Beancan = GameManager.server.CreateEntity(prefab, newPosition); if (Beancan != null) { Beancan.Spawn(); } } private void SpawnGrenade(string prefab, Vector3 position) { Vector3 newPosition = position + new Vector3(0, 1.4f, 0); BaseEntity Grenade = GameManager.server.CreateEntity(prefab, newPosition); if (Grenade != null) { Grenade.Spawn(); } } #endregion #endregion #region Message helper private string msg(string key, string id = null) => lang.GetMessage(key, this, id); #endregion #region Data helpers Playerinfo get_user(BasePlayer player) { if (!Interface.Oxide.DataFileSystem.ExistsDatafile(file_main + player.UserIDString)) { Playerinfo user = new Playerinfo(); user.userName = player.displayName.ToString(); user.barrelCount = 0; update_user(player, user); return user; } else { string raw_player_file = Interface.Oxide.DataFileSystem.ReadObject<string>(file_main + player.UserIDString); return JsonConvert.DeserializeObject<Playerinfo>(raw_player_file); } } void update_user(BasePlayer player, Playerinfo user) { Interface.Oxide.DataFileSystem.WriteObject<string>(file_main + player.UserIDString, JsonConvert.SerializeObject(user)); } public class Playerinfo { private string _userName; private int _barrelCount; public Playerinfo() { } public int barrelCount { get { return _barrelCount; } set { _barrelCount = value; } } public string userName { get { return _userName; } set { _userName = value; } } } #endregion } }
npc.Brain thats the fix oof lol
Error while compiling: Barrelless.cs(738,40): error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line
above has solution...
Error while compiling: Barrelless.cs(738,40): error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line
That worked like a charm, thanks.
Another abandoned uMod plugin...
codepimp1234Another abandoned uMod plugin...
Perhaps it has been by other developers but as far as other server owners this plugin is very much alive and the answer to how to fix it one merely needs to scroll up.
Fix above still not working for me what am i doing wrong
I deleted contence of old plugin and added the above with no luck
does any one have a working .cs it seems to be kicking my but for some reason even though you couldnt make it any easier lol!!
drnateydoes any one have a working .cs it seems to be kicking my but for some reason even though you couldnt make it any easier lol!!
I worked it out what i was doing wrong just add the parts in bold to the origional .cs make sure you use a Capital for the B in Brain once i did that plug in worked fine
npc.Brain.Senses.Init(npc, npc.Brain, 5f, 30f, 40f, 135f, true, true, true, 60f, false, false, true, EntityType.Player, true); for Zombies
and
npc.Brain.Senses.Init(npc, npc.Brain, 5f, 50f, 50f, -1f, true, false, true, 60f, false, false, false, EntityType.Player, false); for Scientists and that got it to compile.
Ater going thru i finally got it should be taken on by a new dev that would take care of it even if its 5 bucks or more worth itPumblerI worked it out what i was doing wrong just add the parts in bold to the origional .cs make sure you use a Capital for the B in Brain once i did that plug in worked fine
npc.Brain.Senses.Init(npc, npc.Brain, 5f, 30f, 40f, 135f, true, true, true, 60f, false, false, true, EntityType.Player, true); for Zombies
and
npc.Brain.Senses.Init(npc, npc.Brain, 5f, 50f, 50f, -1f, true, false, true, 60f, false, false, false, EntityType.Player, false); for Scientists and that got it to compile.
Locked automatically
- 1
- 2