Scripting Problem: Grimrock Alchemist

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Green Cube
Posts: 6
Joined: Mon Sep 17, 2012 10:25 pm

Scripting Problem: Grimrock Alchemist

Post by Green Cube »

Hey,

I wanted to (kinda, sorta) create a room, where you can get an item by offering an item of equal value. So I created three alcoves with three hidden pressure plates in front of them and a lua script.

Code: Select all

function checkName()

	for s_item_1 in alcove_1:containedItems() do
		item_1 = s_item_1
	end
	
	for s_item_2 in alcove_2:containedItems() do
		item_2 = s_item_2
	end
	
	for s_item_3 in alcove_3:containedItems() do
		item_3 = s_item_3
	end

end



function checkItem()

	print(item_1)

	local alcoveCount = alcove_1:getItemCount()+alcove_2:getItemCount()+alcove_3:getItemCount()
	
	if alcoveCount <= 1 then
		if item_1 == getMouseItem() then
			alcove_1:addItem(item_1)
			
		elseif item_2 == getMouseItem() then
			alcove_2:addItem(item_2)
			
		elseif item_3 == getMouseItem() then
			alcove_3:addItem(item_3)
			
		end
		
	setMouseItem()
	hudPrint("Something of equal value must be offered.")
	
	end
	
	checkName()
	
end
The pressure plates connect to the checkName function and the alcoves to the checkItem function set on any. It works pretty well. The only problem is, beside the visual aspect, when you put more items into an alcove the script doesn't work anymore. You can just take all items and be on your way. So to prevent this, my idea was to store the last item (the second) into a variable and put it back to the mouse pointer.

How can I read out the last item and how can I remove it from an alcove using a script?

If this works, it should even be possible to turn this into a Zelda-esque shop. 8-)
Lilltiger
Posts: 95
Joined: Sun Sep 16, 2012 1:12 am

Re: Scripting Problem: Grimrock Alchemist

Post by Lilltiger »

Naa you are complicating it, just add a pressure plate when you exit the room, and there check if you have added enough items to the altars/alcoves to pay for what you bought, if not just close the door so you cant leave.

I think that is the easiest way.

As far as I know you can not remove items from alcoves/altars.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Scripting Problem: Grimrock Alchemist

Post by cromcrom »

Toggle a teleporter that will teleport the stuff in an unreachable place :)
A trip of a thousand leagues starts with a step.
User avatar
Green Cube
Posts: 6
Joined: Mon Sep 17, 2012 10:25 pm

Re: Scripting Problem: Grimrock Alchemist

Post by Green Cube »

@Lillitiger:
You're right, I complicated it. I tried it doing the way you suggested, but a problem came up. I now want to ask if a specific item is in one of three alcoves. I know I can do this by asking three times for each alcove, but is it possible to ask just once? Lua doesn't recognize "or" in a for loop. Or is there another way to ask, other than the one described in “Item on an Alcove”?

@cromcrom:
I thought about that, but that would just look weird if items just teleported away until you lie the other item down again.
Post Reply