Forum

> > CS2D > Scripts > Strange error in save script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Strange error in save script

No replies
To the start Previous 1 Next To the start

old Strange error in save script

Ajmin
User Off Offline

Quote
guys i dont know why the error is happening it works sometime and wont works sometime. no error is displayed in console. i am using hc admin script with the lua so thats the problem? but i dont think so.
Somebody plse help with this

The script is this :

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
addhook("leave","save_leave") -- When you leave it saves
function save_leave(id)
     if (player(id,"usgn")>0) then
          io.output(io.open("sys/lua/saves/"..player(id,"usgn")..".txt","w+"))
          io.write(exp[id].." "..gp[id].." "..level[id])
          io.close()
     end
end

addhook("die","save_die") -- When you die it saves
function save_die(id)
     if (player(id,"usgn")>0) then
          io.output(io.open("sys/lua/saves/"..player(id,"usgn")..".txt","w+"))
          io.write(exp[id].." "..gp[id].." "..level[id])
          io.close()
     end
end
addhook("join","save_join") -- When join load
function save_join(id)
	if (player(id,"usgn")>0) then
		local filename = "sys/lua/saves/%s.txt"
		local file = io.open(filename:format(player(id,"usgn"), "r"))
		local line
		if not file then
			line = {0, 1}
                        level[id]=1
			msg2(id,"©255000000Failed to load save!@C")
		else
			line = file:read("*a"):split()
		end
		exp[id] = tonumber(line[1]) or 0 -- If line[1] is not a number, level[id] becomes 1
                gp[id] = tonumber(line[2]) or 0 -- Same as above reasoning (prevents errors)
		level[id] = tonumber(line[3]) or 1 -- Same as above reasoning (prevents errors)
	else
		msg2(id,"©255000000No USGN found!@C")
		level[id]=1
	end
end

Admin/mod comment

Please use the code-tag in future (added it for you) /DC
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview