Disable turrets in caves?

Hey so some people are abusing a plugin i have where they have powerless electronics. They spam turrets in their cave. is there a plugin that disables turrets in caves?

Only an idea. I don´t know a special plugin only for disable turrets in caves ;) but you could use ZoneManager.

Fly in the middle of the caves and create the zones with sufficient radius. Than set zone flag

  • noturrettargeting - true/false - Stops turrets from targeting players (autoturret/flameturret/guntrap)

Would need to have a custom addon made that detects caves and disables turrets.

 

You can run your server as you see fit but if I may ask whats the diffrence if I place 50 turrets in a cave base or 50 turrets in my above ground base? I mean yes above ground bases may be easier to raid but at the same time cave bases are smaller... so they both have pros and cons to each.

Probably just check if entity is a turret, then if it's being placed in cave, if yes then destroy the turret and return it to player's inv?

I know one plugin, not sure if was here or on another website but completely prevents buidling in-caves... Maybe modified version of it to only block turrets can do the job done. Idk.

This allows you to set a limit to total you can place in a cave, setting to 0 just alerts them they can't place any, setting to 5 would allow 5 per cave total.

 

using System;
using System.Collections.Generic;
using Oxide.Core;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("CaveTurretLimiter", "8SecSleeper", "1.0.0")]
    class CaveTurretLimiter : RustPlugin
    {
		private readonly int layerMasks = LayerMask.GetMask("Deployed");
        private List<Vector3> cavePositions = new List<Vector3>();
        private int maxTurretsInCave = 3;
        private float caveRadius = 100f;
		
        private void OnServerInitialized()
        {
			foreach (var monument in UnityEngine.Object.FindObjectsOfType<MonumentInfo>())
            {			
				if (monument.name.Contains("cave"))			 
					 cavePositions.Add(monument.transform.position);				              			
			}          
        }
		
		object CanBuild(Planner planner, Construction prefab, Construction.Target target)
		{			
			BasePlayer player = planner.GetOwnerPlayer();
            if (player == null || !prefab)
                return null;
			
			if (target.position == Vector3.zero)
				return null;
			
			if (!prefab.ToString().Contains("autoturret_deployed"))
				return null;
			
			if (maxTurretsInCave == 0)
			{
				player.ChatMessage("You're not allowed to place turrets in caves");
				return false;
			}
			if (IsInCaveMonument(target.position))
            {			
				int turretsInCave = GetTurretsInCaveCount(target.position);
                
                if (turretsInCave >= maxTurretsInCave)
                {
                    player.ChatMessage($"There are already {maxTurretsInCave} turrets in this cave. You have reached the limit.");
					return false;
                } else {
					player.ChatMessage($"There have deployed {turretsInCave + 1} turrets in this cave. You're only allowed {maxTurretsInCave} ({maxTurretsInCave - turretsInCave - 1} remaining)");
				}
            }
					
			return null;	
		}
		
        private bool IsInCaveMonument(Vector3 position)
        {
            foreach (var cavePos in cavePositions)
            {
                float distance = Vector3.Distance(position, cavePos);
                if (distance < caveRadius)
                    return true;
            }
            return false;
        }
		
		private int GetTurretsInCaveCount(Vector3 position)
        {
			Puts("enter 1");
            List<BaseEntity> entities = new List<BaseEntity>();
            int turretsCount = 0;

            Vis.Entities(position, caveRadius, entities, layerMasks);

            foreach (var entity in entities)
            {
                Puts($"found {entity} {entity.PrefabName}");
				if (entity != null && entity.PrefabName.Equals("assets/prefabs/npc/autoturret/autoturret_deployed.prefab", StringComparison.OrdinalIgnoreCase))
                {
                    turretsCount++;
                }
            }		

            return turretsCount;
        }
    
    }
}


Merged post

