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

Re: scripting help

Post by ratman »

I also tried in a new project and same warning
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: scripting help

Post by Isaac »

That's very peculiar that I don't get an error with mine, but yours does.

Okay, try this variation on the script:

Code: Select all

altar_1.surface:addConnector('onAcceptItem', 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:destroyDelayed()
			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')
			return false
		end
end
This one gives me no errors, but handles things slightly different than before; based on a hunch. The original script did have a bug—though it didn't crash for me. This version fixes that bug.
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

Re: scripting help

Post by ratman »

that works thank you. :D
billb52

Re: scripting help

Post by billb52 »

Hi Issac
Tried using your variation of the script but when you place the rock on the altar I end up with 2 'skeleton figurines' every time
and the particle system does not fade out, any ideas?
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

Re: scripting help

Post by ratman »

I am trying to use this but instead the player puts some items on a pedestal then hits a button which checks for items and spawns them on the pedastel
User avatar
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: scripting help

Post by Zo Kath Ra »

ratman wrote: Sun Nov 15, 2020 5:51 pm I am trying to use this but instead the player puts some items on a pedestal then hits a button which checks for items and spawns them on the pedastel
IIRC you wanted a script that turns multiple items into a single new item, like crafting potions.

Code: Select all

function transformItems(button)
	local input_item_names = { rock = false, branch = false }
	local output_item_name = "cudgel"
	local surface
	
	local alcove = findEntity("dungeon_alcove_1")
	if alcove and alcove.surface then
		surface = alcove.surface
	else
		print("Entity doesn't exist or has no surface component: dungeon_alcove_1")
		return
	end
	
	-- If any of the input items is on the surface, mark it as present in input_item_names
	for _, item in surface:contents() do
		if input_item_names[item.go.name] ~= nil then
			input_item_names[item.go.name] = true
		end
	end
	
	-- If at least one input item is missing from the surface, exit the function
	for _, present in pairs(input_item_names) do
		if present == false then
			return
		end
	end
	
	-- Destroy the input items
	for _, item in surface:contents() do
		if input_item_names[item.go.name] == true then
			-- Mark the item as destroyed in input_item_names
			-- So only one instance of the input item gets destroyed
			input_item_names[item.go.name] = false
			item.go:destroyDelayed()
		end
	end
	
	-- Add the output item to the surface
	surface:addItem(spawn(output_item_name).item)
	playSound("secret")
	hudPrint("The alcove has created a new " .. output_item_name .. ".")
end
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

Re: scripting help

Post by ratman »

Thanks. How would I make it so it destroys the items even if they are not the right ones?
Post Reply