private void GetTargetEntity(BasePlayer player) { bool flag = Physics.Raycast(player.eyes.HeadRay(), out raycastHit, 2f, Rust.Layers.Solid); if (!flag) { return; } BaseEntity entity; try { entity = raycastHit.GetEntity(); } catch (NullReferenceException nre) { return; } if (entity == null) { return; } MiniCopter mini = ((entity is MiniCopter) ? entity : entity.GetParentEntity()) as MiniCopter; if (mini != null) { PushMini(player, mini); return; } SendReply(player, GetMsg("Err - Can only push minicopter"), GetEnglishName(entity.ShortPrefabName)); }
void ToggleMiniLights(MiniCopter mini) { foreach (var light in mini.GetComponentsInChildren <SearchLight>()) { ToggleFLight(light); } }
object CanMountEntity(BasePlayer player, BaseMountable entity) { if (!(entity is MiniCopter) && !(entity.GetParentEntity() is MiniCopter)) { return(null); } if (player.serverInput.IsDown(BUTTON.FIRE_PRIMARY) || player.serverInput.WasDown(BUTTON.FIRE_PRIMARY)) { GetTargetEntity(player); return(false); } if (!IsBatEnabled()) { return(null); } MiniCopter ent = entity.GetParentEntity() as MiniCopter; if (ent != null) { IOEntity ioe = GetBatteryConnected(ent); if (ioe != null) { SendReply(player, GetMsg("Err - Diconnect Battery"), ioe.GetDisplayName()); return(false); } } return(null); }
private void OnEntitySpawned(BaseNetworkable networkable) { if (networkable == null || !(networkable is MiniCopter)) { return; } NextTick(() => { MiniCopter copter = networkable as MiniCopter; if (copter != null) { Item fuelItem = copter.GetFuelSystem().GetFuelItem(); if (fuelItem != null) { int wolfAmount = Mathf.FloorToInt((float)fuelItem.info.stackable * 0.2f); if (wolfAmount == fuelItem.amount) { if (copter.PrefabName.Contains("vehicles/scrap heli carrier/scraptransporthelicopter")) { fuelItem.amount = _config.fuelAmountScrapTransportHelicopter; } if (copter.PrefabName.Contains("vehicles/minicopter/minicopter.entity")) { fuelItem.amount = _config.fuelAmountMiniCopter; } } } } }); }
private void GiveMinicopter(BasePlayer player, Vector3 customPosition = default(Vector3), bool useCustomPosition = false) { if (FindPlayerMini(player) != null) { player.ChatMessage(lang.GetMessage("mini_current", this, player.UserIDString)); return; } var position = useCustomPosition ? customPosition : GetIdealFixedPositionForPlayer(player); var rotation = useCustomPosition ? Quaternion.identity : GetIdealRotationForPlayer(player); MiniCopter mini = GameManager.server.CreateEntity(_config.assetPrefab, position, rotation) as MiniCopter; if (mini == null) { return; } mini.OwnerID = player.userID; mini.Spawn(); _data.playerMini.Add(player.UserIDString, mini.net.ID); if (permission.UserHasPermission(player.UserIDString, _noFuel)) { EnableUnlimitedFuel(mini); } else { AddInitialFuel(mini, player.UserIDString); } }
private void NoMinicopter(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, _noMini)) { player.ChatMessage(lang.GetMessage("mini_perm", this, player.UserIDString)); return; } if (!_data.playerMini.ContainsKey(player.UserIDString)) { player.ChatMessage(lang.GetMessage("mini_notcurrent", this, player.UserIDString)); return; } MiniCopter mini = BaseNetworkable.serverEntities.Find(_data.playerMini[player.UserIDString]) as MiniCopter; if (mini == null) { return; } if (mini.AnyMounted() && (!_config.canDespawnWhileOccupied || player.GetMountedVehicle() == mini)) { player.ChatMessage(lang.GetMessage("mini_mounted", this, player.UserIDString)); return; } if (IsMiniBeyondMaxDistance(player, mini)) { player.ChatMessage(lang.GetMessage("mini_current_distance", this, player.UserIDString)); return; } BaseNetworkable.serverEntities.Find(_data.playerMini[player.UserIDString])?.Kill(); }
private bool SpawnMini() { Vector3 spawnpoint; int spawnAttempts = 0; int maxSpawnAttempts = (int)Config["MaxSpawnAttempts"]; do { spawnpoint = RandomWorldPosition(); spawnAttempts++; }while (!CanSpawnMini(spawnpoint) && spawnAttempts < maxSpawnAttempts); if (spawnAttempts == maxSpawnAttempts) { return(false); } Quaternion rotation = Quaternion.Euler(0, Random.Next(0, 360), 0); MiniCopter heli = GameManager.server.CreateEntity("assets/content/vehicles/minicopter/minicopter.entity.prefab", spawnpoint, rotation) as MiniCopter; if (heli == null) { return(false); } heli.Spawn(); return(true); }
void AddSearchLight(MiniCopter copter) { SphereEntity sph = (SphereEntity)GameManager.server.CreateEntity(spherePrefab, copter.transform.position, new Quaternion(0, 0, 0, 0), true); DestroyMeshCollider(sph); DestroyGroundComp(sph); sph.Spawn(); sph.SetParent(copter); sph.transform.localPosition = new Vector3(0, -100, 0); SearchLight searchLight = GameManager.server.CreateEntity(searchLightPrefab, sph.transform.position) as SearchLight; DestroyMeshCollider(searchLight); DestroyGroundComp(searchLight); searchLight.Spawn(); searchLight.GetComponent <StorageContainer>().isLootable = false; searchLight.SetFlag(BaseEntity.Flags.Reserved5, true, false, true); searchLight.SetParent(sph); searchLight.transform.localPosition = new Vector3(0, 0, 0); searchLight.transform.localRotation = Quaternion.Euler(new Vector3(20, 0, 180)); searchLight.transform.localRotation = Quaternion.Euler(new Vector3(20, 0, 0)); searchLight.transform.localRotation = Quaternion.Euler(new Vector3(20, 0, 180)); Puts(searchLight.eyePoint.transform.position.ToString()); searchLight._maxHealth = 99999999f; searchLight._health = 99999999f; searchLight.pickup.enabled = false; searchLight.isLockable = true; searchLight.SendNetworkUpdate(); sph.transform.localScale += new Vector3(0.9f, 0, 0); sph.LerpRadiusTo(0.1f, 10f); timer.Once(3f, () => { sph.transform.localPosition = new Vector3(0, 0.24f, 1.8f); }); sph.SendNetworkUpdateImmediate(); //PrintComponents(searchLight); }
void ToggleHover(BasePlayer player, MiniCopter minicopter) { if (!helicopterHovering.ContainsKey(minicopter.GetInstanceID())) { helicopterHovering.Add(minicopter.GetInstanceID(), false); } if (!helicopterFuelUseTime.ContainsKey(minicopter.GetInstanceID())) { helicopterFuelUseTime.Add(minicopter.GetInstanceID(), 0f); } if (!helicopterTimers.ContainsKey(minicopter.GetInstanceID())) { helicopterTimers.Add(minicopter.GetInstanceID(), null); } Rigidbody rb = minicopter.GetComponent <Rigidbody>(); if (rb == null) { PrintWarning(lang.GetMessage("RigidbodyNull", this, null)); PrintToChat(player, lang.GetMessage("ErrorFound", this, player.UserIDString)); return; } if (!helicopterHovering[minicopter.GetInstanceID()]) { helicopterHovering[minicopter.GetInstanceID()] = true; rb.constraints = RigidbodyConstraints.FreezePositionY; if (!_config.Hovering.enableRotationOnHover) { rb.freezeRotation = true; } PrintToChat(player, lang.GetMessage("HelicopterEnabled", this, player.UserIDString)); if (_config.Hovering.keepEngineOnHover) { MonoBehaviour monoBehaviour = minicopter.GetComponent <MonoBehaviour>(); monoBehaviour.StartCoroutine(WhileHovering(minicopter, rb)); } } else { helicopterHovering[minicopter.GetInstanceID()] = false; rb.constraints = RigidbodyConstraints.None; rb.freezeRotation = false; PrintToChat(player, lang.GetMessage("HelicopterDisabled", this, player.UserIDString)); } }
void AddSideStorageBoxes(MiniCopter copter) { AddStorageBox(copter, storagePrefab, new Vector3(0.6f, 0.24f, -0.35f)); if (!IsBatEnabled()) { AddStorageBox(copter, storagePrefab, new Vector3(-0.6f, 0.24f, -0.35f)); } }
void OnEntitySpawned(MiniCopter mini) { if (mini.name.Contains("trans")) { return; } mini.gameObject.AddComponent <MiniWeapons>(); }
private void EnableUnlimitedFuel(MiniCopter minicopter) { var fuelSystem = minicopter.GetFuelSystem(); fuelSystem.cachedHasFuel = true; fuelSystem.nextFuelCheckTime = float.MaxValue; fuelSystem.GetFuelContainer().SetFlag(BaseEntity.Flags.Locked, true); }
private void EnableUnlimitedFuel(MiniCopter minicopter) { minicopter.fuelPerSec = 0f; StorageContainer fuelContainer = minicopter.GetFuelSystem().GetFuelContainer(); fuelContainer.inventory.AddItem(fuelContainer.allowedItem, 1); fuelContainer.SetFlag(BaseEntity.Flags.Locked, true); }
void OnEntitySpawned(MiniCopter mini) { if (mini == null) { return; } mini.gameObject.AddComponent <MiniTrigger>(); }
private bool IsPlayerOwned(MiniCopter mini) { if (mini != null && _data.playerMini.ContainsValue(mini.net.ID)) { return(true); } return(false); }
private void SpawnMinicopter(string id) { // Use find incase they put their username BasePlayer player = BasePlayer.Find(id); if (player == null) { return; } if (_data.playerMini.ContainsKey(player.UserIDString)) { player.ChatMessage(lang.GetMessage("mini_current", this, player.UserIDString)); return; } // Credit Original MyMinicopter Plugin Quaternion rotation = player.GetNetworkRotation(); Vector3 forward = rotation * Vector3.forward; Vector3 straight = Vector3.Cross(Vector3.Cross(Vector3.up, forward), Vector3.up).normalized; Vector3 position = player.transform.position + straight * 5f; position.y = player.transform.position.y + 2f; if (position == null) { return; } BaseVehicle vehicleMini = (BaseVehicle)GameManager.server.CreateEntity(_config.assetPrefab, position, new Quaternion()); if (vehicleMini == null) { return; } vehicleMini.OwnerID = player.userID; vehicleMini.Spawn(); // End _data.playerMini.Add(player.UserIDString, vehicleMini.net.ID); if (permission.UserHasPermission(player.UserIDString, _noFuel)) { MiniCopter minicopter = vehicleMini as MiniCopter; if (minicopter == null) { return; } minicopter.fuelPerSec = 0f; StorageContainer fuelContainer = minicopter.GetFuelSystem().GetFuelContainer(); ItemManager.CreateByItemID(-946369541, 1)?.MoveToContainer(fuelContainer.inventory); fuelContainer.SetFlag(BaseEntity.Flags.Locked, true); } }
void AddFlightLigts(MiniCopter copter) { FlasherLight alight = GameManager.server.CreateEntity(flasherBluePrefab, copter.transform.position) as FlasherLight; alight.Spawn(); DestroyGroundComp(alight); ToggleLight(alight); alight.SetParent(copter); alight.transform.localPosition = new Vector3(0, 1.2f, -2.0f); alight.transform.localRotation = Quaternion.Euler(new Vector3(33, 180, 0)); alight.SendNetworkUpdateImmediate(); }
private void AddInitialFuel(MiniCopter minicopter) { if (_config.fuelAmount == 0) { return; } StorageContainer fuelContainer = minicopter.GetFuelSystem().GetFuelContainer(); int fuelAmount = _config.fuelAmount < 0 ? fuelContainer.allowedItem.stackable : _config.fuelAmount; fuelContainer.inventory.AddItem(fuelContainer.allowedItem, fuelAmount); }
object OnSamSiteTarget(SamSite samsite, MiniCopter target) { BasePlayer player = target.GetDriver(); BuildingPrivlidge priviledge = samsite.GetBuildingPrivilege(); if (player != null && permission.UserHasPermission(player.UserIDString, turretsIgnore) || (samsite.ShortPrefabName == "sam_site_turret_deployed" && _config.samSitesAffected || samsite.ShortPrefabName == "sam_static" && _config.staticSamSitesAffected) && (priviledge == null || priviledge != null && ((priviledge.IsAuthed(player) || (!priviledge.IsAuthed(player.userID) && !player.IsBuildingBlocked()))))) { return(false); } return(null); }
void AddLargeStorageBox(MiniCopter copter) { //sides,negative left | up and down | in and out if (config.storageLargeContainers == 1) { AddStorageBox(copter, storageLargePrefab, new Vector3(0.0f, 0.07f, -1.05f), Quaternion.Euler(0, 180f, 0)); } else if (config.storageLargeContainers >= 2) { AddStorageBox(copter, storageLargePrefab, new Vector3(-0.48f, 0.07f, -1.05f), Quaternion.Euler(0, 180f, 0)); AddStorageBox(copter, storageLargePrefab, new Vector3(0.48f, 0.07f, -1.05f), Quaternion.Euler(0, 180f, 0)); } }
////////////////////// ON KILL - chat owner ///////////////////// void OnEntityKill(BaseNetworkable entity) { if (entity == null) { return; } if (entity.net.ID == null) { return; } MiniCopter check = entity as MiniCopter; if (check == null) { return; } if (storedData.playerminiID == null) { return; } ulong todelete = new ulong(); if (storedData.playerminiID.ContainsValue(entity.net.ID) == false) { if (debug) { Puts($"KILLED MINICOPTER not from myMiniCopter plugin"); } return; } foreach (var item in storedData.playerminiID) { if (item.Value == entity.net.ID) { ChatPlayerOnline(item.Key, "killed"); foreach (BasePlayer player in BasePlayer.activePlayerList.ToList()) { if (player.userID == item.Key) { baseplayerminicop.Remove(player); } } todelete = item.Key; } } if (todelete != null) { storedData.playerminiID.Remove(todelete); } }
void StoreMiniCopterDefaults(MiniCopter copter) { if (copter.liftFraction == 0 || copter.torqueScale.x == 0 || copter.torqueScale.y == 0 || copter.torqueScale.z == 0) { copter.liftFraction = 0.25f; copter.torqueScale = new Vector3(400f, 400f, 200f); } Puts($"Defaults for copters saved as \nfuelPerSecond = {copter.fuelPerSec}\nliftFraction = {copter.liftFraction}\ntorqueScale = {copter.torqueScale}"); copterDefaults = new MiniCopterDefaults { fuelPerSecond = copter.fuelPerSec, liftFraction = copter.liftFraction, torqueScale = copter.torqueScale }; }
ElectricBattery AddBattery(MiniCopter copter) { ElectricBattery abat = GameManager.server.CreateEntity(batteryPrefab, copter.transform.position) as ElectricBattery; abat.maxOutput = 12; abat.Spawn(); DestroyGroundComp(abat); abat.pickup.enabled = false; abat.SetParent(copter); abat.transform.localPosition = new Vector3(-0.7f, 0.2f, -0.2f); abat.transform.localRotation = Quaternion.Euler(0, 0, 0); abat.SendNetworkUpdate(); return(abat); }
// On kill - tell owner void OnEntityKill(BaseNetworkable entity) { if (entity == null) { return; } if (entity.net.ID == null) { return; } MiniCopter check = entity as MiniCopter; if (check == null) { return; } if (storedData.playerminiID == null) { return; } ulong todelete = new ulong(); if (storedData.playerminiID.ContainsValue(entity.net.ID) == false) { if (debug) { Puts($"KILLED non-plugin minicopter"); } return; } foreach (var item in storedData.playerminiID) { if (item.Value == entity.net.ID) { ChatPlayerOnline(item.Key, "killed"); BasePlayer player = BasePlayer.FindByID(item.Key); if (player != null) { baseplayerminicop.Remove(player.userID); } todelete = item.Key; } } if (todelete != null) { storedData.playerminiID.Remove(todelete); SaveData(); } }
void OnEntityMounted(BaseMountable mount, BasePlayer player) { if (mount.GetParentEntity() != null) { if (mount.GetParentEntity().ShortPrefabName == "minicopter.entity" || mount.GetParentEntity().ShortPrefabName == "scraptransporthelicopter" && _config.Permission.scrapheliCanHover) { MiniCopter minicopter = mount.GetParentEntity() as MiniCopter; if (minicopter != null && permission.UserHasPermission(player.UserIDString, canHover)) { PrintToChat(player, lang.GetMessage("Mounted", this, player.UserIDString)); } } } }
// Spawn hook private void SpawnMyMinicopter(BasePlayer player) { if (player.IsBuildingBlocked() & !allowWhenBlocked) { PrintMsgL(player, "BlockedMsg"); return; } Vector3 position = player.transform.position + (player.transform.forward * 5); position.y = player.transform.position.y + 2f; if (position == null) { return; } BaseVehicle vehicleMini = (BaseVehicle)GameManager.server.CreateEntity(prefab, position, new Quaternion()); if (vehicleMini == null) { return; } BaseEntity miniEntity = vehicleMini as BaseEntity; MiniCopter miniCopter = vehicleMini as MiniCopter; miniEntity.OwnerID = player.userID; if (permission.UserHasPermission(player.UserIDString, MinicopterUnlimited)) { miniCopter.fuelPerSec = 0f; } vehicleMini.Spawn(); PrintMsgL(player, "SpawnedMsg"); uint minicopteruint = vehicleMini.net.ID; if (debug) { Puts($"SPAWNED MINICOPTER {minicopteruint.ToString()} for player {player.displayName} OWNER {miniEntity.OwnerID}"); } storedData.playerminiID.Remove(player.userID); storedData.playerminiID.Add(player.userID, minicopteruint); SaveData(); baseplayerminicop.Remove(player.userID); baseplayerminicop.Add(player.userID, vehicleMini); miniEntity = null; miniCopter = null; }
// On kill - tell owner void OnEntityKill(BaseNetworkable entity) { if (entity == null) { return; } if (entity.net.ID == 0) { return; } MiniCopter check = entity as MiniCopter; if (check == null) { return; } if (storedData.playerminiID == null) { return; } ulong todelete = new ulong(); if (storedData.playerminiID.ContainsValue(entity.net.ID) == false) { #if DEBUG Puts($"KILLED non-plugin minicopter"); #endif return; } foreach (var item in storedData.playerminiID) { if (item.Value == entity.net.ID) { ChatPlayerOnline(item.Key, "killed"); BasePlayer player = BasePlayer.FindByID(item.Key); todelete = item.Key; } } if (todelete != 0) { storedData.playerminiID.Remove(todelete); currentMounts.Remove(entity.net.ID); currentMounts.Remove(entity.net.ID + 1); currentMounts.Remove(entity.net.ID + 2); SaveData(); } }
void OnEntityDismounted(BaseMountable mount, BasePlayer player) { if (mount.GetParentEntity() != null) { if (_config.Hovering.disableHoverOnDismount && mount.GetParentEntity().ShortPrefabName == "minicopter.entity" || mount.GetParentEntity().ShortPrefabName == "scraptransporthelicopter" && _config.Permission.scrapheliCanHover) { MiniCopter minicopter = mount.GetParentEntity() as MiniCopter; if (minicopter != null && helicopterHovering.ContainsKey(minicopter.GetInstanceID())) { if (helicopterHovering[minicopter.GetInstanceID()] && mount.GetParentEntity() is MiniCopter && !minicopter.HasAnyPassengers() && minicopter != null) { helicopterHovering[minicopter.GetInstanceID()] = false; minicopter.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; minicopter.GetComponent <Rigidbody>().freezeRotation = false; } } else { if (minicopter == null) { PrintWarning(lang.GetMessage("HelicopterNull", this, null)); } else if (!helicopterHovering.ContainsKey(minicopter.GetInstanceID())) { return; } } } else if (!_config.Hovering.disableHoverOnDismount && mount.GetParentEntity().ShortPrefabName == "minicopter.entity" || mount.GetParentEntity().ShortPrefabName == "scraptransporthelicopter" && _config.Permission.scrapheliCanHover) { if (_config.Hovering.keepEngineOnHover) { MiniCopter minicopter = mount.GetParentEntity() as MiniCopter; if (minicopter != null && helicopterHovering.ContainsKey(minicopter.GetInstanceID())) { Rigidbody rb = minicopter.GetComponent <Rigidbody>(); minicopter.StartCoroutine(WhileHovering(minicopter, rb)); } } } } }
private void FetchMinicopter(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, _fetchMini)) { player.ChatMessage(lang.GetMessage("mini_perm", this, player.UserIDString)); return; } if (!_data.playerMini.ContainsKey(player.UserIDString)) { player.ChatMessage(lang.GetMessage("mini_notcurrent", this, player.UserIDString)); return; } MiniCopter mini = BaseNetworkable.serverEntities.Find(_data.playerMini[player.UserIDString]) as MiniCopter; if (mini == null) { return; } bool isMounted = mini.AnyMounted(); if (isMounted && (!_config.canFetchWhileOccupied || player.GetMountedVehicle() == mini)) { player.ChatMessage(lang.GetMessage("mini_mounted", this, player.UserIDString)); return; } if (IsMiniBeyondMaxDistance(player, mini)) { player.ChatMessage(lang.GetMessage("mini_current_distance", this, player.UserIDString)); return; } if (isMounted) { // mini.DismountAllPlayers() doesn't work so we have to enumerate the mount points foreach (var mountPoint in mini.mountPoints) { mountPoint.mountable?.DismountAllPlayers(); } } mini.transform.SetPositionAndRotation(GetIdealFixedPositionForPlayer(player), GetIdealRotationForPlayer(player)); }
void RestoreMiniCopter(MiniCopter copter, bool removeStorage = false) { copter.fuelPerSec = copterDefaults.fuelPerSecond; copter.liftFraction = copterDefaults.liftFraction; copter.torqueScale = copterDefaults.torqueScale; if (removeStorage) { foreach (var child in copter.children) { if (child.name == storagePrefab || child.name == storageLargePrefab || child.name == autoturretPrefab) { copter.RemoveChild(child); child.Kill(); } } } }