Page 1 of 1

Mass spawning objects by script

Posted: Wed Dec 03, 2014 3:17 am
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

Re: Mass spawning objects by script

Posted: Wed Dec 03, 2014 4:35 am
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).

Re: Mass spawning objects by script

Posted: Wed Dec 03, 2014 5:25 am
by GoldenShadowGS
I don't know if that will work since they wander aimlessly when idle and will go above the surface.

Re: Mass spawning objects by script

Posted: Wed Dec 03, 2014 5:37 am
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.

Re: Mass spawning objects by script

Posted: Wed Dec 03, 2014 5:41 am
by GoldenShadowGS
How do you make a custom brain?

Re: Mass spawning objects by script

Posted: Wed Dec 03, 2014 5:54 am
by minmay

Re: Mass spawning objects by script

Posted: Wed Dec 03, 2014 9:34 pm
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.

Re: Mass spawning objects by script

Posted: Thu Dec 04, 2014 2:30 am
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.