scripting help
scripting help
how do I make it so that when you place a certain item on altar, it removes it and replaces it with something else?
Grey Island mod(WIP): http://www.grimrock.net/forum/viewtopic ... 99#p123699
Re: scripting help
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]
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?
- Sir Tawmis
- Posts: 994
- Joined: Mon Jul 30, 2012 8:15 am
- Contact:
Re: scripting help
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.
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.
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.
Re: scripting help
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.
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.
Grey Island mod(WIP): http://www.grimrock.net/forum/viewtopic ... 99#p123699
Re: scripting help
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
when I put that in, it gives me a warning on line 5 saying 'attempt to index local 'item' (a nil value)
Grey Island mod(WIP): http://www.grimrock.net/forum/viewtopic ... 99#p123699
Re: scripting help
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.
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.
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
Re: scripting help
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?
Grey Island mod(WIP): http://www.grimrock.net/forum/viewtopic ... 99#p123699
Re: scripting help
Try the script as-is, in a new project; place an altar and the rocks.
*Also, what is the item that you are using?

*Also, what is the item that you are using?

Re: scripting help
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"
Grey Island mod(WIP): http://www.grimrock.net/forum/viewtopic ... 99#p123699