using System;
using System.Collections.Generic;
using Oxide.Core;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("CaveTurretLimiter", "8SecSleeper", "1.0.1")]
    class CaveTurretLimiter : RustPlugin
    {
		private readonly int layerMasks = LayerMask.GetMask("Deployed");
        private List<Vector3> cavePositions = new List<Vector3>();
        private int maxTurretsInCave = 3;
        private float caveRadius = 75f;
		
        private void OnServerInitialized()
        {
			foreach (var monument in UnityEngine.Object.FindObjectsOfType<MonumentInfo>())
            {			
				if (monument.name.Contains("cave"))			 
					 cavePositions.Add(monument.transform.position);				              			
			}          
        }
		
		object CanBuild(Planner planner, Construction prefab, Construction.Target target)
		{			
			BasePlayer player = planner.GetOwnerPlayer();
            if (player == null || !prefab)
                return null;
			
			if (target.position == Vector3.zero)
				return null;
			
			if (!prefab.ToString().Contains("autoturret_deployed"))
				return null;
			
			if (maxTurretsInCave == 0)
			{
				player.ChatMessage("You're not allowed to place turrets in caves");
				return false;
			}
			if (IsInCaveMonument(target.position))
            {			
				int turretsInCave = GetTurretsInCaveCount(target.position);
                
                if (turretsInCave >= maxTurretsInCave)
                {
                    player.ChatMessage($"There are already {maxTurretsInCave} turrets in this cave. You have reached the limit.");
					return false;
                } else {
					player.ChatMessage($"There have deployed {turretsInCave + 1} turrets in this cave. You're only allowed {maxTurretsInCave} ({maxTurretsInCave - turretsInCave - 1} remaining)");
				}
            }
					
			return null;	
		}
		
        private bool IsInCaveMonument(Vector3 position)
        {
            foreach (var cavePos in cavePositions)
            {
                float distance = Vector3.Distance(position, cavePos);
                if (distance < caveRadius)
                    return true;
            }
            return false;
        }
		
		private int GetTurretsInCaveCount(Vector3 position)
        {			
            List<BaseEntity> entities = new List<BaseEntity>();
            int turretsCount = 0;

            Vis.Entities(position, caveRadius, entities, layerMasks);

            foreach (var entity in entities)
            {
				if (entity != null && entity.PrefabName.Equals("assets/prefabs/npc/autoturret/autoturret_deployed.prefab", StringComparison.OrdinalIgnoreCase))
                {
                    turretsCount++;
                }
            }		

            return turretsCount;
        }
    
    }
}

WOW Thank you so much!

8SecSleeper

This allows you to set a limit to total you can place in a cave, setting to 0 just alerts them they can't place any, setting to 5 would allow 5 per cave total.

 

