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); }
Solved Getting the owner of a quarry?
Discussion in 'Rust Development' started by DylanSMR, Mar 9, 2016.
-
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); }
Code:private void OnQuarryGather(MiningQuarry quarry, Item item) { BasePlayer player = BasePlayer.FindSleeping(quarry.OwnerID); }
Last edited by a moderator: Mar 10, 2016 -
Ah thanks!
[DOUBLEPOST=1457569790][/DOUBLEPOST]Any way to search for both by chance? -
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 }
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 -
Oh I see, thanks again