1. Code:
    void GetIntInFront(BasePlayer player)
        {
            RaycastHit hit;
            var propi;
            BasePlayer bplayer = player as BasePlayer;
            if (Physics.Raycast(bplayer.eyes.HeadRay(), 3))
            {
                propi = hit.GetEntity();
                Puts(propi.ShortPrefabName);
                return propi;
            }
        }
    Code:
    Error while compiling: ControlProp.cs(113,17): error CS0127: `Oxide.Plugins.ControlProp.GetIntInFront(BasePlayer)': A return keyword must not be followed by any expression when method returns void
     
  2. There's at least two issues with that code. Firstly, you're using void, that's not going to accept any return values. In your case, it looks like it should be BaseEntity GetIntInFront(BasePlayer player)

    Secondly, you're only returning a value if the raycast actually happens. You'll need return something after the if (incase the if is not met). Check code below:
    Code:
    BaseEntity GetIntInFront(BasePlayer player)
        {
            RaycastHit hit;
            var propi;
            BasePlayer bplayer = player as BasePlayer;
            if (Physics.Raycast(bplayer.eyes.HeadRay(), 3))
            {
                propi = hit.GetEntity();
                Puts(propi.ShortPrefabName);
                return propi;
            }
            return null;
        }
    
    EDIT: Also, the BasePlayer bplayer = player as BasePlayer is redundant and unneeded. player is already declared and is already a BasePlayer. ;)
     
  3. First of all, you can't declare a var without saing what you will save in it.
    It should be:
    var propi = new BaseEntity();
    or, BaseEntity propi;
    Other - @Shady757 said.

    PS. You raycast will not work, cause itdoesnot save RayHit in anything.
    Should work.
    Code:
    BaseEntity GetIntInFront(BasePlayer player)
    {
    RaycastHit hitinfo;
    if (Physics.Raycast(player.eyes.position, Quaternion.Euler(player.GetNetworkRotation()) * Vector3.forward, out hitinfo, 5f)
    {
        if (hitinfo.GetEntity() != null)
        {
            Puts(hitinfo.GetEntity().ShortPrefabName);
            return hitinfo.GetEntity();
        }
    }
    return null;
    }
    PSS. Actually, it will have troubles sometimes, as i think, you want to check is something in front of player (and you think about object), then you need to add Layer check, because maybe it will find trigger in front of you (if you are in building zone (or building trigger was removed in building 3.0?))
     
    Last edited by a moderator: Feb 4, 2018
  4. Wulf

    Wulf Community Admin

    You can’t use IPlayer just anywhere you want. Chat commands in a RustPlugin expect a BasePlayer.
     
  5. What parts do I need to fix?
     
  6. Change IPlayer to BasePlayer, it have ~same methods and fields.
    player.Reply -> player.ChatMessage
     
  7. Code:
    using System.Collections.Generic;
    using System.Linq;
    using Oxide.Core.Libraries.Covalence;
    using Oxide.Game.Rust.Cui;
    using UnityEngine;namespace Oxide.Plugins
    {
    [Info("ControlProp", "cookiecool", 0.1)]
    [Description("Allows you to control props to diguise your self or to hide.")]    class ControlProp : RustPlugin
    {        private Dictionary<BasePlayer, BaseEntity> props = new Dictionary<BasePlayer, BaseEntity>();
        string perm = "controlprop.use";
        #region Loaded
        void Loaded()
        {
            permission.RegisterPermission("controlprop.use", this);
            while (props.Count >= 1)
            {
                foreach (BasePlayer player in props.Keys)
                {
                    var basePlayer = player.Object as BasePlayer;
                    BaseEntity prop = props[player];
                    prop.transform.position = (new Vector3(basePlayer.transform.position.x, basePlayer.transform.position.y, basePlayer.transform.position.z));
                    prop.SendNetworkUpdate();
                }
            }
        }
        #endregion        #region EnterPropCommand
        [ChatCommand("enterprop")]
        private void EnterPropCommand(BasePlayer player, string command, string[] args)
        {            if (!player.HasPermission(perm))
            {
                player.ChatMessage("You do not have permission to this command!");
            }
            if (player.HasPermission(perm))
            {                if (props.ContainsKey(player))
                {
                    player.ChatMessage("You have to leave the current prop with /leaveprop before you can enter a new one");
                }
                else if ((!props.ContainsKey(player)))
                {
                    var propi = GetIntInFront(player);
                    if (propi == null)
                    {
                        player.ChatMessage("You have to be looking at a prop!");                    }
                    else if (!propi == null)
                    {
                        if (propi is BuildingBlock)
                        {
                            player.ChatMessage("You can not control building blocks!");
                        }
                        else if (!propi is BuildingBlock)
                        {
                            props.Add(player, propi);
                            player.ChatMessage("You are now controlling a prop.");
                        }                    }
                }
            }
        }
        #endregion        #region LeavePropCommand
        [ChatCommand("leaveprop")]
        private void LeavePropCommand(BasePlayer player, string command, string[] args)
        {
            if (!player.HasPermission("controlprop.use"))
            {
                player.ChatMessage("You do not have permission to this command!");
            } else if (player.HasPermission("controlprop.use"))
            {
                if (props.ContainsKey(player))
                {
                    player.ChatMessage("You have left the prop!");                    props.Remove(player);
                }
                else if ((!props.ContainsKey(player)))
                {
                    player.ChatMessage("You are currently not controlling a prop.");
                }
            }
        }
        #endregion        #region GetIntInfront
        BaseEntity GetIntInFront(BasePlayer player)
        {
            RaycastHit hit;
            BasePlayer bplayer = player as BasePlayer;
            if (Physics.Raycast(bplayer.eyes.HeadRay(), out hit, 3))
            {
                var propi = hit.GetEntity();
                Puts(propi.ShortPrefabName);
                return propi;
            }
            return null;
        }        #endregion        #region Unload
        private void Unload()
        {
            props.Clear();
        }
        #endregion    }
    }
    Code:
    Unable to load ControlProp. ControlProp.cs(88,31): error CS1061: Type `BasePlayer' does not contain a definition for `HasPermission' and no extension method `HasPermission' of type `BasePlayer' could be found. Are you missing an assembly reference?
     
  8. Wulf

    Wulf Community Admin

    Means you can’t use the HasPermission method with that variable because it doesn’t contain it. You would have to use the permission library helper in Oxide instead.
     
  9. How would I do that?
     
  10. if(permission.UserHasPermission(player.UserIDString, "name"))
     
  11. Code:
    using System.Collections.Generic;
    using System.Linq;
    using Oxide.Core.Libraries.Covalence;
    using Oxide.Game.Rust.Cui;
    using UnityEngine;namespace Oxide.Plugins
    {
    [Info("ControlProp", "cookiecool", 0.1)]
    [Description("Allows you to control props to diguise your self or to hide.")]    class ControlProp : RustPlugin
    {        private Dictionary<BasePlayer, BaseEntity> props = new Dictionary<BasePlayer, BaseEntity>();
        string perm = "controlprop.use";
        #region Loaded
        void Loaded()
        {
            permission.RegisterPermission("controlprop.use", this);
            while (props.Count >= 1)
            {
                foreach (BasePlayer player in props.Keys)
                {
                    var basePlayer = player.Object as BasePlayer;
                    BaseEntity prop = props[player];
                    prop.transform.position = (new Vector3(basePlayer.transform.position.x, basePlayer.transform.position.y, basePlayer.transform.position.z));
                    prop.SendNetworkUpdate();
                }
            }
        }
        #endregion        #region EnterPropCommand
        [ChatCommand("enterprop")]
        private void EnterPropCommand(BasePlayer player, string command, string[] args)
        {            if (!permission.UserHasPermission(player.UserIDString, perm))
            {
                player.ChatMessage("You do not have permission to this command!");
            }
            if (permission.UserHasPermission(player.UserIDString, perm))
            {                if (props.ContainsKey(player))
                {
                    player.ChatMessage("You have to leave the current prop with /leaveprop before you can enter a new one");
                }
                else if ((!props.ContainsKey(player)))
                {
                    var propi = GetIntInFront(player);
                    if (propi == null)
                    {
                        player.ChatMessage("You have to be looking at a prop!");                    }
                    else if (!propi == null)
                    {
                        if (propi is BuildingBlock)
                        {
                            player.ChatMessage("You can not control building blocks!");
                        }
                        else if (!propi is BuildingBlock)
                        {
                            props.Add(player, propi);
                            player.ChatMessage("You are now controlling a prop.");
                        }                    }
                }
            }
        }
        #endregion        #region LeavePropCommand
        [ChatCommand("leaveprop")]
        private void LeavePropCommand(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, perm))
            {
                player.ChatMessage("You do not have permission to this command!");
            } else if (permission.UserHasPermission(player.UserIDString, perm))
            {
                if (props.ContainsKey(player))
                {
                    player.ChatMessage("You have left the prop!");                    props.Remove(player);
                }
                else if ((!props.ContainsKey(player)))
                {
                    player.ChatMessage("You are currently not controlling a prop.");
                }
            }
        }
        #endregion        #region GetIntInfront
        BaseEntity GetIntInFront(BasePlayer player)
        {
            RaycastHit hit;
            BasePlayer bplayer = player as BasePlayer;
            if (Physics.Raycast(bplayer.eyes.HeadRay(), out hit, 3))
            {
                var propi = hit.GetEntity();
                Puts(propi.ShortPrefabName);
                return propi;
            }
            return null;
        }        #endregion        #region Unload
        private void Unload()
        {
            props.Clear();
        }
        #endregion    }
    }
    Code:
    Error while compiling: ControlProp.cs(28,45): error CS1061: Type `BasePlayer' does not contain a definition for `Object' and no extension method `Object' of type `BasePlayer' could be found. Are you missing an assembly reference?
     
  12. var basePlayer = player.Object as BasePlayer;
    For what you try to use it? What is it? :)
     
  13. So the leave command works and says you don't have permission or tells you that you aren't controlling a prop if they have permission. the enterprop command though doesn't telling you if its a building block or lets you enter a prop. But it does output the entity name to console.

    Code:
    using System.Collections.Generic;
    using System.Linq;
    using Oxide.Core.Libraries.Covalence;
    using Oxide.Game.Rust.Cui;
    using UnityEngine;namespace Oxide.Plugins
    {
    [Info("ControlProp", "cookiecool", 0.1)]
    [Description("Allows you to control props to diguise your self or to hide.")]    class ControlProp : RustPlugin
    {        private Dictionary<BasePlayer, BaseEntity> props = new Dictionary<BasePlayer, BaseEntity>();
        string perm = "controlprop.use";
        #region Loaded
        void Loaded()
        {
            permission.RegisterPermission("controlprop.use", this);
            while (props.Count >= 1)
            {
                foreach (BasePlayer player in props.Keys)
                {
                    BaseEntity prop = props[player];
                    prop.transform.position = (new Vector3(player.transform.position.x, player.transform.position.y, player.transform.position.z));
                    prop.SendNetworkUpdate();
                }
            }
        }
        #endregion        #region EnterPropCommand
        [ChatCommand("enterprop")]
        private void EnterPropCommand(BasePlayer player, string command, string[] args)
        {            if (!permission.UserHasPermission(player.UserIDString, perm))
            {
                player.ChatMessage("You do not have permission to this command!");
            }
            else if (permission.UserHasPermission(player.UserIDString, perm))
            {                if (props.ContainsKey(player))
                {
                    player.ChatMessage("You have to leave the current prop with /leaveprop before you can enter a new one");
                }
                else if (!props.ContainsKey(player))
                {
                    var propi = GetIntInFront(player);
                    if (propi == null)
                    {
                        player.ChatMessage("You have to be looking at a prop!");                    }
                    else if (!propi == null)
                    {
                        if (propi is BuildingBlock)
                        {
                            player.ChatMessage("You can not control building blocks!");
                        }
                        else if (!propi is BuildingBlock)
                        {
                            props.Add(player, propi);
                            player.ChatMessage("You are now controlling a prop.");
                        }                    }
                }
            }
        }
        #endregion        #region LeavePropCommand
        [ChatCommand("leaveprop")]
        private void LeavePropCommand(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, perm))
            {
                player.ChatMessage("You do not have permission to this command!");
            } else if (permission.UserHasPermission(player.UserIDString, perm))
            {
                if (props.ContainsKey(player))
                {
                    player.ChatMessage("You have left the prop!");                    props.Remove(player);
                }
                else if (!props.ContainsKey(player))
                {
                    player.ChatMessage("You are currently not controlling a prop.");
                }
            }
        }
        #endregion        #region GetIntInfront
        BaseEntity GetIntInFront(BasePlayer player)
        {
            RaycastHit hit;
            if (Physics.Raycast(player.eyes.HeadRay(), out hit, 3))
            {
                var propi = hit.GetEntity();
                Puts(propi.ShortPrefabName);
                return propi;
            }
            return null;
        }        #endregion        #region Unload
        private void Unload()
        {
            props.Clear();
        }
        #endregion    }
    }
     
  14. Wulf

    Wulf Community Admin

    You don’t have the permission then.
     
  15. I gave my self permission I know because the leave prop command said that I want in a prop which is should I have permission. But the enter prop didn't.
     
  16. Wulf

    Wulf Community Admin

    If you see the no permission message as you previously stated, then that is where the code is stopping, which would mean you don’t have the permission.

    Also, you don’t need to do multiple checks for each permission check in the command, either do a return or a else, not any else if. Same goes for the dictionary check.
     
  17. I see the no permission message but I don't see other messages

    fix no building message I had to chane if (!propi == nil) to if(prop != nil)
     
  18. Wulf

    Wulf Community Admin

    Yup, one of the many issues. :p
     
  19. When I type /enterprop on like a stone node or a hemp bush still doesn't work.