C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
/*
* EULA
*
* You may not copy, modify, merge, publish, distribute, sublicense, or sell copies of This Software without the Developers consent
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*
* Copyright Ryuk © 2023
* Contact hikarigg38@gmail.com
* Developers Ryuk
*/
using Facepunch;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Rust;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using UnityEngine;
using System.Collections;
using Random = UnityEngine.Random;
using ProtoBuf;
using Oxide.Core.Configuration;
using UnityEngine.UI;
using System.IO;
using Facepunch.Extend;
using System.Text.RegularExpressions;
namespace Oxide.Plugins
{
[Info("Creative", "Ryuk", "1.1.18")]
[Description("Create zone, Imagine and Create bases, Save and load your bases and invite friends!")]
public class Creative : RustPlugin
{
[PluginReference] Plugin CopyPaste;
public static Creative Instance;
public Dictionary<string, ZoneTrigger> activeZones = new Dictionary<string, ZoneTrigger>();
private Dictionary<ulong, bool> playerInfAmmo = new Dictionary<ulong, bool>();
private Dictionary<ulong, bool> playerIsNoclip = new Dictionary<ulong, bool>();
private Dictionary<ulong, bool> playerIsLoadingBase = new Dictionary<ulong, bool>();
private Dictionary<ulong, bool> canUpgrade = new Dictionary<ulong, bool>();
private Dictionary<ulong, bool> playerStability = new Dictionary<ulong, bool>();
private Dictionary<ulong, bool> playerGodMode = new Dictionary<ulong, bool>();
private Dictionary<ulong, bool> playerResourceHud = new Dictionary<ulong, bool>();
private Dictionary<ulong, bool> playerAutomaticEntityEnable = new Dictionary<ulong, bool>();
private Dictionary<ulong, int> upgradeLevels = new Dictionary<ulong, int>();
private Dictionary<ulong, int> skinSelected = new Dictionary<ulong, int>();
private Dictionary<ulong, string> currentBaseName = new Dictionary<ulong, string>();
Dictionary<BasePlayer, HashSet<SearchLight>> deployedSearchLights = new Dictionary<BasePlayer, HashSet<SearchLight>>();
Dictionary<BasePlayer, HashSet<SamSite>> deployedSamSites = new Dictionary<BasePlayer, HashSet<SamSite>>();
private string dataFilePath;
private Dictionary<ulong, Dictionary<string, List<BuildingBlockData>>> savedBases = Facepunch.Pool.Get<Dictionary<ulong, Dictionary<string, List<BuildingBlockData>>>>();
private bool isMenuOpen = false;
private Timer checkTimer;
private Dictionary<string, VendingMachineMapMarker> machineMarkers = new Dictionary<string, VendingMachineMapMarker>();
private Dictionary<string, MapMarkerGenericRadius> sphereMarker = new Dictionary<string, MapMarkerGenericRadius>();
private List<string> resourceItems = new List<string>
{
"wood",
"stones",
"sulfur",
"cloth",
"leather",
"lowgradefuel",
"metal.refined",
"gunpowder",
"hqm",
"metal.fragments",
"fat.animal",
"skull.human",
"gears",
"pipes",
"roadsigns",
"rope",
"semibody",
"sheetmetal",
"tarp",
"techparts",
"targeting.computer",
"cctv.camera",
"riflebody",
"scrap",
"smgbody",
"explosives",
"metalspring",
"electricfuse",
"metalblade",
"metalpipe",
"ladder.wooden.wall",
"skull.wolf",
"sewingkit",
};
void Loaded()
{
Instance = this;
}
private void RegisterPermissions()
{
permission.RegisterPermission("creative.all", this);
permission.RegisterPermission("creative.fly", this);
permission.RegisterPermission("creative.infammo", this);
permission.RegisterPermission("creative.infres", this);
permission.RegisterPermission("creative.stability", this);
permission.RegisterPermission("creative.godmode", this);
permission.RegisterPermission("creative.autoenablentity", this);
permission.RegisterPermission("creative.allowclaim", this);
permission.RegisterPermission("creative.vip", this);
permission.RegisterPermission("creative.admin", this);
}
void Init()
{
RegisterPermissions();
deployedSearchLights = new Dictionary<BasePlayer, HashSet<SearchLight>>();
deployedSamSites = new Dictionary<BasePlayer, HashSet<SamSite>>();
dataFilePath = Path.Combine(Interface.GetMod().DataDirectory, "Creatives");
LoadData();
LoadConfig();
cmd.AddChatCommand(_config.claim_cmd, this, "ClaimZone");
cmd.AddChatCommand(_config.unclaim_cmd, this, "UnclaimZone");
cmd.AddChatCommand(_config.create_cmd, this, "team_create");
cmd.AddChatCommand(_config.invite_cmd, this, "team_invite");
cmd.AddChatCommand(_config.save_cmd, this, "ChatCmdSaveBase");
cmd.AddChatCommand(_config.load_cmd, this, "ChatCmdLoadBase");
cmd.AddChatCommand(_config.time_cmd, this, "SetTimeCommand");
cmd.AddChatCommand(_config.list_cmd, this, "ChatCmdListBases");
cmd.AddChatCommand(_config.undo_cmd, this, "ChatCmdUndo");
cmd.AddChatCommand(_config.menu_cmd, this, "ChatMenu");
cmd.AddChatCommand(_config.info_cmd, this, "ChatInfoCommand");
cmd.AddChatCommand(_config.cost_cmd, this, "BaseCostCommand");
cmd.AddChatCommand(_config.upg_cmd, this, "UpgradeCommand");
cmd.AddChatCommand(_config.noclip_cmd, this, "FlyCommand");
}
void OnServerInitialized()
{
if (CopyPaste != null)
Puts("CopyPaste plugin found");
foreach (var player in BasePlayer.activePlayerList){
playerInfAmmo[player.userID] = false;
playerIsNoclip[player.userID] = false;
playerIsLoadingBase[player.userID] = false;
playerStability[player.userID] = false;
canUpgrade[player.userID] = false;
playerGodMode[player.userID] = true;
playerResourceHud[player.userID] = _config.res_hud;
playerAutomaticEntityEnable[player.userID] = false;
skinSelected[player.userID] = 0;
upgradeLevels[player.userID] = 0;
currentBaseName[player.userID] = "autosave";
GrantResources(player);
checkTimer = timer.Repeat(5f, 0, () =>
{
RemoveEffectsFromPlayer(player);
});
}
DownloadImage();
foreach (ItemBlueprint bp in ItemManager.GetBlueprints())
bp.workbenchLevelRequired = 0;
if (_config.disable_terrain_kick)
ConsoleSystem.Run(ConsoleSystem.Option.Server, "antihack.terrain_protection 0");
if (_config.disable_decay)
{
ConsoleSystem.Run(ConsoleSystem.Option.Server, "decay.scale 0");
ConsoleSystem.Run(ConsoleSystem.Option.Server, "decay.upkeep 0");
}
if (_config.always_day){
ConsoleSystem.Run(ConsoleSystem.Option.Server, "env.progresstime false");
ConsoleSystem.Run(ConsoleSystem.Option.Server, "env.time 12");
}
foreach (ItemBlueprint bp in ItemManager.bpList)
{
BPs.Add(bp.targetItem.itemid);
}
LoadPublishedCodes();
}
void Unload()
{
checkTimer?.Destroy();
foreach (var kvp in activeZones.ToList())
{
UnityEngine.Object.DestroyImmediate(kvp.Value.gameObject);
}
activeZones.Clear();
foreach (var player in BasePlayer.activePlayerList)
{
DestroyButtons(player);
if (GetPlayerNoClipStatus(player))
{
player.SendConsoleCommand("noclip");
SetPlayerNoClipStatus(player);
}
}
RemoveAllMarkers();
Facepunch.Pool.FreeList(ref EntStable);
Facepunch.Pool.FreeList(ref stablentites);
Facepunch.Pool.FreeList(ref BPs);
Facepunch.Pool.Free(ref savedBases);
}
private void OnServerSave()
{
foreach (BasePlayer player in BasePlayer.activePlayerList)
{
SendReply(player, "Autosaving bases.There will be some lag.");
Vector3 Zone_Center_Pos = GetZoneCenter(player);
if (Zone_Center_Pos == Vector3.zero)
return;
if (_config.base_system == "default")
{
if (GetLoadingBaseStatus(player))
return;
SaveBase(player, "autosave");
}else if (_config.base_system == "copypaste"){
if (CopyPaste == null)
{
Puts("CopyPaste plugin not loaded.Please make sure you have added this plugin!");
return;
}
var layers = LayerMask.GetMask("Construction", "Deployed");
RaycastHit hit = new RaycastHit();
if (!Physics.Raycast(player.eyes.HeadRay(), out hit, 100f, layers))
{
SendReply(player, "Invalid entity.Please look at your base before save!");
return;
}
string new_base_name = player.userID + "_autosave";
var files = Interface.Oxide.DataFileSystem.GetFiles("copypaste/");
var options = new List<string>{"each", "false", "radius", "60", "method", "proximity", "share", "true", "tree", "false" };
var status = CopyPaste.Call("TryCopyFromSteamId", player.userID, new_base_name, options.ToArray());
if (status is string)
{
SendReply(player, "There was a problem trying to save your base.");
return;
}
SendReply(player, $"Successfully saved 'autosave'");
}
}
}
private void CreateMapMarker(string markerID, string text, Vector3 position, float radius, BasePlayer player)
{
float wrldSize = ConVar.Server.worldsize;
wrldSize = wrldSize / 25;
if (_config.divider_val != 0.0f)
wrldSize = _config.divider_val;
if (!_config.zone_mapmarkers)
return;
MapMarkerGenericRadius mapMarker = GameManager.server.CreateEntity("assets/prefabs/tools/map/genericradiusmarker.prefab", position) as MapMarkerGenericRadius;
if (mapMarker != null)
{
mapMarker.alpha = 0.6f;
mapMarker.color1 = Color.green;
mapMarker.color2 = Color.white;
mapMarker.name = markerID;
mapMarker.radius = radius / wrldSize;
mapMarker.OwnerID = player.userID;
mapMarker.Spawn();
mapMarker.SendUpdate();
sphereMarker[markerID] = mapMarker;
}
var markerPrefab = GameManager.server.CreateEntity("assets/prefabs/deployable/vendingmachine/vending_mapmarker.prefab", position) as VendingMachineMapMarker;
if (markerPrefab != null)
{
markerPrefab.markerShopName = text;
markerPrefab.SetFlag(BaseEntity.Flags.Busy, true, false, true);
markerPrefab.Spawn();
markerPrefab.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);
machineMarkers[markerID] = markerPrefab;
}
}
private void RemoveMarker(string markerID)
{
if (sphereMarker.ContainsKey(markerID))
{
MapMarkerGenericRadius marker = sphereMarker[markerID];
if (marker != null && !marker.IsDestroyed)
{
marker.Kill();
}
sphereMarker.Remove(markerID);
}
if (machineMarkers.ContainsKey(markerID))
{
VendingMachineMapMarker marker = machineMarkers[markerID];
if (marker != null)
{
marker.Kill();
}
machineMarkers.Remove(markerID);
}
}
private void RemoveAllMarkers()
{
foreach (var Smarker in sphereMarker.Values)
{
if (Smarker != null)
{
Smarker.Kill();
}
}
sphereMarker.Clear();
foreach (var marker in machineMarkers.Values)
{
if (marker != null)
{
marker.Kill();
}
}
machineMarkers.Clear();
}
private bool DoesZoneCollide(Vector3 position, float radius)
{
if (_config.lobby_position != Vector3.zero)
{
float distance_lobby = Vector3.Distance(position, _config.lobby_position);
if (distance_lobby < radius + 60f)
return true;
}
foreach (var kvp in activeZones)
{
var existingZone = kvp.Value;
float distance = Vector3.Distance(position, existingZone.transform.position);
if (distance < radius + existingZone.GetColliderRadius())
{
return true;
}
}
return false;
}
public string GenerateRandomZoneID()
{
int length = 10;
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
System.Random random = new System.Random();
string randomID = new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
return randomID;
}
float getplayerradius(BasePlayer player)
{
if (permission.UserHasPermission(player.UserIDString, "creative.admin") || permission.UserHasPermission(player.UserIDString, "creative.vip"))
return _config.vip_zone_radius;
return _config.default_zone_radius;
}
void DeleteEntities(BasePlayer player)
{
Vector3 Zone_Center_Pos = GetZoneCenter(player);
if (Zone_Center_Pos == Vector3.zero)
{
SendReply(player, "You don't have any claimed area!");
return;
}
List<BaseEntity> entitiesToRemove = Facepunch.Pool.GetList<BaseEntity>();
int entitiesCount = 0;
foreach (var entity in BaseNetworkable.serverEntities.OfType<BaseEntity>())
{
if (entity is BasePlayer || entity.OwnerID == 0)
continue;
if (Vector3.Distance(Zone_Center_Pos, entity.transform.position) <= getplayerradius(player))
{
entitiesToRemove.Add(entity);
entitiesCount++;
}
}
ServerMgr.Instance.StartCoroutine(DeleteEntitiesCoroutine(player, entitiesToRemove, entitiesCount));
}
private IEnumerator DeleteEntitiesCoroutine(BasePlayer player, List<BaseEntity> entitiesToRemove, int totalEntities)
{
float deletionDelay = 0.2f;
for (int i = 0; i < totalEntities; i++)
{
if (i < entitiesToRemove.Count)
{
BaseEntity entityToRemove = entitiesToRemove[i];
if (entityToRemove != null && !entityToRemove.IsDestroyed)
entityToRemove.Kill();
}
yield return new WaitForSeconds(deletionDelay);
}
SendReply(player, $"Removed {totalEntities} entities/buildings in a {getplayerradius(player)} radius.");
Facepunch.Pool.FreeList(ref entitiesToRemove);
}
void OnPlayerConnected(BasePlayer player){
if (!player)
return;
GrantResources(player);
playerInfAmmo[player.userID] = false;
playerIsNoclip[player.userID] = false;
playerIsLoadingBase[player.userID] = false;
playerStability[player.userID] = false;
canUpgrade[player.userID] = false;
playerGodMode[player.userID] = true;
playerResourceHud[player.userID] = _config.res_hud;
playerAutomaticEntityEnable[player.userID] = false;
skinSelected[player.userID] = 0;
upgradeLevels[player.userID] = 0;
currentBaseName[player.userID] = "autosave";
CheckBuildingPlan(player);
ShowInfoHelpGUI(player);
ServerMgr.Instance.StartCoroutine(UnlockBlueprints(player));
player.ClientRPCPlayer(null, player, "craftMode", 1);
player.SetPlayerFlag(BasePlayer.PlayerFlags.IsDeveloper, true);
player.PauseFlyHackDetection(86400f);
player.PauseSpeedHackDetection(86400f);
player.SendNetworkUpdateImmediate();
}
private List<int> BPs = Facepunch.Pool.GetList<int>();
private IEnumerator UnlockBlueprints(BasePlayer player)
{
var currentPlayerBps = player.PersistantPlayerInfo.unlockedItems;
foreach (var bp in BPs)
{
if (!currentPlayerBps.Contains(bp))
currentPlayerBps.Add(bp);
}
var persistantPlayerInfo = player.PersistantPlayerInfo;
persistantPlayerInfo.unlockedItems = currentPlayerBps;
player.PersistantPlayerInfo = persistantPlayerInfo;
player.SendNetworkUpdateImmediate();
player.ClientRPCPlayer(null, player, "UnlockedBlueprint", 0);
yield return new WaitForSeconds(0.05f);
}
void OnPlayerDisconnected(BasePlayer player, string reason)
{
if (GetPlayerNoClipStatus(player))
{
player.SendConsoleCommand("noclip");
}
RemoveEffectsFromPlayer(player);
ulong playerId = player.userID;
if (!_config.ondisconnect_keep_things)
{
player.inventory.Strip();
List<string> zonesToRemove = Facepunch.Pool.GetList<string>();
zonesToRemove.AddRange(activeZones.Where(pair => pair.Value.GetOwner() == player.userID).Select(pair => pair.Key));
foreach (string zoneID in zonesToRemove)
{
if (activeZones.TryGetValue(zoneID, out var zoneTrigger))
{
RemoveMarker(zoneID);
DeleteEntities(player);
zoneTrigger.DeleteCircle();
activeZones.Remove(zoneID);
UnityEngine.Object.DestroyImmediate(zoneTrigger.gameObject);
}
}
Facepunch.Pool.FreeList(ref zonesToRemove);
}
}
private void OnPlayerInit(BasePlayer player)
{
timer.Once(1f, () => RemoveEffectsFromPlayer(player));
GrantResources(player);
}
private bool IsPlayerNearTerrainOrWater(Vector3 position, float minimumDistance)
{
Vector3 up = Vector3.up * minimumDistance;
return Physics.Raycast(position, Vector3.down, up.magnitude, LayerMask.GetMask("Water", "Terrain", "World", "Default"));
}
private System.Random random = new System.Random();
private string publishCodesFilePath = Path.Combine(Interface.Oxide.DataDirectory, "Creatives", "Published.json");
private List<PublishedData> publishCodes = new List<PublishedData>();
public class PublishedData
{
public ulong UserId { get; set; }
public string BaseName { get; set; }
public ulong Code { get; set; }
}
private void LoadPublishedCodes()
{
if (File.Exists(publishCodesFilePath))
{
string jsonData = File.ReadAllText(publishCodesFilePath);
publishCodes = JsonConvert.DeserializeObject<List<PublishedData>>(jsonData);
}
}
private void SavePublishedCodes()
{
string jsonData = JsonConvert.SerializeObject(publishCodes, Formatting.Indented);
File.WriteAllText(publishCodesFilePath, jsonData);
}
private ulong GenerateRandomCode()
{
return (ulong)random.Next(1000000000, int.MaxValue) * 10UL + (ulong)random.Next(0, 999999999);
}
[ChatCommand("publish")]
private void PublishCommand(BasePlayer player, string command, string[] args)
{
if (!currentBaseName.ContainsKey(player.userID))
return;
string baseName = currentBaseName[player.userID];
PublishedData existingData = publishCodes.Find(data => data.UserId == player.userID && data.BaseName == baseName);
if (existingData != null)
{
existingData.Code = GenerateRandomCode();
SavePublishedCodes();
SendReply(player, $"Your base has been republished with code {existingData.Code}");
}
else
{
ulong code = GenerateRandomCode();
publishCodes.Add(new PublishedData { UserId = player.userID, BaseName = baseName, Code = code });
SavePublishedCodes();
SendReply(player, $"Your base has been published with code {code}");
}
}
[ChatCommand("load_code")]
private void LoadCodeCommand(BasePlayer player, string command, string[] args)
{
if (args.Length < 1)
{
SendReply(player, "Usage: /load_code <published code>");
return;
}
ulong codeToLoad;
if (ulong.TryParse(args[0], out codeToLoad))
{
var entry = publishCodes.Find(c => c.Code == codeToLoad);
if (entry != null)
{
UndoBase(player);
switch (_config.base_system)
{
case "default":
LoadBase(player.userID, entry.BaseName, player);
break;
case "copypaste":
Vector3 Zone_Center_Pos = GetZoneCenter(player);
LoadBaseCp(player.userID, entry.BaseName, player, Zone_Center_Pos);
break;
}
SendReply(player, $"Loaded base using code {codeToLoad}");
}
else
{
SendReply(player, $"No base found with the code {codeToLoad}");
}
}
else
{
SendReply(player, "Invalid code.Please use a valid 10-digit code");
}
}
[ChatCommand("code_list")]
private void CodeListCommand(BasePlayer player, string command, string[] args)
{
var playerEntries = publishCodes.FindAll(c => c.UserId == player.userID);
if (playerEntries.Count > 0)
{
SendReply(player, "Your published bases:");
foreach (var entry in playerEntries)
{
SendReply(player, $"Name: {entry.BaseName} | Public Code: {entry.Code}");
}
}
else
{
SendReply(player, "You haven't published any bases yet.");
}
}
private void ClaimZone(BasePlayer player, string command, string[] args)
{
if (!permission.UserHasPermission(player.UserIDString, "creative.allowclaim") && !hasPerms(player))
{
SendReply(player, "You do not have permission to use this command.");
return;
}
string closestZoneID = FindClosestZone(player);
if (string.IsNullOrEmpty(closestZoneID))
{
ClaimZoneFunc(player);
}else{
if (activeZones.TryGetValue(closestZoneID, out var zoneTrigger))
{
if (zoneTrigger.GetOwner() == player.userID)
{
SendReply(player, "You already own a claimed area.");
}
}
}
}
private void ClaimZoneFunc(BasePlayer player)
{
Vector3 playerPosition = player.transform.position;
if (!IsPlayerNearTerrainOrWater(playerPosition, 5f))
{
SendReply(player, "You should be in the terrain before claim a zone!");
return;
}
if (DoesZoneCollide(playerPosition, getplayerradius(player)))
{
SendReply(player, "You cannot claim a zone here; It overlaps with an existing zone.");
return;
}
string zoneID = GenerateRandomZoneID();
var zoneTrigger = new GameObject().AddComponent<ZoneTrigger>();
float fixed_radius = getplayerradius(player) - 10;
zoneTrigger.CreateBubble(playerPosition, fixed_radius, zoneID, player.userID);
zoneTrigger.CenterZone = playerPosition;
activeZones.Add(zoneID, zoneTrigger);
CreateMapMarker(zoneID, player.displayName, playerPosition, getplayerradius(player), player);
SendReply(player, $"You've claimed the zone! | ID: {zoneID}");
}
[ConsoleCommand("playermenu.infres")]
private void infrescommand(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player != null)
{
if (!permission.UserHasPermission(player.UserIDString, "creative.infres") && !hasPerms(player))
{
SendReply(player, "You do not have permission to use this command.");
return;
}
player.inventory.Strip();
GrantResources(player);
}
}
[ConsoleCommand("playermenu.basecost")]
private void basecostcommand(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player != null)
{
player.SendConsoleCommand("chat.say", "/cost");
}
}
[ConsoleCommand("playermenu.claimzone")]
private void claimzonecommand(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player != null)
{
if (!permission.UserHasPermission(player.UserIDString, "creative.allowclaim") && !hasPerms(player))
{
SendReply(player, "You do not have permission to use this command.");
return;
}
string closestZoneID = FindClosestZone(player);
if (string.IsNullOrEmpty(closestZoneID))
{
ClaimZoneFunc(player);
}else{
if (activeZones.TryGetValue(closestZoneID, out var zoneTrigger))
{
if (zoneTrigger.GetOwner() == player.userID)
{
UnclaimFunc(player);
}
}
}
UpdateMenu(player);
}
}
[ConsoleCommand("playermenu.stability")]
private void stabcommand(ConsoleSystem.Arg arg)
{
var player = arg.Player();
if (player == null)
return;
if (!permission.UserHasPermission(player.UserIDString, "creative.stability") && !hasPerms(player))
{
SendReply(player, "You do not have permission to use this command.");
return;
}
if (playerStability[player.userID])
playerStability[player.userID] = false;
else
playerStability[player.userID] = true;
Vector3 Zone_Center_Pos = GetZoneCenter(player);
List<StabilityEntity> entities = GetEntitiesInRadius(Zone_Center_Pos, getplayerradius(player));
if (entities.Count > 0){
foreach (var entity in entities)
{
if (playerStability[player.userID])
entity.grounded = true;
else
entity.grounded = false;
entity.InitializeSupports();
entity.UpdateStability();
}
}
UpdateMenu(player);
}
public List<StabilityEntity> stablentites = Facepunch.Pool.GetList<StabilityEntity>();
private List<StabilityEntity> GetEntitiesInRadius(Vector3 position, float radius)
{
foreach (var entity in BaseNetworkable.serverEntities)
{
if (Vector3.Distance(entity.transform.position, position) <= radius)
{
var stabilityEntity = entity as StabilityEntity;
if (stabilityEntity != null)
{
if (!stabilityEntity.grounded)
{
stablentites.Add(stabilityEntity);
}
}
}
}
return stablentites;
}
private void UnclaimZone(BasePlayer player, string cmd, string[] args)
{
if (args.Length != 0)
{
SendReply(player, "Usage: /unclaim");
return;
}
UnclaimFunc(player);
}
private void UnclaimFunc(BasePlayer player)
{
string closestZoneID = FindClosestZone(player);
if (string.IsNullOrEmpty(closestZoneID))
{
SendReply(player, "You do not have any zones to unclaim.");
return;
}
if (playerIsLoadingBase[player.userID])
{
SendReply(player, "You can't unclaim while loading a base!");
return;
}
if (activeZones.TryGetValue(closestZoneID, out var zoneTrigger))
{
if (zoneTrigger.GetOwner() == player.userID || player.IsAdmin && permission.UserHasPermission(player.UserIDString, "creative.admin"))
{
DeleteEntities(player);
zoneTrigger.DeleteCircle();
activeZones.Remove(closestZoneID);
UnityEngine.Object.DestroyImmediate(zoneTrigger.gameObject);
RemoveMarker(closestZoneID);
SendReply(player, $"You've unclaimed zone with ID: {closestZoneID}");
}
else
{
SendReply(player, "You do not have permission to unclaim this zone.");
}
}
}
private string FindClosestZone(BasePlayer player)
{
string closestZoneID = null;
float closestDistance = float.MaxValue;
Vector3 playerPosition = player.transform.position;
foreach (var kvp in activeZones)
{
var existingZone = kvp.Value;
float distance = Vector3.Distance(playerPosition, existingZone.transform.position);
if (distance < closestDistance)
{
if (existingZone.GetOwner() == player.userID || player.Team != null && player.Team.members.Contains(existingZone.GetOwner()))
{
closestDistance = distance;
closestZoneID = kvp.Key;
}
}
}
return closestZoneID;
}
Vector3 GetZoneCenter(BasePlayer player){
var zonesToRemove = Facepunch.Pool.GetList<string>();
zonesToRemove.AddRange(activeZones.Where(pair => pair.Value.GetOwner() == player.userID).Select(pair => pair.Key));
foreach (string zoneID in zonesToRemove)
{
if (activeZones.TryGetValue(zoneID, out var zoneTrigger))
{
return zoneTrigger.GetZoneCenterZ();
}
}
Facepunch.Pool.FreeList(ref zonesToRemove);
return Vector3.zero;
}
bool GetPlayerInfAmmoStatus(BasePlayer player)
{
return playerInfAmmo[player.userID];
}
void SetPlayerInfAmmoStatus(BasePlayer player)
{
playerInfAmmo[player.userID] = !playerInfAmmo[player.userID];
}
void SetLoadingBaseStatus(BasePlayer player, bool value)
{
playerIsLoadingBase[player.userID] = value;
}
bool GetLoadingBaseStatus(BasePlayer player)
{
return playerIsLoadingBase[player.userID];
}
bool GetPlayerNoClipStatus(BasePlayer player)
{
if (!playerGodMode.ContainsKey(player.userID))
return false;
return playerIsNoclip[player.userID];
//return player.IsFlying;
}
void SetPlayerNoClipStatus(BasePlayer player)
{
playerIsNoclip[player.userID] = !playerIsNoclip[player.userID];
}
bool GetZoneOwned(BasePlayer player)
{
string closestZoneID = FindClosestZone(player);
if (string.IsNullOrEmpty(closestZoneID))
{
return false;
}
if (activeZones.TryGetValue(closestZoneID, out var zoneTrigger))
{
if (zoneTrigger.GetOwner() == player.userID || player.IsAdmin && permission.UserHasPermission(player.UserIDString, "creative.admin"))
{
return true;
}
}
return false;
}
void ChangeGTFOStatus(BasePlayer player){
string closestZoneID = FindClosestZone(player);
if (string.IsNullOrEmpty(closestZoneID))
{
SendReply(player, "You should own a zone before use GTFO.");
return;
}
if (activeZones.TryGetValue(closestZoneID, out var zoneTrigger))
{
if (zoneTrigger.GetOwner() == player.userID || player.IsAdmin && permission.UserHasPermission(player.UserIDString, "creative.admin"))
{
zoneTrigger.GTFO = !zoneTrigger.GTFO;
SendReply(player, $"[GTFO] Status: {zoneTrigger.GTFO} | zoneid: {closestZoneID}");
}
else
{
SendReply(player, "You do not have permission to change GTFO mode.");
}
}
}
bool GetGTFOStatus(BasePlayer player)
{
string closestZoneID = FindClosestZone(player);
if (string.IsNullOrEmpty(closestZoneID))
{
return true;
}
if (activeZones.TryGetValue(closestZoneID, out var zoneTrigger))
{
if (zoneTrigger.GetOwner() == player.userID || player.IsAdmin && permission.UserHasPermission(player.UserIDString, "creative.admin"))
{
return zoneTrigger.GTFO;
}
}
return true;
}
void OnPlayerInput(BasePlayer player, InputState input)
{
if (player == null || input == null)
{
return;
}
if (input.WasJustPressed(BUTTON.FIRE_THIRD))
{
ToggleMenu(player);
}
if (canUpgrade != null )
{
if (canUpgrade[player.userID])
{
if (input.WasJustPressed(BUTTON.FIRE_PRIMARY))
DoBuilding(player, "upgrade");
if (input.WasJustPressed(BUTTON.FIRE_SECONDARY))
DoBuilding(player, "downgrade");
}
}
var item = player.GetActiveItem();
if (item == null)
{
return;
}
HeldEntity heldEntity = player.GetHeldEntity() as HeldEntity;
if (input.WasJustPressed(BUTTON.RELOAD))
{
if (item.info != null && item.info.shortname != null && item.info.shortname == "hammer")
{
var layers = LayerMask.GetMask("Construction", "Default", "Deployed");
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(player.eyes.HeadRay(), out hit, 10f, layers))
{
var entity = hit.GetEntity();
if (entity != null)
{
if (entity.OwnerID == player.userID || (player.Team != null && player.Team.members.Contains(entity.OwnerID)))
{
((BaseEntity)entity).Kill();
}
}
}
}
}
}
private void RemoveEffectsFromPlayer(BasePlayer player)
{
if (player == null || !player.IsConnected)
return;
if (player.metabolism.calories.value < 500)
player.metabolism.calories.value = 500;
if (player.metabolism.hydration.value < 250)
player.metabolism.hydration.value = 250;
player.health = 100;
player.metabolism.temperature.value = 30;
player.metabolism.wetness.max = 0;
}
int RandGenerator()
{
int minValue = 0;
int maxValue = 16;
return UnityEngine.Random.Range(minValue, maxValue + 1);
}
void OnEntityBuilt(Planner planner, GameObject gameObject)
{
var player = planner.GetOwnerPlayer();
if (player == null) return;
var furnace = gameObject.GetComponent<BaseOven>();
var mixingTable = gameObject.GetComponent<Recycler>();
var turret = gameObject.GetComponent<AutoTurret>();
var door = gameObject.GetComponent<Door>();
var chineseLantern = gameObject.GetComponent<ChineseLantern>();
var searchlight = gameObject.GetComponent<SearchLight>();
var samSite = gameObject.GetComponent<SamSite>();
int assignedLevel = upgradeLevels[player.userID];
var buildingBlock = gameObject.GetComponent<BuildingBlock>();
var deployable = gameObject.GetComponent<Deployable>();
if (!deployable){
if (buildingBlock != null)
{
var targetGrade = (BuildingGrade.Enum)assignedLevel;
ulong skinsel = (ulong)skinSelected[player.userID];
buildingBlock.SetGrade(targetGrade);
buildingBlock.SetHealthToMax();
if (upgradeLevels[player.userID] == 2)
{
buildingBlock.ChangeGradeAndSkin(buildingBlock.grade, skinsel, true, true);
}
if (upgradeLevels[player.userID] == 3 && skinSelected[player.userID] > 0)
{
buildingBlock.playerCustomColourToApply = (uint)RandGenerator();
buildingBlock.ChangeGradeAndSkin(buildingBlock.grade, 10221, true, true);
}
if (playerStability[player.userID]){
if (!buildingBlock.grounded)
{
stablentites.Add(buildingBlock);
buildingBlock.grounded = true;
}
}
buildingBlock.UpdateSkin();
buildingBlock.SendNetworkUpdateImmediate();
}
}
if (playerAutomaticEntityEnable.ContainsKey(player.userID) && !playerAutomaticEntityEnable[player.userID])
return;
if (furnace != null && furnace.ShortPrefabName.Contains("furnace"))
{
timer.Once(0.1f, () =>
{
AddInfiniteFuel(furnace);
LightFurnace(furnace);
});
}
if (chineseLantern != null)
{
timer.Once(0.1f, () =>
{
AddFuelToChineseLantern(chineseLantern, 1000);
LightChineseLantern(chineseLantern);
});
}
if (turret != null)
{
timer.Once(0.1f, () =>
{
PowerTurret(turret);
AutoAuthorizePlayers(turret);
});
}
if (door != null && door.ShortPrefabName.Contains("wall.frame.garagedoor"))
{
timer.Once(0.1f, () =>
{
OpenGarageDoor(door);
});
}
if (searchlight != null)
{
timer.Once(0.1f, () =>
{
EnableSearchLight(searchlight);
AddSearchLight(searchlight, player);
});
}
if (samSite != null)
{
timer.Once(0.1f, () =>
{
EnableSamSite(samSite);
AddSamSite(samSite, player);
});
}
}
void EnableSearchLight(SearchLight searchlight)
{
searchlight.SetFlag(BaseEntity.Flags.On, true);
}
void EnableSamSite(SamSite samSite)
{
samSite.SetFlag(BaseEntity.Flags.On, true);
}
void AddSearchLight(SearchLight searchlight, BasePlayer player)
{
if (!deployedSearchLights.ContainsKey(player))
deployedSearchLights[player] = new HashSet<SearchLight>();
deployedSearchLights[player].Add(searchlight);
}
void AddSamSite(SamSite samSite, BasePlayer player)
{
if (!deployedSamSites.ContainsKey(player))
deployedSamSites[player] = new HashSet<SamSite>();
deployedSamSites[player].Add(samSite);
}
[ConsoleCommand("creative_runcmd")]
private void creative_runcmd(ConsoleSystem.Arg arg)
{
var args = arg.Args;
if (arg.Player() == null)
return;
var player = arg?.Player();
string chatcmd = args[0].ToString();
string replacedValues = chatcmd.Replace("{player.name}", $"{player.displayName}").Replace("{player.steam}", $"{player.userID}");
switch(replacedValues){
case "twig":
arg.Player().SendConsoleCommand($"chat.say \"/up 0\" ");
break;
case "wood":
arg.Player().SendConsoleCommand($"chat.say \"/up 1\" ");
break;
case "stone":
arg.Player().SendConsoleCommand($"chat.say \"/up 2\" ");
break;
case "frags":
arg.Player().SendConsoleCommand($"chat.say \"/up 3\" ");
break;
case "hqm":
arg.Player().SendConsoleCommand($"chat.say \"/up 4\" ");
break;
case "adobe":
arg.Player().SendConsoleCommand($"chat.say \"/up 5\" ");
break;
case "bricks":
arg.Player().SendConsoleCommand($"chat.say \"/up 6\" ");
break;
case "brutalist":
arg.Player().SendConsoleCommand($"chat.say \"/up 7\" ");
break;
case "ship":
arg.Player().SendConsoleCommand($"chat.say \"/up 8\" ");
break;
}
}
public class ImageURL { public string Name; public string Url; }
private readonly HashSet<string> _failedImages = new HashSet<string>();
private readonly Dictionary<string, string> _images = new Dictionary<string, string>();
private readonly HashSet<ImageURL> _urls = new HashSet<ImageURL>
{
new ImageURL { Name = "twig", Url = "Images/blank.png" },
new ImageURL { Name = "wood", Url = "Images/wood.png" },
new ImageURL { Name = "stone", Url = "Images/stones.png" },
new ImageURL { Name = "frags", Url = "Images/metal_fragments.png" },
new ImageURL { Name = "hqm", Url = "Images/metal_refined.png" },
new ImageURL { Name = "adobe", Url = "Images/stone_adobe_dlc.png" },
new ImageURL { Name = "bricks", Url = "Images/stone_brick_dls.png" },
new ImageURL { Name = "brutalist", Url = "Images/stones_brutalist_dlc.png" },
new ImageURL { Name = "ship", Url = "Images/ship.png" },
};
private void DownloadImage()
{
ImageURL image = _urls.FirstOrDefault(x => !_images.ContainsKey(x.Name) && !_failedImages.Contains(x.Name));
if (image != nul
// ... [Code preview truncated due to length. Full source in attached file] ...