I love this new hook, I'm just wondering how to determine the BasePlayer for the researcher from the ResearchTable class?
Solved Getting BasePlayer in OnItemResearchEnds
Discussion in 'Rust Development' started by Calytic, May 12, 2015.
-
Calytic Community Admin Community Mod
-
Ex c#:
Code:using System.Reflection;static FieldInfo userfield = typeof(ResearchTable).GetField("user", (BindingFlags.Instance | BindingFlags.NonPublic));;void SomeFunc(ResearchTable table) { BasePlayer player = userfield.GetValue(table) as BasePlayer; }
-
Calytic Community Admin Community Mod
Reflection is great! How do I do this in JS? =P
Something like..
Code:SomeFunc: function(table) { var userfield = table.GetType().GetField("user", (global.System.Reflection.BindingFlags.Instance | global.System.Reflection.BindingFlags.NonPublic)); var player = userfield.GetValue(table); }
[DOUBLEPOST=1431466442][/DOUBLEPOST]I'm having the same problem of accessing private properties on 2 other issues I have logged. Knowing how to read AND mutate private properties from JS is sorely needed otherwise I'll have to rewrite everything in C#. -
Idk how to do it in JS (never tried), but u can try to use 'rust.PrivateBindingFlag()' instead of '(global.System.Reflection.BindingFlags.Instance | global.System.Reflection.BindingFlags.NonPublic)'.
-
Don't have any server files with me but I thought when I tested the hooks when I added them that I didn't use Reflection to get the player who was doing it. I'll have a look tonight and get back to you.
-
Calytic Community Admin Community Mod
Code:SomeFunc: function(table) { var userfield = table.GetType().GetField("user", rust.PrivateBindingFlag()); var player = userfield.GetValue(table); }