hyiltiz Posted August 25, 2017 Share Posted August 25, 2017 Do c_gonext() find the prefab if it is in some inventory, say a backpack on a player or ground, chest on the ground, lureplant inventory etc.? I understand it doesn't look for entities in other shards so I should try it in each of them separately. Link to comment Share on other sites More sharing options...
ptr Posted August 26, 2017 Share Posted August 26, 2017 It will find them, but you can only goto a entity with a position. Link to comment Share on other sites More sharing options...
hyiltiz Posted August 26, 2017 Author Share Posted August 26, 2017 7 hours ago, ptr said: It will find them, but you can only goto a entity with a position. What entities do not have a position? Anything in inventories? Link to comment Share on other sites More sharing options...
ptr Posted August 26, 2017 Share Posted August 26, 2017 Well, those entitiesin inventory don't have own positions, but they share the position with the owner, which is called 'local' in the code. Those entities which REALLY don't have positions are special entities like network things. If you want to find entities in a mod, you can do a for loop on 'Ents', which is a global variable, and find what you want with v.prefab. Link to comment Share on other sites More sharing options...
hyiltiz Posted August 28, 2017 Author Share Posted August 28, 2017 Ah, ok! Is there a documentation of the API of the game, such as all the global variables and helper functions? I did dig into the lua scripts enough to navigate my ways around, but not enough to reason about it without looking at those scripts. Link to comment Share on other sites More sharing options...
ptr Posted August 28, 2017 Share Posted August 28, 2017 Sadly, no. You can find some useful functions about entities in simutil.lua, and special functions used for mods in modutil.lua. The consolecommands.lua can give you some hints on how cheating commands like c_godmode() work. But if you want to want to write a mod, it will be helpful to begin from reading the code in similar mods. Then you can see what functions they have used and look up for their sourse code by searching the entire 'scripts' folder. Link to comment Share on other sites More sharing options...
Lumina Posted August 28, 2017 Share Posted August 28, 2017 There are some example in the API here : But not a lot and some could be outdated. Link to comment Share on other sites More sharing options...
hyiltiz Posted October 9, 2017 Author Share Posted October 9, 2017 Welp, then we could just hack our way in ./scripts. Link to comment Share on other sites More sharing options...
DarkXero Posted October 11, 2017 Share Posted October 11, 2017 You can c_gonext to items in dropped backpacks. Items in players' inventories are off the charts using FindEntities. You can loop through the global Ents table though (example for axe, and you being the player 1): for k, v in pairs(Ents) do if v.prefab == "axe" then UserToPlayer(1).Transform:SetPosition(v:GetPosition():Get()) end end Link to comment Share on other sites More sharing options...
cezarica Posted October 11, 2017 Share Posted October 11, 2017 And what if I want to see only the stuff that isn't part of some inventory, be it player inventory, his backpack, lureplant, chest, and so on? Link to comment Share on other sites More sharing options...
ptr Posted October 11, 2017 Share Posted October 11, 2017 5 hours ago, cezarica said: And what if I want to see only the stuff that isn't part of some inventory, be it player inventory, his backpack, lureplant, chest, and so on? check inst.components.inventoryitem==nil or inst.components.inventoryitem.owner==nil ? Link to comment Share on other sites More sharing options...
cezarica Posted October 11, 2017 Share Posted October 11, 2017 With == nil doesn't seem to be working but dose with ~= nil. local items = { spoiled_food = true, twigs = true, cutgrass = true, boneshard = true } for _,v in pairs(Ents) do if items[v.prefab] then if v.components.inventoryitem ~= nil and v.components.inventoryitem.owner ~= nil then print(v.prefab) end end end This is the code I'm using and want to do something to clean the world of junk. Link to comment Share on other sites More sharing options...
ptr Posted October 11, 2017 Share Posted October 11, 2017 You want things inside inventory? Link to comment Share on other sites More sharing options...
cezarica Posted October 11, 2017 Share Posted October 11, 2017 (edited) I want to filter out and get a list of things that aren't part of any container, I mean that are on the ground. From here I want to get the amount of said prefab and eliminate them if are beyond a certain amount specified for each prefab in particular. From what I read on "Relational Operators" the ~= is exactly what i needed as it " Checks if the value of two operands are equal or not, if values are not equal then condition becomes true." In my case I want to check if v.components.inventoryitem is nil and v.components.inventoryitem.owner is nil as well. Now, how do I count them? Apart adding the prefabs I want in a local table and loop trough it and increment a number that is. Edited October 11, 2017 by cezarica Link to comment Share on other sites More sharing options...
ptr Posted October 11, 2017 Share Posted October 11, 2017 But in your code, "v.components.inventoryitem ~= nil" means it can be put into the inventory and "v.components.inventoryitem.owner ~= nil" means it is inside some container or inventory. Count with some increment directly in the Ents loop? I don't get your idea. Link to comment Share on other sites More sharing options...
cezarica Posted October 11, 2017 Share Posted October 11, 2017 By count I meant to see how many times a certain prefab exists in the world laying on the ground. For instance if there are more than let's say 10 rot I want to remove them all. Link to comment Share on other sites More sharing options...
ptr Posted October 11, 2017 Share Posted October 11, 2017 It will be better to store them in a local table, otherwise you still need to do another Ents loop after counting. And counting table elements does not require loop, simply #tablename. Link to comment Share on other sites More sharing options...
cezarica Posted October 11, 2017 Share Posted October 11, 2017 (edited) I tried with: local items = { spoiled_food = true } for k, v in pairs(Ents) do if items[v.prefab] then if v.components.inventoryitem ~= nil and v.components.inventoryitem.owner ~= nil then print(string.format("prefab: %s | count: %s", v.prefab, #v)) end end end or a condensed command to try in console: local items = { spoiled_food = true }; for k, v in pairs(Ents) do if items[v.prefab] then if v.components.inventoryitem ~= nil and v.components.inventoryitem.owner ~= nil then print(string.format("prefab: %s | count: %s", v.prefab, #v)); end; end; end; and the result is: [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 [05:47:49]: prefab: spoiled_food | count: 0 What I'm missing? Is there a way to tell if there's a stack or just one? Edit: Decided to run a little experiment with v:GetPosition():Get() and results are: [05:52:23]: prefab: spoiled_food | pos: 494 [05:52:23]: prefab: spoiled_food | pos: 494 [05:52:23]: prefab: spoiled_food | pos: 494 [05:52:23]: prefab: spoiled_food | pos: 494 [05:52:23]: prefab: spoiled_food | pos: 494 [05:52:23]: prefab: spoiled_food | pos: 494 [05:52:23]: prefab: spoiled_food | pos: 494 [05:52:23]: prefab: spoiled_food | pos: 819 [05:52:23]: prefab: spoiled_food | pos: 819 [05:52:23]: prefab: spoiled_food | pos: 819 [05:52:23]: prefab: spoiled_food | pos: 819 [05:52:23]: prefab: spoiled_food | pos: 819 [05:52:23]: prefab: spoiled_food | pos: 819 [05:52:23]: prefab: spoiled_food | pos: 800 [05:52:23]: prefab: spoiled_food | pos: 800 [05:52:23]: prefab: spoiled_food | pos: 800 [05:52:23]: prefab: spoiled_food | pos: 800 [05:52:23]: prefab: spoiled_food | pos: 800 Dose this mean that basically i got just 3 stacks somewhere? Sounds a bit impossible to say the least... I use Point(v.Transform:GetWorldPosition()) to get the exact X, Y and Z coordinates of portal in one of my custom commands but can't get it to work in here for some reason. :S Edited October 11, 2017 by cezarica Link to comment Share on other sites More sharing options...
ptr Posted October 11, 2017 Share Posted October 11, 2017 There will be only one prefab if they are stacked. You can check prefab.components.stackable.stacksize for number. BTW, I still don't get the idea of your code local items = {} for _, v in pairs(Ents) do if v.prefab and (v.components.inventoryitem == nil or v.components.inventoryitem.owner == nil) then if not items[v.prefab] then items[v.prefab]={} end table.insert(items[v.prefab],v) end end for k, v in pairs(items) do print(string.format("prefab: %s | count: %s", k, #v)) end Link to comment Share on other sites More sharing options...
cezarica Posted October 11, 2017 Share Posted October 11, 2017 Using the prefab.components.stackable.stacksize seems to do the trick as I wanted. [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 16 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 40 [08:07:01]: prefab: spoiled_food | count: 30 Needs more testing I guess. Link to comment Share on other sites More sharing options...
cezarica Posted October 12, 2017 Share Posted October 12, 2017 The v.components.inventoryitem == nil or v.components.inventoryitem.owner == nil seems to do what I wanted. Thanks a lot ptr. Link to comment Share on other sites More sharing options...
Boogiepop210 Posted September 7, 2022 Share Posted September 7, 2022 On 10/10/2017 at 7:02 PM, DarkXero said: Items in players' inventories are off the charts using FindEntities. Last time I checked they can replace prefab command replaces prefabs even in inventories. I prob should fix that. 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