Hello!
I'm brand new to Plugin development for Rust, so go easy on meI 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!
Getting all entities of certain types?
Discussion in 'Rust Development' started by The FSM, Jun 2, 2016.
-
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!"); }
-
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! -
Worked perfectly ! Thanks
-
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? -
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; }