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
Some errors and issues with some code
Discussion in 'Rust Development' started by cookiecool, Feb 4, 2018.
-
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; }
-
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; }
Last edited by a moderator: Feb 4, 2018 -
K thx
-
Wulf Community Admin
-
-
Change IPlayer to BasePlayer, it have ~same methods and fields.
player.Reply -> player.ChatMessage -
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?
-
Wulf Community Admin
-
-
if(permission.UserHasPermission(player.UserIDString, "name"))
-
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?
-
var basePlayer = player.Object as BasePlayer;
For what you try to use it? What is it? -
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 } }
-
Wulf Community Admin
You don’t have the permission then.
-
-
Wulf Community Admin
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. -
fix no building message I had to chane if (!propi == nil) to if(prop != nil) -
Wulf Community Admin
-