Forum

> > CS2D > Scripts > Saving Map
Forums overviewCS2D overview Scripts overviewLog in to reply

English Saving Map

7 replies
To the start Previous 1 Next To the start

old Saving Map

X-Files
User Off Offline

Quote
is it possible to save map after changing tiles with lua ? in game ?
after restarting server all works is going and its bad...

if its not possible maybe dc can take it as new idea

old Re: Saving Map

MikuAuahDark
User Off Offline

Quote
Made this about 10 minutes
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
function do_write()
	local map=io.open("maps/"..game("sv_map")..".map","r+")
	if map:read("*l")=="Unreal Software's Counter-Strike 2D Map File (max)" then
		map:read(50)
		for i=1,12 do map:read("*l") end
		local tile_count=string.byte(map:read(1))
		map:read(7)
		map:read("*l")
		map:read(11)
		if map:read("*l"):reverse()=="unrealsoftware.de" then
			map:read(tile_count)
			for x=0,map("xsize") do
				for y=0,map("ysize") do
					map:write(string.char(tile(x,y,"frame")))
				end
			end
		else
			local pos=map:seek("cur")
			map:close()
			error("Invalid header! Seek at "..pos)
	else
		map:close()
		error("Invalid map file")
	end
	map:close()
end

Untested but it follows the cs2d map format.
Backup your map before using as it would modify the original map(mode r+)

old Re: Saving Map

DC
Admin Off Offline

Quote
Assuming that the script is correct: It only works if the map is not using any tile modifiers (like rotated tiles, blending, color, brightness). It would destroy maps with modifiers.

old Re: Saving Map

X-Files
User Off Offline

Quote
user MikuAuahDark has written
Made this about 10 minutes
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
function do_write()
	local map=io.open("maps/"..game("sv_map")..".map","r+")
	if map:read("*l")=="Unreal Software's Counter-Strike 2D Map File (max)" then
		map:read(50)
		for i=1,12 do map:read("*l") end
		local tile_count=string.byte(map:read(1))
		map:read(7)
		map:read("*l")
		map:read(11)
		if map:read("*l"):reverse()=="unrealsoftware.de" then
			map:read(tile_count)
			for x=0,map("xsize") do
				for y=0,map("ysize") do
					map:write(string.char(tile(x,y,"frame")))
				end
			end
		else
			local pos=map:seek("cur")
			map:close()
			error("Invalid header! Seek at "..pos)
	else
		map:close()
		error("Invalid map file")
	end
	map:close()
end

Untested but it follows the cs2d map format.
Backup your map before using as it would modify the original map(mode r+)


its giving an error says Invalid header! Seek at "x" pos
x changing for each map, i couldnt figure out

old Re: Saving Map

MikuAuahDark
User Off Offline

Quote
Hmm, it seems that it doesn't skipping some bytes correctly. I'm gonna check it out tomorrow.

bdw x is always changing for each map because string in cs2d map file are end at CRLF(unknown length).
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview