Hi guys,
I've read a few threads about "BasePlayer.FindByID(ulong userId)",
and am looking for the same thing, but for BaseEntity. Does it exist?
For a little back story, I'm trying to keep a data file of certain Entities but now realise that's much more involved than I first thought. (Thread)
Thanks in advance.
Getting BaseEntity from ID?
Discussion in 'Rust Development' started by Steenamaroo, Mar 9, 2017.
-
BasePlayer.FindByID(ulong).ToBaseEntity() ?
-
Wulf Community Admin
-
Not sure if this is what you mean but from looking at older projects you can simply store the .net.ID and then do something like:
Code:foreach (BaseEntity entity in BaseNetworkable.serverEntities.Where(p => (p as BaseEntity).net.ID == StoredNetID).ToList()) { entity.Kill(); }
-
Thanks for the replies, gents.
Norn, your answer looks like what I was after. I'll try it out and let you know.
-
I was under the impression the net ID changes on server restart - so data may not be useful after a restart... You may want to test this; I could be wrong (it happened once back in '88).
-
Hey! I saw that suggested in a few threads.
I think the verdict was it's no longer an issue, but I'll confirm for myself.
Thank you for the info. -
You are correct - I just tested this out and the net IDs seem to be persisted across restarts.
-
Ah that's great. Thanks for posting back.
-
looping over the serverEntities to find one -> fail, sorry^^
Code:BaseNetworkable.serverEntities.Find(uint netID)
-
Even better. Thanks Nogrod!
-
-
This is working perfectly.
Code:target = keyvaluepair.Key; targetEntity = BaseNetworkable.serverEntities.Find(target) as BaseEntity;
Thanks again, fellas. -
-
Sorry, I don't follow.
I thought I was using Nogrod's method, although I had to add 'as BaseEntity' to please it.
[DOUBLEPOST=1489198618][/DOUBLEPOST]Oh, NM. I gotcha!
Thanks.