Mass spawning objects by script

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
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Mass spawning objects by script

Post by GoldenShadowGS »

Code: Select all

function counttiles()
	local zero = 0
	local one = 0
	local two = 0
	local three = 0
	for x = 0,31 do
		for y = 0,31 do
			if party.map:getAutomapTile(x,y) == 0 then
				zero = zero + 1
			elseif party.map:getAutomapTile(x,y) == 1 then
				one = one + 1
			elseif party.map:getAutomapTile(x,y) == 2 then
				blocker = spawn("blocker", party.level, x,y,0,0)
				blocker.obstacle:setBlockItems(false)
				blocker.obstacle:setBlockMonsters(true)
				blocker.obstacle:setBlockParty(false)
				blocker.obstacle:setRepelProjectiles(false) 
				two = two + 1
			elseif party.map:getAutomapTile(x,y) == 3 then
				three = three + 1
			end
		end
	end
	print(zero,one,two,three)
	local total = zero + one + two + three
	print("Total =", total)
end

counttiles()
With the help of the asset pack, I figured out how to make flying Zarchton divers. This change lets them change elevation, but the big problem I have is they are not limited to the water. They like to fly above the water surface and I can not have that!
So my solution is to put a sheet of blockers on the water surface that is set to only block monsters. Doing this manually is extremely tedious, so I wrote a script to place them all for me and apply the correct settings to each one.

I left in the debug code so you can experiment with that each number represents, 2 = water. In a 32*32 map grid, you should end up with 1024 tiles, and it does, at least on the map I tested it on.

Change party.level to the actual number for your level once you know it.

EDIT: found out that the coordinates start at 0 instead of 1, so X range is 0, 31 and Y range is 0, 31
Last edited by GoldenShadowGS on Thu Dec 04, 2014 5:14 pm, edited 2 times in total.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Mass spawning objects by script

Post by minmay »

This seems like a really bad solution. It will stop actual flying monsters from crossing water, and bloat the level with unneeded entities on top of that.

I would rather use the onBeginAction hook in the zarchton's MonsterChangeAltitude component, check the elevation, and return false if it would result in moving out of a water tile (i.e. the party is not below them (so they are trying to move up) and they are already at the water surface's elevation).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: Mass spawning objects by script

Post by GoldenShadowGS »

I don't know if that will work since they wander aimlessly when idle and will go above the surface.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Mass spawning objects by script

Post by minmay »

Really? Are you sure? I've never seen an eyctopus, xeloroid, crowern, wyvern, shrakk torr, ice guardian, etc. change elevation except directly to the party's elevation. If that really is the case, just use a custom brain I guess.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: Mass spawning objects by script

Post by GoldenShadowGS »

How do you make a custom brain?
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Mass spawning objects by script

Post by minmay »

Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Mass spawning objects by script

Post by Drakkan »

Hi GoldenShadowGS, I am quite interested to use your script for some fancy thing. Please could you check if it is possible to do following - when script triggered I want object Raining_particle to be spawned in current dungeon level in elevation level 7. And also some trigger which will disable it all again when required.
Please check

thanks alot.
Breath from the unpromising waters.
Eye of the Atlantis
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: Mass spawning objects by script

Post by GoldenShadowGS »

Sounds like its possible with the nested for loops that check every tile. it checks all 32 Y coordinates for each X coordinate. You can use that to do stuff. Like find which tiles are at a certain elevation. Map:getElevation(x,y)
for x = 1,32 do
for y = 1,32 do
if party.map:getElevation(x,y) == 7 then
--do stuff here
end
end
end

You can switch party (I think) for any entity on the map you want to run the script on.

If you are a little more specific with the details, I can help write a script for you.
Post Reply