Jump to content

Recommended Posts

local assertive = {	world = true, cave = true, forest = true, shard_network = true, world_network = true, forest_network = true, cave_network = true,	maxwellthrone = true,} -- These can only exist once, and the throne needs a profileprint("Prefabs with inventoryitem")for k, v in pairs(Prefabs) do	if not assertive[k] then		local inst = Prefabs[k] and Prefabs[k].fn and SpawnPrefab(k) -- backpack skins have no fn		if inst and inst.components and inst.components.inventoryitem then			print(inst.prefab)			inst:Remove()		end	endend

works once I filtered prefabs that didn't like existing more than once, or never.

 

local all_inventoryitem_objects = {}AddComponentPostInit("inventoryitem",function(self)	table.insert(all_inventoryitem_objects, self.inst)end)GLOBAL.rawset(GLOBAL,"print_all",function()	for i,v in ipairs(all_inventoryitem_objects) do		if v:IsValid() then			print(tostring(v))		end	endend)

local all_inventoryitem_objects = {}AddComponentPostInit("inventoryitem",function(self)	table.insert(all_inventoryitem_objects, self.inst)end)GLOBAL.rawset(GLOBAL,"print_all",function()	for i,v in ipairs(all_inventoryitem_objects) do		if v:IsValid() then			print(tostring(v))		end	endend)

 

 

Though I recommend to use the prefab names as keys and true as a dummy value. Not only does this cut the annoying GUID away, but also it prevents duplicates (which will happen a lot otherwise)

Though I recommend to use the prefab names as keys and true as a dummy value. Not only does this cut the annoying GUID away, but also it prevents duplicates (which will happen a lot otherwise)

it depends on what you need - all objects or just prefab names.

(I'm not sure why someone need prefab names in existing active world, because AddPrefabPostInit already does not work at that momet).

 

And yes, this is dirty code, but this is only an example.

Edited by Maris

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...