scripting help

Have trouble running Legend of Grimrock 2 or do you have questions about the purchasing options? Look for help here.
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

scripting help

Post by ratman »

how do I make it so that when you place a certain item on altar, it removes it and replaces it with something else?
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: scripting help

Post by Isaac »

This really needs to be in the forum for your intended game; nearly all scripting advice will be very different between the two.

Question(s): [Assuming LoG2]
  • Do you intend that the user-placed item becomes something new when put upon the [empty] altar, or will there be an item already on the altar that must change into the new item? (If so, does this destroy the item placed?)
  • Is the user placed item stackable?
User avatar
Sir Tawmis
Posts: 980
Joined: Mon Jul 30, 2012 8:15 am
Contact:

Re: scripting help

Post by Sir Tawmis »

As Isaac said - please post the questions in the proper sections of the forum.

We have sections for Legend of Grimrock 1 and 2, from general chatter, to actual scripting and modding.

Please let us know what game this is for and it will be moved to the proper section.
Define ... 'Lost.' Neverending Nights - The Neverwinter Machinima that WILL make you laugh!
Also read: Legend of Grimrock: Destiny's Chance here on the forum! Check out the site I made for Legend of Grimrock: Destiny's Chance.
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

Re: scripting help

Post by ratman »

grimrock 2
the item becomes something new and is not stackable.
I would try to do something like when the party places a gem on the altar it replaces it with a potion.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: scripting help

Post by Isaac »

Code: Select all

altar_1.surface:addConnector('onInsertItem', self.go.id, "itemSwap")  --< change altar_1 to the ID of your altar >
function itemSwap(surface, item)
	local checkItem = "rock" -------------------------------< Name of the user placed item >
	local itemReplacement = "figure_skeleton" ----< Name of the replacement item >
		if item.go.item:getStackSize() < 2 and
			item.go.name == checkItem then
			item.go:destroy()
			surface:addItem(spawn(itemReplacement).item)
		end
end
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

Re: scripting help

Post by ratman »

when I put that in, it gives me a warning on line 5 saying 'attempt to index local 'item' (a nil value)
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: scripting help

Post by Isaac »

First (and you may have already), please double check that the copy / paste was exact.
I do not see this error in the editor or in the game. :o

*Also, please ensure that you are running version: 2.2.4 of the engine.

__________________________________

Here is the same script as above, but with an effect for the spawned item.
SpoilerShow

Code: Select all

altar_1.surface:addConnector('onInsertItem', self.go.id, "itemSwap")
function itemSwap(surface, item)
	local checkItem = "rock"
	local itemReplacement = "figure_skeleton"
		if item.go.item:getStackSize() == 1 and
			item.go.name == checkItem then
			item.go:destroy()
			surface:addItem(spawn(itemReplacement).item)
			--optional effect 
			surface.go:createComponent('Particle'):setParticleSystem('beacon_crystal')
			surface.go.particle:setDestroySelf(true)
			surface.go.particle:fadeOut(1)
			surface.go:playSound('teleport')
		end
end
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

Re: scripting help

Post by ratman »

I checked and I am running version 2.2.4 version, and I double checked the copy and paste. perhaps it is because of an asset pack I am using in my dungeon?
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: scripting help

Post by Isaac »

Try the script as-is, in a new project; place an altar and the rocks.
*Also, what is the item that you are using?
Image
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

Re: scripting help

Post by ratman »

I tried again in the same project making the connecter to the script from the altar (I don't know why I didn't think of that earlier) and now on the same line the warning simply says "bad object"
Post Reply