So I'm trying to make a dictionary with two values. 1st value the player and second value the prop the player is disguised as. How would I save both values in one line so It looks like "player, prop" So I would check if the dictionary ContainsKey(player) but if it returns true how do I get the prop as a value?
Solved Dictionary two values
Discussion in 'Rust Development' started by cookiecool, Feb 3, 2018.
-
If there were multiple dictionary things how would I get TValue from Tkey? Confused a bit.
-
Code:Dictionary<int, string> dictionary = new Dictionary<int, string>(); Type[] arguments = dictionary.GetType().GetGenericArguments(); Type keyType = arguments[0]; Type valueType = arguments[1];
-
I was looking in a plugins coding and this is how they did it would it be correct?
Code:var prop = props[player];
-
So I'm new to plugin creation and trying to create a plugin but I get this error and since I'm not very experienced I don't know what to do. Anyone got ideas on how to fix it??
Code
Code:namespace Oxide.Plugins { [Info("ControlProp", "cookiecool", 0.1)] [Description("Allows you to control props to diguise your self or to hide.")] private Dictionary<IPlayer, BaseEntity> props = new Dictionary<IPlayer, BaseEntity>(); class ControlProp : RustPlugin { string perm = "controlprop.use"; #region Loaded void Loaded() { permission.RegisterPermission("controlprop.use", this); while (props.Count >= 1) { foreach (IPlayer player in props.Keys) { var basePlayer = player.Object as BasePlayer; var prop = props[basePlayer] as BaseEntity; prop.transform.position = basePlayer.transform.position; } } }
Code:Error while compiling: ControlProp.cs(14,56): error CS1525: Unexpected symbol `Dictionary', expecting `class', `delegate', `enum', `interface', `partial', or `struct'
Last edited by a moderator: Feb 4, 2018 -
You need to share all the code, that's not enough to go off of. It looks like you declared your dictionary in the incorrect place.
-
Code:
namespace Oxide.Plugins { [Info("ControlProp", "cookiecool", 0.1)] [Description("Allows you to control props to diguise your self or to hide.")] private Dictionary<IPlayer, BaseEntity> props = new Dictionary<IPlayer, BaseEntity>(); class ControlProp : RustPlugin { string perm = "controlprop.use"; #region Loaded void Loaded() { permission.RegisterPermission("controlprop.use", this); while (props.Count >= 1) { foreach (IPlayer player in props.Keys) { var basePlayer = player.Object as BasePlayer; var prop = props[basePlayer] as BaseEntity; prop.transform.position = basePlayer.transform.position; } } }
-
Wulf Community Admin
-
- You shouldn't use a while loop, try a timer. Better yet, use a class inherited from MonoBehaviour and attach it to the entity.
- Your casts have no purpose, it's a RustPlugin, so you should be storing BasePlayers anyway, additionally, your dictionary is of IPlayers and BaseEntities, so that as BaseEntity is useless.
- Your perm field should be constant, so it's baked into the assembly when compiled.
- You should move that code to OnServerInitialized, that's when the server begins accepting connections.
-
oof now I got another error
Code:private void Unload() { var propList = props.Keys.ToList(); foreach (IPlayer player in props.Keys) { props.remove(player); } }
Code:Error while compiling: ControlProp.cs(115,23): error CS1061: Type `System.Collections.Generic.Dictionary<Oxide.Core.Libraries.Covalence.IPlayer,BaseEntity>' does not contain a definition for `remove' and no extension method `remove' of type `System.Collections.Generic.Dictionary<Oxide.Core.Libraries.Covalence.IPlayer,BaseEntity>' could be found. Are you missing an assembly reference?
-
Last edited by a moderator: Feb 4, 2018
-
same region now I'm getting
Code:Error while compiling: ControlProp.cs(112,34): error CS1955: The member `System.Collections.Generic.Dictionary<Oxide.Core.Libraries.Covalence.IPlayer,BaseEntity>.Keys' cannot be used as method or delegate
-
-
Here it is
Code:private void Unload() { var propList = props.Keys.ToList(); foreach (IPlayer player in props.Keys) { props.remove(player); } }
-
-
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
Last edited by a moderator: Feb 4, 2018 -
class NewClass {
public int Lol1;
public int Lol2;
}
private Dictionary<int, NewClass> lols = new Dictionary<int, newClass>();
foreach (var check in lols)
Puts(check.Lol1 + " " + check.Lol2);