Forum

> > CS2D > Scripts > Not used tiles?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Not used tiles?

2 replies
To the start Previous 1 Next To the start

old Not used tiles?

zazz
User Off Offline

Quote
My current map is big ass, and my tileset is like 252+
Is it possible to know by lua what are the current tile IDs that i'm not using in the map? because i want to replace them with other ones (With Paint) and don't want to bug the map tiles

Sorry for the bother!

old Re: Not used tiles?

Cure Pikachu
User Off Offline

Quote
Not sure about this code.
× I am assuming first frame is 0 and tilecount returns 256 for a max-size tileset. (Second one is busted)
× Also assuming that the upper-left position of the map is (0,0) and the lower-right is (xsize-1,ysize-1). (Second one is busted)
√ I am posting from my laptop which doesn't have CS2D, so I can't test it at this time, sorry. Will update this when I get home.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
--[[
maptiles = {}
for x = 0, map("xsize") do
	maptiles[x] = {}
	for y = 0, map("ysize") do
		maptiles[x][y] = tile(x,y,"originalframe")
	end
end
]]

tileset_used = {}
for i = 0, map("tilecount") do
	tileset_used[i] = false
end

for i = 0, map("tilecount") do
	for x = 0, map("xsize") do
		for y = 0, map("ysize") do
			-- if maptiles[x][y] == i and (not tileset_used[i]) then
			if i == tile(x,y,"originalframe") and (not tileset_used[i]) then
				tileset_used[i] = true
			end
		end
	end
end

function output_unused_tiles() -- Call this to print output
	local output = ""
	print("Tile frames unused:")
	for i = 0, map("tilecount") do
		if not tileset_used[i] then
			if output == "" then
				output = output.. "" ..i
			else
				output = output.. " " ..i
			end
		end
	end
	print(output)
end
EDIT: Fixed the code, my assumptions aren't quite right. user zazz please come back and test again.
EDIT 2: I realised that it can be done much more efficently, I think.
edited 8×, last 25.11.15 08:28:34 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview