1. Hello!

    I'm brand new to Plugin development for Rust, so go easy on me :) I seem to be missing a couple of things, and I was hoping someone could clarify them for me.

    First of all I am doing everything in C#, I understand how to use the hooks but I am trying to do a couple things outside of the hooks.

    First question I have is, is there an Object or Object Manager that will allow me to get a list of say all of the Entities, players, buildings, high walls, etc?

    What I am trying to do is get a List of all High Stone Wall Entities/Game Object.

    I've been looking at Component.FindObjectsOfType and FindObjectsOfType, but I'm sure there is a better way.

    Thanks!
     
  2. Code:
     [ChatCommand("highwalls")]
            private void cmdHighWallCount(BasePlayer player, string command, string[] args)
            {
                if (!player.IsAdmin()) return;
                var count = 0;
               foreach(var wall in GameObject.FindObjectsOfType<SimpleBuildingBlock>())
                {
                    var name = wall?.LookupShortPrefabName() ?? string.Empty;
                    if (!name.Contains("high") && !name.Contains("stone")) continue; //can't remember exact shortname right now
                    count++;
                }
                SendReply(player, "There are " + count + " high external stone walls!");
            }
    Hopefully this example is enough to show you how/what you can do.
     
  3. Perfect! That looks like exactly what I was looking for!

    I will test it out tonight. If it works that gives me a good place to start when dealing with entities, etc.

    I really appreciate it!
     
  4. Worked perfectly ! Thanks
     
  5. Lets say I wanted to find all the human skulls on the map,
    I can't find an exact object type for skulls, so I assume Id have to loop through all Objects of type "Item"? and then check Item.info. for itemid or shortname matching?

    On a large server, will sifting through all the Items periodically use up a lot of server resources?
     
  6. Not if you do it correctly. Using FindObjectsOfType is slow no matter what, use it the least you can. You also can't use find objects of type on Item.

    Code:
    HashSet<Item> serverItems = new HashSet<Item>();
            bool init = false;
     void OnEntitySpawned(BaseNetworkable entity)
            {
                if (!init || entity == null) return;
                var item = entity?.GetComponent<Item>() ?? null;
                if (item != null) serverItems.Add(item);
            }        void OnServerInitialized()
            {
                var dropped = GameObject.FindObjectsOfType<DroppedItem>();
                var storage = GameObject.FindObjectsOfType<StorageContainer>();
                for(int i = 0; i < dropped.Length; i++)
                {
                    var item = dropped[i]?.item ?? null;
                    if (item == null) continue;
                    serverItems.Add(item);
                }
                for(int i = 0; i < storage.Length; i++)
                {
                    var container = storage[i]?.inventory?.itemList ?? null;
                    for (int j = 0; j < container.Count; j++) serverItems.Add(container[j]);
                }
                for(int i = 0; i < BasePlayer.activePlayerList.Count; i++)
                {
                    var player = BasePlayer.activePlayerList[i];
                    var items = player?.inventory?.AllItems() ?? null;
                    if (items != null && items.Length > 0) for (int j = 0; j < items.Length; j++) serverItems.Add(items[j]);
                }
                for (int i = 0; i < BasePlayer.sleepingPlayerList.Count; i++)
                {
                    var player = BasePlayer.sleepingPlayerList[i];
                    var items = player?.inventory?.AllItems() ?? null;
                    if (items != null && items.Length > 0) for (int j = 0; j < items.Length; j++) serverItems.Add(items[j]);
                }
                init = true;
    }
    
    As you can see, this just goes through (I believe) all containers where items are held and adds them to the hashset. It should also add any newly spawned items, though I haven't actually tested that part. Hopefully this is enough to at the very least give you an idea of how to do it well. The code isn't the cleanest, but that part's up to you. ;)