Page 1 of 2
Is it possible to locate an item via console using item ID?
Posted: Mon Jul 10, 2023 8:14 am
by sapientCrow
As stated..
Is it at all possible to use a console command to locate where a specific item is and what level based on an item ID?
thanks for the help
Re: Is it possible to locate an item via console using item ID?
Posted: Mon Jul 10, 2023 9:49 am
by Isaac
It's possible if that item already exists (on the floor) in the dungeon; it won't work with items that come from scripts, but have not yet been spawned. It won't locate items inside surface containers, unless those containers are individually searched. You would first have to access the containers, then check every item inside each of them.
You could use a custom function in the console that iterates through every object found on each map level using allEntities(), and check them for an item component, and/or a surface component. Objects having surfaces would then have their contents searched for the item.
If you have the custom ID of the object then it's easier, but auto-generated instances are given numerical IDs, so they need component inspection to determine what they are.
Sacks and wooden boxes can be put into chests; if found in a surface, their contents must each be checked individually.
Re: Is it possible to locate an item via console using item ID?
Posted: Mon Jul 10, 2023 2:39 pm
by sapientCrow
thank you for the response
the goal is toe find an item if it is there that is which would be on the ground already in a certain level
so could I console something that said check this level for this ID?
Re: Is it possible to locate an item via console using item ID?
Posted: Mon Jul 10, 2023 5:59 pm
by Isaac
sapientCrow wrote: ↑Mon Jul 10, 2023 2:39 pm
...so could I console something that said check this level for this ID?
The answer is yes—if you are asking whether such a thing is possible to make (on your own) and use it in the console.
Here is the best resource for Grimrock 2 scripting:
https://github.com/JKos/log2doc/wiki
And here are the relevant object functions:
https://github.com/JKos/log2doc/wiki/Ob ... lasses#map
But if you are asking for an example, there is a dedicated Question & Answer thread for LoG2 scripting problems; this question has been answered a few times in it. The thread is a trove of esoteric solutions for just about anything imaginable within the engine.
http://www.grimrock.net/forum/viewtopic ... 50#p109544
Code: Select all
Dungeon.getMap([level number]):allEntities()
So... You can use the level number to search: Dungeon.getMap(1):allEntities()
or you can search whatever level the party is currently on: Dungeon.getMap(party.level):allEntities()
The allEntities() function returns either nil (nothing), or the first object found. To see any output from this you will need to print it to the console.
Re: Is it possible to locate an item via console using item ID?
Posted: Mon Jul 10, 2023 8:03 pm
by sapientCrow
thanks again very much
so I use
print (Dungeon.getMap(party.level):allEntities())
and the first line is just a function
can i push this out to a log file or text document with an entire list /array of the level I am on
total newbie in coding here so sorry for ignorance
Re: Is it possible to locate an item via console using item ID?
Posted: Mon Jul 10, 2023 8:13 pm
by Isaac
You can paste this into the console to locate the item with the id, "serpent_staff_1".
You can change the quoted id string to be the id that you wish to find.
Code: Select all
do
local_item_id = "serpent_staff_1"
for index = 1, Dungeon:getMaxLevels() do
for item in Dungeon.getMap(index):allEntities() do
if item.id == local_item_id then
hudPrint("A matching item was found in "..item.map:getName().." ".."(level "..item.level..") @ tile X:"..tostring(item.x)..",Y:"..tostring(item.y))
setMouseItem(item.item)
playSound("secret") party:spawn('blob')
return
end
end
end
hudPrint("No matching item was found")
end
Note: It is important to paste the whole thing, including the trailing spaces at the end of each line. Be sure to leave the space character at the end of the line when you change the id string.
Re: Is it possible to locate an item via console using item ID?
Posted: Mon Jul 10, 2023 9:27 pm
by sapientCrow
thanks I really appreciate you taking the time to make this
I am not able to get to ever return true though
like I spawn a tome of wisdom and change item Id to tome_wisdom and drop the tome on floor and it still returns no item found
Re: Is it possible to locate an item via console using item ID?
Posted: Mon Jul 10, 2023 9:40 pm
by Isaac
Try placing (not spawning) a serpent staff in the editor; test the preview to ensure that it's working as intended.
________________
I tested a blank map with a tome of wisdom, and the script located it.
Code: Select all
do
local_item_id = "tome_wisdom"
for index = 1, Dungeon:getMaxLevels() do
for item in Dungeon.getMap(index):allEntities() do
if item.id == local_item_id then
hudPrint("A matching item was found in "..item.map:getName().." ".."(level "..item.level..") @ tile X:"..tostring(item.x)..",Y:"..tostring(item.y))
setMouseItem(item.item)
playSound("secret") party:spawn('blob')
return
end
end
end
hudPrint("No matching item was found")
end
_______________
When you say, "spawn", do you mean in-game, or in-editor, and do you mean spawn via console command, or by placement (with mouse) in the editor?
Re: Is it possible to locate an item via console using item ID?
Posted: Mon Jul 10, 2023 9:59 pm
by sapientCrow
Isaac wrote: ↑Mon Jul 10, 2023 9:40 pm
Try placing (not spawning) a serpent staff in the editor; test the preview to ensure that it's working as intended.
________________
I tested a blank map with a tome of wisdom, and the script located it.
Code: Select all
do
local_item_id = "tome_wisdom"
for index = 1, Dungeon:getMaxLevels() do
for item in Dungeon.getMap(index):allEntities() do
if item.id == local_item_id then
hudPrint("A matching item was found in "..item.map:getName().." ".."(level "..item.level..") @ tile X:"..tostring(item.x)..",Y:"..tostring(item.y))
setMouseItem(item.item)
playSound("secret") party:spawn('blob')
return
end
end
end
hudPrint("No matching item was found")
end
_______________
When you say, "spawn", do you mean in-game, or in-editor, and do you mean spawn via console command, or by placement (with mouse) in the editor?
spawn as in spawn with console
Re: Is it possible to locate an item via console using item ID?
Posted: Mon Jul 10, 2023 10:07 pm
by Isaac
Can you type that command here, as used?