1. So im creating something and I ran into a bit of trouble. How do I find the owner of a quarry when it gathers | Code |
    Code:
            private void OnQuarryGather(MiningQuarry quarry, Item item)
            {
                item.amount = (item.amount * player.GetComponent<pGather>().GatherRate);
            }
     
  2. This should do the trick:
    This will only search for players which are on the server!
    Code:
    private void OnQuarryGather(MiningQuarry quarry, Item item)
    {
        BasePlayer player = BasePlayer.FindByID(quarry.OwnerID);
    }
    The following will only search for sleeping players:
    Code:
    private void OnQuarryGather(MiningQuarry quarry, Item item)
    {
        BasePlayer player = BasePlayer.FindSleeping(quarry.OwnerID);
    }
    There are some other functions with the purpose of finding a BasePlayer. Your best option is looking at the BasePlayer class inside the Assembly-CSharp.dll located in .../RustDedicated_Data/Managed with a decompiler like Telerik JustDecompiler free .NET decompiler.
     
    Last edited by a moderator: Mar 10, 2016
  3. Ah thanks!
    [DOUBLEPOST=1457569790][/DOUBLEPOST]Any way to search for both by chance?
     
  4. Keep in mind that OnQuarryGather(...) might be called quite often if multiple quarries are running on a server. Searching for the BasePlayer each time the hook is called might not be the best option. Consider caching (saving) the BasePlayer or whatever else you need inside your plugin the first time the OnQuarryGather(...) hook is called.

    Something like this:
    Code:
    Dictionary<ulong, BasePlayer> quarryOwners = new Dictionary<ulong, BasePlayer>();private void OnQuarryGather(MiningQuarry quarry, Item item)
    {
        BasePlayer player;
        if (!quarryOwners.TryGetValue(quarry.OwnerID, out player))
        {
            player = BasePlayer.FindByID(quarry.OwnerID) ?? BasePlayer.FindSleeping(quarry.OwnerID);
            quarryOwners[quarry.OwnerID] = player;
        }
        if (player == null) return;
        // do something
    }
    One more thing, though:
    I do not know whether the player will show up in one of the lists (active player list/sleeping player list) if he is logged off and dead so you might need to go down a different route entirely.
     
    Last edited by a moderator: Mar 10, 2016
  5. Oh I see, thanks again :D