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
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
sv={} addhook("say","sv.say") function sv.say(id,txt) 	local usgn = player(id,"usgn") 	local file 	if (txt=="!save") then 		if (usgn~=0) then 			file = io.open("sys/lua/saves/"..usgn..".txt", "w") 			file:write(VAR.."\n") -- Writes Line 1 			file:write(VAR.."\n") -- Writes Line 2 			file:write(VAR.."\n") -- Writes Line 3 			file:write(VAR.."\n") -- Writes Line 4 			file:write(VAR.."\n") -- Writes Line 5 			file:close() 			msg2(id,"©000255000Saved!") 			return 1 		else 			msg2(id,"©000255000You must have an USGN account for saving/loading.") 			return 1 		end 	elseif (txt=="!load") then 		if (usgn~=0) then 			file = io.open("sys/lua/saves/"..usgn..".txt", "r") 			VAR=file:read("\*n") -- Reads Line 1 			VAR=file:read("\*n") -- Reads Line 2 			VAR=file:read("\*n") -- Reads Line 3 			VAR=file:read("\*n") -- Reads Line 4 			VAR=file:read("\*n") -- Reads Line 5 			file:close() 			msg2(id,"©000255000Loaded!") 			return 1 		else 			msg2(id,"©000255000You must have an USGN account for saving/loading.") 			return 1 		end 	end end
I made a simple script for saving data to a file. I had to search a lot and had to download someone's else script (whom I don't remember and I couldn't find his post again) to understand how to actually do it.
I wanted to share it because it's very easy to understand this way, and very easy to edit it.
You just need to change VAR with whatever you want to save/load:
file:write(VAR.."\n") -- VAR is saved and "\n" creates a new line, so when you use file:write() again, it will write in that new line.
VAR=file:read("\*n") -- Whatever is in the line is assigned to VAR, calling file:read() again, reads the next line. The "\*n" is for reading numbers, so if you want to load a string, just leave VAR=file:read().
You should read the same quantity of lines that you write.
You can keep adding lines as you please.
It only saves/loads if you have an usgn account (you obviously can change that).
If you don't understand something just ask.