My newest little bit of scripting

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

My newest little bit of scripting

Post by Ryeath_Greystalk »

You guys are probably bored of my little entry level scripts, but I'm having a blast trying to figure this stuff out.

Here is my latest script.

Code: Select all

--add bomb to alcove--

function addBomb()
local pitcheck = true
	if pitcheck == BombCheckPit:isOpen() then
		local bombcheck = BombAlcove1:getItemCount()
		local bombcheck2 = BombAlcove2:getItemCount()
			if bombcheck == 0 then
				BombAlcove1:addItem(spawn("shock_bomb"))
				if bombcheck2 == 0 then
					BombAlcove2:addItem(spawn("shock_bomb"))
				end
			else
			if bombcheck2 == 0 then
				BombAlcove2:addItem(spawn("shock_bomb"))
			end
		end
	end
end
Basically I need to have an available supply of bombs until the pit is closed. So the script checks if the pit is closed, then checks both alcoves and if they are empty puts a bomb in them.

Sometimes I think it's harder to design puzzles than to solve them.

What I've got going on is the basic throw an item across a pit to activate a pressure plate and close the pit. But I wanted to make it so the plate is activated by bombs only. So I came up with the idea to require the plate to be activated multiple times because a bomb will activate the plate then self destruct. Connected to a counter to count down and eventually close the pit. Great, but what if someone throws a rock first, then the plate will never deactivate and trap the player forever. So I put a teleport on the plate with a small delay and it would teleport the rock back to the player. However the counter still got triggered, so the pit would close even though no bombs were thrown. So I then used the timer to increment the counter to offset when the rocks activated the plate, but that didn't work either because it also reset when bombs were thrown. Then I put the teleporter connected to a wall button so the teleporter only comes on if the player pushes it, like a reset button.

Now that I got that part functioning I needed to make sure the player has bombs available. Thats where my script comes in. I have two alcoves to make bombs available, as long as they are empty. so the player will be able to complete the puzzle. Great my puzzle is complete, but wait another issue has arrived, the player now has an endless supply of bombs. However I didn't want the player to have an endless supply of bombs so I went back and added the pit close check to stop the supply once the pit closed.

Yeah I'm done, but not quite. Theres nothing stopping the player from loading up on bombs before solving the puzzle. I can think of two ways to deal with this so far, one is to search the players inventories, count how many shock bombs they have before reaching the puzzle and after the puzzle somehow removing the excess, or making sure no shock bombs are available up til this point and removing all shock bombs afterwards, or leaving a couple. I don't know, but I probably won't have a chance to look at it until this weekend.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: My newest little bit of scripting

Post by Komag »

That can be simplified a bit

function addBomb()
if BombCheckPit:isOpen then
local bombcheck1 = BombAlcove1:getItemCount()
local bombcheck2 = BombAlcove2:getItemCount()
if bombcheck1 == 0 then
BombAlcove1:addItem(spawn("shock_bomb"))
end
if bombcheck2 == 0 then
BombAlcove2:addItem(spawn("shock_bomb"))
end
end
end
Finished Dungeons - complete mods to play
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: My newest little bit of scripting

Post by Ryeath_Greystalk »

Thanks again Komag

After looking at they way you eliminated the pitcheck variable, I tried the same with the bombcheck variable and was able to eliminate a couple more lines.

Code: Select all

--add bomb to alcove--

function addBomb()
if BombCheckPit:isOpen() then
	if BombAlcove1:getItemCount() == 0 then
		BombAlcove1:addItem(spawn("shock_bomb"))
	end
	if BombAlcove2:getItemCount() == 0 then
		BombAlcove2:addItem(spawn("shock_bomb"))
	end
end
end

Much cleaner.

Thanks again for your wonderful insight.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: My newest little bit of scripting

Post by Komag »

sometimes using local variables like that, even for one-off use later, can keep the meat of the function more clear even if the whole function ends up longer. But in this case, your version is better. :)
Finished Dungeons - complete mods to play
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: My newest little bit of scripting (update)

Post by Ryeath_Greystalk »

I figured out how I'm gonna prevent the players from loading up on bombs now.

After musing for a couple hours about inventory searches and such, I decided to foray into the arena of custom assets. I cut and pasted the super_machete clone from the modding page and changed it to heavy_bomb, base item shock_bomb, named Heavy Bomb and made the weight 30 kilograms. Now they can carry as much as they want, provided they don't want to go anywhere. :twisted:

But I was wondering if there is a list of the definitions for items in the game. For instance I'm thinking about modifying a spider to make it a bit weaker than normal, but I don't know where to find out what normal is.

I'll keep looking around but if someone knows that would be awesome.

Thanks again.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: My newest little bit of scripting

Post by Komag »

it's in the asset pack in the scripts folder, see the monsters.lua for things like spiders, the items.lua for stuff like bombs, and the objects.lua for things like alcoves or doors
Finished Dungeons - complete mods to play
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: My newest little bit of scripting

Post by Ryeath_Greystalk »

Komag wrote:it's in the asset pack in the scripts folder, see the monsters.lua for things like spiders, the items.lua for stuff like bombs, and the objects.lua for things like alcoves or doors
I find the monsters file in the mod assets but it doesn't have anything in it. all it says is

-- This file has been generated by Dungeon Editor 1.3.6

-- TODO: place your custom monster definitions here

so I did a search of my computer for monsters.lua and .lua. I got 40 .lua files but nothing with the game monsters. Does the fact I bought throuh steam affect anything?
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: My newest little bit of scripting

Post by Neikun »

He means the scripts folder found in this file:
http://www.grimrock.net/modding/asset-pack/
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: My newest little bit of scripting

Post by Ryeath_Greystalk »

That's just what I was looking for.

Thanks Neikun & Komag
Post Reply