[Script] Fill void with walls

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

[Script] Fill void with walls

Post by alois »

Hi all!

If one tries different elevations in a forest, or in a beach scenario, one immediately finds that - differently to what happens with dungeons and mines, for example - zones with different elevations are not automatically filled (there is no "forest wall" as there is a "dungeon wall"; I mean, there is, but it is not "vertical"!); thus, if one wants to make zones with different elevations using outdoor tiles, one has to build the walls one by one: a rather difficult task (is the facing correct? the elevation? etc.).

I've therefore written the following code which "fills in the blanks", adding "dungeon_walls" to compensate for the lack of a beach/forest wall. Just draw a map outdoors with different elevations (set the ceiling to 7 to avoid unpleasant surprises...), either using the beach ground tile, or the forest ground tile (or both), and then connect a pressure plate to the "makeWalls()" function in the script below. Step on the plate, and it's done!

Code: Select all

function makeWalls()
	local map = self.go.map
	local inix,finx = 0,31 -- the full map, change as you like
	local iniy,finy = 0,31 -- the full map, change as you like
	local list = {
		"dungeon_wall_01",
		"dungeon_wall_02",
	}
-- also: local list = {"forest_elevation_edge"}
	for x = (inix+1),(finx-1),1 do
		for y = (iniy+1),(finy-1),1 do
			local tilec = map:getAutomapTile(x,y)
			local elevc = map:getElevation(x,y)
			if (tilec == 1) or (tilec == 0) then -- 0 and 1 are the automap tiles for beach ground and forest ground
				for dir = 0,3,1 do
					local dx,dy = getForward(dir)
					local tilen = map:getAutomapTile(x+dx,y+dy)
					local elevn = map:getElevation(x+dx,y+dy)
					if ((tilen == 1) or (tilen == 0)) and (elevc < elevn) then
						for elev = elevc,(elevn-1),1 do
							local ran = math.random(#list)
							spawn(list[ran],party.party.level,x,y,dir,elev)
						end
					end
				end
			end
		end
	end
end
Here are the screenshots of the map, and the rendering before/after stepping on the pressure plate connected to the script

Image

Image

Image

Now, if only it were possible to save a file from the editor to disk, one could create the map, let the script add the walls, save their positions to disk, and copy the file inside dungeon.lua...

Alois :)
Last edited by alois on Wed Nov 12, 2014 9:52 am, edited 2 times in total.
User avatar
antti
Posts: 688
Joined: Thu Feb 23, 2012 1:43 pm
Location: Espoo, Finland
Contact:

Re: [Script] Fill void with walls

Post by antti »

Instead of the dungeon walls, I suggest you to try out "forest_elevation_edge". It's the walls which are used on the river banks and such so it should be compatible with forest and beach ground.
Steven Seagal of gaming industry
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: [Script] Fill void with walls

Post by alois »

antti wrote:Instead of the dungeon walls, I suggest you to try out "forest_elevation_edge". It's the walls which are used on the river banks and such so it should be compatible with forest and beach ground.
Done: thanks!

Any chances to see a function to save a file to disk from within an editor run? :)

Alois :)
Post Reply