_Q_ Posted October 13, 2015 Share Posted October 13, 2015 Is there a way I could print a list of all prefabs with invenotryitem component to the log file?Or I just need to go to the prefab folder and do it all manually. Link to comment Share on other sites More sharing options...
DarkXero Posted October 14, 2015 Share Posted October 14, 2015 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 endendworks once I filtered prefabs that didn't like existing more than once, or never. Link to comment Share on other sites More sharing options...
Maris Posted October 16, 2015 Share Posted October 16, 2015 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) Link to comment Share on other sites More sharing options...
Mobbstar Posted October 16, 2015 Share Posted October 16, 2015 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) Link to comment Share on other sites More sharing options...
Maris Posted October 16, 2015 Share Posted October 16, 2015 (edited) 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 October 16, 2015 by Maris Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now