Anyone can help me use the f. functions to do this?
Forum
CS2D General Saving and loading a SINGLE value based on USGNSaving and loading a SINGLE value based on USGN
11 replies 1
Anyone can help me use the f. functions to do this?
And next time use the LUA thread
But post yours anyways just in case,
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
41
42
43
44
45
46
47
48
49
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
41
42
43
44
45
46
47
48
49
function initArray(m) 	local array = {} 	for i = 1, m do 		array[i]=0 	end 	return array end credits = initArray(32) addhook("leave","saved_save") function saved_save(id) local usgn = player(id, "usgn") if usgn > 0 then 	 if not player(id,"bot") then local save_data = credits[id].. file = assert(io.open("sys/lua/saved/"..usgn..".txt","w")) file:write(save_data) file:close() 		end 	end end addhook("join","joinsavnumt") function joinsavnumt(id) usgn=player(id,"usgn") 	files = io.open("sys/lua/saved/"..usgn..".txt","r") 	if(files~=nil) then 		for line in io.lines("sys/lua/saved/"..usgn..".txt","r") do 		local parses = toTable(line) 		if (tonumber(parses[1])>0) then 		credits[id] = tonumber(parses[1]) 		break 		end 	end end end function toTable(t,match) local cmd = {} 	if not match then match = "[^%s]+" end 		for word in string.gmatch(t, match) do 		table.insert(cmd, word) 	end 	return cmd end
Didn't really test it, try anyway
My Code:
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
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
function script.RP.save(id) 	if (player(id,"usgn") > 0) then 		f = assert(io.open('data/'..player(id,"usgn")..'.txt','w')) 		f:write(script.RP.money[id]) 		f:close() 		msg2(id,"©000255000Save File Written!@C") 	else 		msg2(id,"©000255000Save Failed!@C") 	end end function script.RP.load(id) 	local usgn = player(id,"usgn") 	if (usgn > 0) then 		msg2(id,'Your U.S.G.N. ID: '..usgn..'@C') 		hudtxt2(id,5,'Logged in: #'..usgn,5,410,0) 		f = io.open('data/'..usgn..'.txt','r') 		if (f ~= nil) then 			msg2(id'Your Save File Found!@C') 			local cash = tonumber(f:read("*all")) 			script.RP.transaction(id,cash) 			f:close() 		else 			msg2(id,'Failed To Load Save!@C') 		end 	else 		msg2(id,'Please check your U.S.G.N. account settings!@C') 	end end
do you really need to use totable?
Trotskygrad has written
[...]do you really need to use totable?
no not to save or load single values well you do not really need it for multiple values either
- Dark Void - has written
no not to save or load single values well you do not really need it for multiple values either
Trotskygrad has written
[...]do you really need to use totable?
no not to save or load single values well you do not really need it for multiple values either
then why does by load thing fail.
Trotskygrad has written
No, cause when you !save, it overwrites the old value.
You mean it can save new save's and not overwrite old save? that need you make menu for that, or you can also make new say like !save1, !save2, !save3, but need the different places.
Example:
Player says !save the script saves his cash: 15340$
Then the text file looks like this:
1
15340$
Now the text file looks like this:
1
14000$
Trotskygrad has written
Geh...
My Code:
My Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function script.RP.load(id) 	local usgn = player(id,"usgn") 	if (usgn > 0) then 		msg2(id,'Your U.S.G.N. ID: '..usgn..'@C') 		hudtxt2(id,5,'Logged in: #'..usgn,5,410,0) 		f = io.open('data/'..usgn..'.txt','r') 		if (f ~= nil) then 			msg2(id'Your Save File Found!@C') 		[b]	for l in io.lines('data/'..usgn..'.txt') do 			local cash = string.sub(l, 1, string.len(l))[/b] 			script.RP.transaction(id,cash) 			f:close() 		else 			msg2(id,'Failed To Load Save!@C') 		end 	else 		msg2(id,'Please check your U.S.G.N. account settings!@C') 	end end
that should work
1