Is it possible to locate an item via console using item ID?

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
sapientCrow
Posts: 608
Joined: Sun Apr 22, 2012 10:57 am

Re: Is it possible to locate an item via console using item ID?

Post by sapientCrow »

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
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Is it possible to locate an item via console using item ID?

Post by Isaac »

Ah... Sorry, I mean't for you to post your spawn command as you typed in the game.

When I use the script in the editor preview, it locates the book (if it exists on the floor) within the dungeon. So I wanted to see your spawn command, to see the id that it generates. Lua is case sensitive, and any variation (even letter case) will not pass the equality check.
User avatar
sapientCrow
Posts: 608
Joined: Sun Apr 22, 2012 10:57 am

Re: Is it possible to locate an item via console using item ID?

Post by sapientCrow »

spawn "tome_wisdom"


is there a console command to hold an item and have it return the ID? or name
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Is it possible to locate an item via console using item ID?

Post by Isaac »

sapientCrow wrote: Tue Jul 11, 2023 1:32 am spawn "tome_wisdom"
This will generate a tome_wisdom object with a numerical id.

*You can check this id string by holding the tome item on the mouse cursor, and pasting the following into the console:

Code: Select all

print(getMouseItem().go.id)
To spawn an object in console with a specified id string, you can use this:

Code: Select all

spawn("tome_wisdom",nil,nil,nil,nil,nil,"your_id")
*Checkable with the above getMouseItem() function. The spawn will fail if there is already an object with that name.

Alternatively you can fill out the parameters for the Spawn function instead of using 'nil'. This lets you spawn it on a specific map, tile, face direction, and elevation.

Code: Select all

spawn(object, level, x, y, facing, elevation, id)
* https://github.com/JKos/log2doc/wiki/Gl ... ions#spawn

** BTW, objects with numerical id strings are not directly accessible—because you cannot use their id's directly. To access generated objects like these you can use findEntity() for this.

Code: Select all

print(findEntity("47").name)
User avatar
sapientCrow
Posts: 608
Joined: Sun Apr 22, 2012 10:57 am

Re: Is it possible to locate an item via console using item ID?

Post by sapientCrow »

Thank you so much!

All of this was really helpful for mean now I understand the difference between setting and spawning too as far as ID/name goes.

thanks again for the help!!
User avatar
sapientCrow
Posts: 608
Joined: Sun Apr 22, 2012 10:57 am

Re: Is it possible to locate an item via console using item ID?

Post by sapientCrow »

I guess if it has a numerical ID it is not possible to do a search for it with the level search code right?
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Is it possible to locate an item via console using item ID?

Post by Isaac »

If you know the numerical id#, you can put that inside the quotes, and it should work.

Code: Select all

local_item_id = "140" 
Post Reply