edited 1×, last 11.07.13 11:51:15 pm
Forum
CS2D Scripts Save/Load pointsSave/Load points
18 replies 1
Global USGN data manager [LOAD/SAVE SCRIPT] (20)
(Don't take it as a troll post)
Infinite Rain has written
I think that I'm the only one who noticed it, but I think that Starkkz join unreal software only to upload his scripts/apps or to brag them in threads like this. I might be wrong tho.
Actually Starkkz's files are good and there are no doubts (I think), but I don't think that superpegamento needs so complicated script as Starkkz posted. In f.a there are lots of easy scripts that superpegamento would use.
On-topic: I would like to know if the file serves or not.
Starkkz has written
@ Infinite Rain: Don't be jealous, I make this stuff so the people can solve their problems quickly. Maybe he has more things to save than just points, that's why I share it to him.
On-topic: I would like to know if the file serves or not.
On-topic: I would like to know if the file serves or not.
hi Starkkz guide me with your codes , but a problem not load data.. that could be?
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
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
local points = {} addhook("join", "point_reset") addhook("kill","point_increase") addhook("say" , "points") addhook("leave","points_save") addhook("join" , "loadpoints") function point_reset(id) points[id] = 0 point_update(id) end function point_increase(id) if not points[id] then points[id] = 0 return end points[id] = points[id] + 1 point_update(id) end function points(id,msg) if msg=="!point" then msg2(id, "©252000000"..player(id,"name").." ©255075000Your Points:©000100255 " .. points[id] or 0 .. "") end end function point_update(id) end function points_save(id) if (player(id,"usgn")>0) then io.output(io.open("sys/lua/saves/ranking/"..player(id,"usgn")..".txt","w+")) io.write(points[id]) io.close() end end function loadpoints(id) 	if (player(id,"usgn")>0) then 		local filename = "sys/lua/saves/ranking/%s.txt" 		local file = io.open(filename:format(player(id,"usgn"), "r")) end end
Starkkz has written
@ Infinite Rain: Don't be jealous
I lol'd.
---
Where in the post I said that your files are bad? Read carefully.
Admin/mod comment
First warning, stop going off-topic. Starkkz has written
On the load function you have to use file:read("*a"), it will return the points as a string, after that you will have to use the tonumber function to convert it into a number.
please code example...
in this way?
1
2
2
line = file:read("*a"):split() points[id] = tonumber(line[1]) or 0
Infinite Rain has written
I think that I'm the only one who noticed it, but I think that Starkkz join unreal software only to upload his scripts/apps or to brag them in threads like this. I might be wrong tho.
(Don't take it as a troll post)
(Don't take it as a troll post)
I think people noticed that but you didn't, Everyone here brag his uploads.
Starkkz has written
@ superpegamento: You don't need to use the split function in this case, but it will work anyway if you added it to your script. If you didn't, it won't work.
Ok.
This hook will work then?
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
function loadpoints(id) 	if (player(id,"usgn")>0) then 		local filename = "sys/lua/saves/ranking/%s.txt" 		local file = io.open(filename:format(player(id,"usgn"), "r")) 		line = file:read("*a") 		points[id] = tonumber(line[1]) or 0 	end end
Edit: change this
1
local file = io.open(filename:format(player(id,"usgn"), "r"))
To this:
1
local file = io.open(filename:format(player(id,"usgn")), "r")
edited 1×, last 11.07.13 08:17:15 pm
Starkkz has written
I suggest you to put local when defining the line variable, change line[1] to line, and finish it puting file:close().
Edit: change this
To this:
Edit: change this
1
local file = io.open(filename:format(player(id,"usgn"), "r"))
To this:
1
local file = io.open(filename:format(player(id,"usgn")), "r")
Ok..but still not working
here is the 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
50
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 local points = {} addhook("join", "point_reset") addhook("kill","point_increase") addhook("say" , "puntos") addhook("leave","save_leave") addhook("join" , "loadpoints") function point_reset(id) points[id] = 0 point_update(id) end function point_increase(id) if not points[id] then points[id] = 0 return end points[id] = points[id] + 1 point_update(id) end function puntos(id,msg) if msg=="!point" then msg2(id, "©252000000"..player(id,"name").." ©255075000Your Points:©000100255 " .. points[id] or 0 .. "") end end function point_update(id) end function save_leave(id) if (player(id,"usgn")>0) then local file = (io.open("sys/lua/saves/ranking/"..player(id,"usgn")..".txt","w+")) file:write(points[id]) file:close() end end function loadpoints(id) 	if (player(id,"usgn")>0) then 		local filename = "sys/lua/saves/ranking/%s.txt" 		local file = io.open(filename:format(player(id,"usgn")), "r") 		line = file:read("*a") 		points[id] = tonumber(line) or 0 file:close() 	end end
Starkkz has written
Does it give you errors?
not get errors the problem is that the data is not loaded when you enter the server, for example
1 point for kill a user - is stored in the folder saves/ranking
then exit and enter on server have 0 points - points not charged ... Try in your server
Starkkz has written
On line 21 remove return, on line 36 change w+ to w, on line 46 change *a to *l
thank you very much!
the problem was the hook
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
addhook("kill","point_increase") function point_reset(id) points[id] = 0 point_update(id) end function point_increase(id) if not points[id] then points[id] = 0 return end points[id] = points[id] + 1 point_update(id) end
is replaced for
1
2
3
4
2
3
4
addhook("kill" , "point_increase") function point_increase(id) points[id] = points[id] + 1 end
1