using System;
using System.Collections.Generic;
using Oxide.Core;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("CaveTurretLimiter", "8SecSleeper", "1.0.0")]
    class CaveTurretLimiter : RustPlugin
    {
		private readonly int layerMasks = LayerMask.GetMask("Deployed");
        private List<Vector3> cavePositions = new List<Vector3>();
        private int maxTurretsInCave = 3;
        private float caveRadius = 100f;
		
        private void OnServerInitialized()
        {
			foreach (var monument in UnityEngine.Object.FindObjectsOfType<MonumentInfo>())
            {			
				if (monument.name.Contains("cave"))			 
					 cavePositions.Add(monument.transform.position);				              			
			}          
        }
		
		object CanBuild(Planner planner, Construction prefab, Construction.Target target)
		{			
			BasePlayer player = planner.GetOwnerPlayer();
            if (player == null || !prefab)
                return null;
			
			if (target.position == Vector3.zero)
				return null;
			
			if (!prefab.ToString().Contains("autoturret_deployed"))
				return null;
			
			if (maxTurretsInCave == 0)
			{
				player.ChatMessage("You're not allowed to place turrets in caves");
				return false;
			}
			if (IsInCaveMonument(target.position))
            {			
				int turretsInCave = GetTurretsInCaveCount(target.position);
                
                if (turretsInCave >= maxTurretsInCave)
                {
                    player.ChatMessage($"There are already {maxTurretsInCave} turrets in this cave. You have reached the limit.");
					return false;
                } else {
					player.ChatMessage($"There have deployed {turretsInCave + 1} turrets in this cave. You're only allowed {maxTurretsInCave} ({maxTurretsInCave - turretsInCave - 1} remaining)");
				}
            }
					
			return null;	
		}
		
        private bool IsInCaveMonument(Vector3 position)
        {
            foreach (var cavePos in cavePositions)
            {
                float distance = Vector3.Distance(position, cavePos);
                if (distance < caveRadius)
                    return true;
            }
            return false;
        }
		
		private int GetTurretsInCaveCount(Vector3 position)
        {
			Puts("enter 1");
            List<BaseEntity> entities = new List<BaseEntity>();
            int turretsCount = 0;

            Vis.Entities(position, caveRadius, entities, layerMasks);

            foreach (var entity in entities)
            {
                Puts($"found {entity} {entity.PrefabName}");
				if (entity != null && entity.PrefabName.Equals("assets/prefabs/npc/autoturret/autoturret_deployed.prefab", StringComparison.OrdinalIgnoreCase))
                {
                    turretsCount++;
                }
            }		

            return turretsCount;
        }
    
    }
}


Merged post

using System;
using System.Collections.Generic;
using Oxide.Core;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("CaveTurretLimiter", "8SecSleeper", "1.0.1")]
    class CaveTurretLimiter : RustPlugin
    {
		private readonly int layerMasks = LayerMask.GetMask("Deployed");
        private List<Vector3> cavePositions = new List<Vector3>();
        private int maxTurretsInCave = 3;
        private float caveRadius = 75f;
		
        private void OnServerInitialized()
        {
			foreach (var monument in UnityEngine.Object.FindObjectsOfType<MonumentInfo>())
            {			
				if (monument.name.Contains("cave"))			 
					 cavePositions.Add(monument.transform.position);				              			
			}          
        }
		
		object CanBuild(Planner planner, Construction prefab, Construction.Target target)
		{			
			BasePlayer player = planner.GetOwnerPlayer();
            if (player == null || !prefab)
                return null;
			
			if (target.position == Vector3.zero)
				return null;
			
			if (!prefab.ToString().Contains("autoturret_deployed"))
				return null;
			
			if (maxTurretsInCave == 0)
			{
				player.ChatMessage("You're not allowed to place turrets in caves");
				return false;
			}
			if (IsInCaveMonument(target.position))
            {			
				int turretsInCave = GetTurretsInCaveCount(target.position);
                
                if (turretsInCave >= maxTurretsInCave)
                {
                    player.ChatMessage($"There are already {maxTurretsInCave} turrets in this cave. You have reached the limit.");
					return false;
                } else {
					player.ChatMessage($"There have deployed {turretsInCave + 1} turrets in this cave. You're only allowed {maxTurretsInCave} ({maxTurretsInCave - turretsInCave - 1} remaining)");
				}
            }
					
			return null;	
		}
		
        private bool IsInCaveMonument(Vector3 position)
        {
            foreach (var cavePos in cavePositions)
            {
                float distance = Vector3.Distance(position, cavePos);
                if (distance < caveRadius)
                    return true;
            }
            return false;
        }
		
		private int GetTurretsInCaveCount(Vector3 position)
        {			
            List<BaseEntity> entities = new List<BaseEntity>();
            int turretsCount = 0;

            Vis.Entities(position, caveRadius, entities, layerMasks);

            foreach (var entity in entities)
            {
				if (entity != null && entity.PrefabName.Equals("assets/prefabs/npc/autoturret/autoturret_deployed.prefab", StringComparison.OrdinalIgnoreCase))
                {
                    turretsCount++;
                }
            }		

            return turretsCount;
        }
    
    }
}