public bool AttemptToHitch(RidableHorse horse, HitchSpot hitch = null) { if (horse == null) { return(false); } if (hitch == null) { hitch = GetClosest(horse.transform.position); } if (hitch != null) { object obj = Interface.CallHook("OnHorseHitch", horse, hitch); if (obj is bool) { return((bool)obj); } hitch.SetOccupiedBy(horse); horse.SetHitch(this); horse.transform.SetPositionAndRotation(hitch.spot.position, hitch.spot.rotation); horse.DismountAllPlayers(); return(true); } return(false); }
private object OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo) { if (entity == null) { return(null); } if (entity is RidableHorse) { if (horses.ContainsKey(entity.net.ID)) { if (configData.Options.debug) { Puts($"Horse: {entity.net.ID} owned by {entity.OwnerID} is being attacked!"); } if (configData.Options.AlertWhenAttacked) { RidableHorse horse = entity as RidableHorse; if (horse.mountPoints[0].mountable.GetMounted() == null) { InputMessage message = new InputMessage() { buttons = 64 }; horse.RiderInput(new InputState() { current = message }, null); } } } } return(null); }
public void UnhitchAll() { HitchSpot[] array = hitchSpots; for (int i = 0; i < array.Length; i++) { RidableHorse horse = array[i].GetHorse(); if ((bool)horse) { Unhitch(horse); } } }
private object OnRidableAnimalClaim(RidableHorse horse, BasePlayer player) { if (!horse.IsForSale() || !HasPermissionAny(player.UserIDString, Permission_Free_All, Permission_Free_RidableHorse)) { return(null); } horse.SetFlag(BaseEntity.Flags.Reserved2, false); horse.AttemptMount(player, doMountChecks: false); Interface.CallHook("OnRidableAnimalClaimed", horse, player); return(false); }
private void OnEntityDeath(RidableHorse entity, HitInfo info) { if (entity == null || !config.EnableStorage) { return; } var box = entity.GetComponent <AddStorageBox>()?.box as StorageContainer; if (box != null) { box.DropItems(); } }
private void cmdStats(BasePlayer player, string command, string[] args) { RidableHorse entity = player.GetMounted().GetParentEntity() as RidableHorse; if (entity == null) { _instance.Puts($"entity is null"); return; } foreach (var s in entity.mountPoints) { _instance.Puts($"pos: {s.pos}\n {s.bone}\n {s.mountable}\n IsMounted:{s.mountable.IsMounted()}\n {s.prefab}"); } _instance.Puts($"IsMounted[0]:{entity.mountPoints[0].mountable.IsMounted()}\n IsMounted[1]:{entity.mountPoints[1].mountable.IsMounted()}"); // _instance.Puts($"HasMountPoints: {entity.HasMountPoints()}"); }
public void Unhitch(RidableHorse horse) { HitchSpot[] array = hitchSpots; foreach (HitchSpot hitchSpot in array) { if (hitchSpot.GetHorse(base.isServer) == horse) { if (Interface.CallHook("OnHorseUnhitch", horse, hitchSpot) != null) { break; } hitchSpot.SetOccupiedBy(null); horse.SetHitch(null); } } }
private void OnEntitySpawned(RidableHorse entity) { if (entity == null || !config.EnableStorage) { return; } NextTick(() => { foreach (StorageContainer child in entity.GetComponentsInChildren <StorageContainer>(true)) { if (child.name == "assets/prefabs/deployable/small stash/small_stash_deployed.prefab") { return; } } entity.gameObject.AddComponent <AddStorageBox>(); }); }
void Awake() { entity = GetComponent <RidableHorse>(); if (entity == null) { Destroy(this); return; } box = GameManager.server.CreateEntity("assets/prefabs/deployable/small stash/small_stash_deployed.prefab", entity.transform.position) as StorageContainer; if (box == null) { return; } box.Spawn(); box.SetParent(entity); box.transform.localPosition = new Vector3(0.4f, 1f, -0.4f); box.transform.Rotate(new Vector3(90.0f, 90.0f, 0.0f)); box.SendNetworkUpdateImmediate(true); }
private object CanMountEntity(BasePlayer player, RidableHorse mountable) { if (!configData.Options.RestrictMounting) { return(null); } if (player == null) { return(null); } RidableHorse horse = mountable.GetComponentInParent <RidableHorse>(); if (horse != null) { if (configData.Options.debug) { Puts($"Player {player.userID.ToString()} wants to mount horse {mountable.net.ID.ToString()}"); } if (horses.ContainsKey(mountable.net.ID)) { if (horse.OwnerID == player.userID || IsFriend(player.userID, horse.OwnerID)) { if (configData.Options.debug) { Puts("Mounting allowed."); } return(null); } Message(player.IPlayer, "horseowned"); if (configData.Options.debug) { Puts("Mounting blocked."); } return(true); } } return(null); }
private RidableHorse GetClosestHorse(HitchTrough hitchTrough, BasePlayer player) { var closestDistance = 1000f; RidableHorse closestHorse = null; for (var i = 0; i < hitchTrough.hitchSpots.Length; i++) { var hitchSpot = hitchTrough.hitchSpots[i]; if (!hitchSpot.IsOccupied()) { continue; } var distance = Vector3.Distance(player.transform.position, hitchSpot.spot.position); if (distance < closestDistance) { closestDistance = distance; closestHorse = hitchSpot.horse.Get(serverside: true) as RidableHorse; } } return(closestHorse); }
public void SetOccupiedBy(RidableHorse newHorse) { horse.Set(newHorse); }
private void HandleTimer(ulong horseid, ulong userid, bool start = false) { if (htimer.ContainsKey(horseid)) { if (start) { htimer[horseid].timer = timer.Once(htimer[horseid].countdown, () => HandleTimer(horseid, userid, false)); if (configData.Options.debug) { Puts($"Started release timer for horse {horseid.ToString()} owned by {userid.ToString()}"); } } else { if (htimer.ContainsKey(horseid)) { htimer[horseid].timer.Destroy(); htimer.Remove(horseid); } try { BaseNetworkable horse = BaseNetworkable.serverEntities.Find((uint)horseid); BasePlayer player = RustCore.FindPlayerByIdString(userid.ToString()); RidableHorse mounted = player.GetMounted().GetComponentInParent <RidableHorse>(); if (mounted.net.ID == horseid && configData.Options.ReleaseOwnerOnHorse) { // Player is on this horse and we allow ownership to be removed while on the horse mounted.OwnerID = 0; horses.Remove(horseid); if (configData.Options.debug) { Puts($"Released horse {horseid.ToString()} owned by {userid.ToString()}"); } } else if (mounted.net.ID == horseid && !configData.Options.ReleaseOwnerOnHorse) { // Player is on this horse and we DO NOT allow ownership to be removed while on the horse // Reset the timer... htimer.Add(horseid, new HTimer() { start = Time.realtimeSinceStartup, countdown = configData.Options.ReleaseTime, userid = userid }); htimer[horseid].timer = timer.Once(configData.Options.ReleaseTime, () => HandleTimer(horseid, userid)); if (configData.Options.debug) { Puts($"Reset ownership timer for horse {horseid.ToString()} owned by {userid.ToString()}"); } } else { // Player is NOT mounted on this horse... BaseEntity bhorse = horse as BaseEntity; bhorse.OwnerID = 0; horses.Remove(horseid); if (configData.Options.debug) { Puts($"Released horse {horseid.ToString()} owned by {userid}"); } } SaveData(); } catch { BaseNetworkable horse = BaseNetworkable.serverEntities.Find((uint)horseid); BaseEntity bhorse = horse as BaseEntity; bhorse.OwnerID = 0; horses.Remove(horseid); SaveData(); if (configData.Options.debug) { Puts($"Released horse {horseid.ToString()} owned by {userid}"); } } } } }
private void OnEntityMounted(BaseMountable mountable, BasePlayer player) { if (player == null) { return; } if (mountable == null) { return; } if (!configData.Options.SetOwnerOnFirstMount) { return; } RidableHorse horse = mountable.GetComponentInParent <RidableHorse>(); if (horse != null) { ulong userid = player.userID; if (IsAtLimit(userid)) { if (permission.UserHasPermission(userid.ToString(), permVIP)) { Message(player.IPlayer, "horselimit", configData.Options.VIPLimit); } else { Message(player.IPlayer, "horselimit", configData.Options.Limit); } return; } if (!horses.ContainsKey(mountable.net.ID)) { horse.OwnerID = player.userID; ulong horseid = horse.net.ID; horses.Remove(horseid); horses.Add(horseid, player.userID); SaveData(); if (configData.Options.EnableTimer) { htimer.Add(horseid, new HTimer() { start = Time.realtimeSinceStartup, countdown = configData.Options.ReleaseTime, userid = player.userID }); HandleTimer(horseid, player.userID, true); } Message(player.IPlayer, "horseclaimed"); if (configData.Options.debug) { Puts($"Player {player.userID.ToString()} mounted horse {mountable.net.ID.ToString()} and now owns it."); } } else if (horse.OwnerID == userid) { Message(player.IPlayer, "yourhorse"); } else { Message(player.IPlayer, "horseowned"); } } }
private void OnRidableAnimalClaimed(RidableHorse horse, BasePlayer player) => SetOwnerIfPermission(horse, player);