1. 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.
     
  2. BasePlayer.FindByID(ulong).ToBaseEntity() ?
     
  3. Wulf

    Wulf Community Admin

    A BaseEntity can be more than a player. I don't think ToBaseEntity() exists even?
     
  4. 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();
                    }
    
     
  5. Thanks for the replies, gents.
    Norn, your answer looks like what I was after. I'll try it out and let you know.

    :)
     
  6. 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).
     
  7. 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. :)
     
  8. You are correct - I just tested this out and the net IDs seem to be persisted across restarts.
     
  9. Ah that's great. Thanks for posting back. :)
     
  10. looping over the serverEntities to find one -> fail, sorry^^
    Code:
    BaseNetworkable.serverEntities.Find(uint netID)
     
  11. Even better. Thanks Nogrod! :)
     
  12. If only I knew that existed ;)
     
  13. This is working perfectly.
    Code:
                            target = keyvaluepair.Key;
                            targetEntity = BaseNetworkable.serverEntities.Find(target) as BaseEntity;
    Norn's variation worked fine too.
    Thanks again, fellas. :)
     
  14. Of course that works too, but that example loops through all entities on the server which could potentially be 200-300k which would take a lot longer than a simple dictionary lookup (example from Nogrod)
     
  15. 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.