Page 1 of 2
scripting help
Posted: Mon Jan 20, 2020 1:28 am
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?
Re: scripting help
Posted: Mon Jan 20, 2020 11:18 am
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?
Re: scripting help
Posted: Mon Jan 20, 2020 7:05 pm
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.
Re: scripting help
Posted: Tue Jan 21, 2020 12:42 am
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.
Re: scripting help
Posted: Tue Jan 21, 2020 1:45 am
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
Re: scripting help
Posted: Tue Jan 21, 2020 1:59 am
by ratman
when I put that in, it gives me a warning on line 5 saying 'attempt to index local 'item' (a nil value)
Re: scripting help
Posted: Tue Jan 21, 2020 2:40 am
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.
*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.
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
Re: scripting help
Posted: Tue Jan 21, 2020 3:04 am
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?
Re: scripting help
Posted: Tue Jan 21, 2020 3:09 am
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?

Re: scripting help
Posted: Tue Jan 21, 2020 11:54 pm
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"