1. if it possible to get baseplayer who use table on c#
    From this method
    OnItemResearchEnd
    Code:
    void OnItemResearchEnd(ResearchTable table, float chance)
    {
        Puts("OnItemResearchEnd works!");
        return chance;
    }
     
  2. Were you able to solve it since your post is marked as "Solved"?

    If yes, could you tell me how?
     
  3. Wulf

    Wulf Community Admin

    As far as I know, table.user.
     
  4. Private field?
     
  5. Wulf

    Wulf Community Admin

    "table" is what you pass in via OnItemResearchEnd. If you look in a decompiler, you can see that table.user would be the BasePlayer.
     
  6. I mean that user is private field. We can't get this from outside.
     
  7. Wulf

    Wulf Community Admin

    Try "table.inventory.playerOwner" and see if that works.
     
  8. Returns nothing from .playerOwner. So, I think getting BasePlayer in this hook is not possible for now.
     
  9. Wulf

    Wulf Community Admin

    I'm sure there is a way.
     
  10. You can access private fields via reflection. I'm at work right now so I don't have a working example, but check LimeBench, I use reflection in it to access buildingprivs for the player. That field might be null all the time though, not the first time I would see a named variable in this code that has no use.

    Another way, assuming the research table functions as a Container, is to loop through active players and find which one is looting the table in question. I don't remember the name of the property or function but you can obtain the currently open container for a player. If the container == the tables container then you know you caught your fish. I use this in MoegicBox and possibly Salvager, check these out.
     
  11. Quick example:
    Code:
    void OnItemResearchEnd(ResearchTable table, float chance) {
        var userField = typeof(ResearchTable).GetField("user", (BindingFlags.Instance | BindingFlags.NonPublic));
        var player = userField.GetValue(table) as BasePlayer;
    }
    
     
  12. i find table position and close player position
     
  13. not reliable.. you could have 3 guys standing next to it, which are you going to chose?
    [DOUBLEPOST=1444885242][/DOUBLEPOST]
    Code:
            private static BasePlayer GetPlayerFromContainer(ItemContainer container, Item item) => item.GetOwnerPlayer() ??
                                BasePlayer.activePlayerList.FirstOrDefault(p => p.inventory.loot.IsLooting() && p.inventory.loot.entitySource == container.entityOwner);
    
     
  14. As Deicide666ra explained before, and Chilli posted a snippet, the reliable way to do this is by getting the value of the private user field through reflection. Here is another example on getting the player and some more info:
    Code:
    using System.Reflection;namespace Oxide.Plugins
    {
        [Info("Research Table Example", "Mughisi", 1.0)]
        class ResearchTableExample : RustPlugin
        {
            private FieldInfo user = typeof(ResearchTable).GetField("user", BindingFlags.NonPublic | BindingFlags.Instance);        void OnItemResearchEnd(ResearchTable table, float chance)
            {
                var player = user.GetValue(table) as BasePlayer;
                var status = chance < table.GetSuccessChance(table.GetResearchItem(), table.inventory.GetSlot(1));
                Puts($"{player.displayName} just finished researching {table.GetResearchItem().info.displayName.english} and {(status ? "succeeded" : "failed")}.");
            }
        }
    }
    The above example would output something like:
    "Mughisi just finished researching Silencer and failed."
    "Mughisi just finished researching Snow Jacked - Wood Camo and succeeded."