Exemple #1
0
 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);
 }
Exemple #2
0
 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);
 }
Exemple #3
0
 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);
        }
Exemple #5
0
        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()}");
        }
Exemple #7
0
 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);
         }
     }
 }
Exemple #8
0
        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>();
            });
        }
Exemple #9
0
            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);
            }
Exemple #10
0
        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);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
 public void SetOccupiedBy(RidableHorse newHorse)
 {
     horse.Set(newHorse);
 }
Exemple #13
0
        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}");
                        }
                    }
                }
            }
        }
Exemple #14
0
        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);