Forum

> > CS2D > Scripts > save&load error.
Forums overviewCS2D overview Scripts overviewLog in to reply

English save&load error.

13 replies
To the start Previous 1 Next To the start

old save&load error.

loldlold123
User Off Offline

Quote
Spoiler >
thats not complete lua,but other codes not about save&load

i dont have good english, and i will talk clearly.
Step1:
i join to my server
Step2:
i take 1000 dollar
Step3:
i exit from my server
Step4:
i rejoin to my server
Step5:
i saw my 1000 dollar.(and there is 1000 dollar value in xxxx.txt(this means saved successfully))
Step6:
Server SHUTDOWN.
Step7:
Server again online
Step8:
i join to my server
Step9:
There is no money.
-----
There is no error in console.
i think,you understant my problem.i need help pls.

old Re: save&load error.

Hador
User Off Offline

Quote
Did the Server shut itself down, or did you shut it down?

Did the message "Failed to load save!" appear?


Oh, and next time use the code-tag so that we can understand the code better.
edited 2×, last 16.07.11 11:06:31 pm

old Re: save&load error.

loldlold123
User Off Offline

Quote
@hador,when i close it or when shut itself
@fehuziom there is already save function in leave hook in complete script
@2fast4you ARE YOU CRAZY? i must close server, when i update it,or when server crashed all players will kill me.

old Re: save&load error.

Hador
User Off Offline

Quote
no, the question was, when you say "server SHUTDOWN",

do you mean:

1. you went to your Server and closed the program
or
2. you did nothing, and the server shut down all by its self?

old Re: save&load error.

EngiN33R
Moderator Off Offline

Quote
@hador
Of course he meant 1.

You might want to check the file after the server shutdown and see if it still keeps the 1000 value or becomes empty.

Also it might be because you're shutting down the server while you're on it (just speculating).

old Re: save&load error.

loldlold123
User Off Offline

Quote
hador,i mean both of them.when i closing or when it shut it self.

@Engin33R
i saw 1000 value in xxx.txt file ,when i close it.And when i open it there is again 1000 value in xxx.txt but when i exit from server or when i shutdown it.hhleave(id) make your money=0 (hhleave(id)
          hhsave(id)
          money[id]=0)
and these means:
Save succuessfully.
Load system has error but i dont know what is error.

--------------------------------
i think,i need new load system.Can anyone do it?
put these variables

careerpoint[id]
money[id]
moral[id]
plx[id]
ctpas[id]
tpas[id]
pistoll[id]
lightl[id]
shoplicencelevel[id]
shoplicencepoint[id]
careerpoint[id]
and these variables in usgn.txt with this status
0 0 0 0 0 0 0 0 0 0 0
and file,(sys/lua/user)

pls help me,i promised to my friends i open it Monday but i cant do it if there is no save&load system.
edited 1×, last 17.07.11 05:59:06 pm

old Re: save&load error.

Apache uwu
User Off Offline

Quote
Yeah it is very very messy.

New code.

1
2
3
4
5
6
7
8
9
10
11
addhook("join","_join")

player_dat={}

function _join(id)
	if player(id,"usgn")~=0 then
		for line in io.lines("sys/lua/user/"..player(id,"usgn")..".txt") do
			player_dat[id]={line:match("(.*) (.*) (.*) (.*) (.*) (.*) (.*) (.*) (.*) (.*) (.*)")}
		end
	end
end

Not tested, but it should have...

player_dat[id][1] --> careerpoint[id]
player_dat[id][2] --> money[id]
player_dat[id][3] --> moral[id]

And so on.

old Re: save&load error.

Lee
Moderator Off Offline

Quote
You could just use a more generalized solution that splits a string via whitespace. This ensures that adding additional entries in the data scheme won't require rewriting of the code

1
2
3
4
5
6
7
8
9
10
function string.split(t, s)
	local cmd = {}
	for word in t:gmatch "[^" .. (s and s or "%s") .."]+" do
		table.insert(cmd, word)
	end
	return cmd
end

...
               player_dat[id]=line:split()

old Re: save&load error.

loldlold123
User Off Offline

Quote
okey but where i need to add player_dat[id]=line:split() ?

function hhload(id)
          if player(id,"usgn")~=0 then
for line in io.lines("sys/lua/user/"..player(id,"usgn")..".txt") do
               player_dat[id]=line:split()
player_dat[id]={line:match("(.*) (.*) (.*) (.*) (.*) (.*) (.*) (.*) (.*) (.*) (.*)")}
               careerpoint[id]=player_dat[id][1]
               money[id]=player_dat[id][2]
               moral[id]=player_dat[id][3]
               plx[id]=player_dat[id][4]
               ctpas[id]=player_dat[id][5]
               tpas[id]=player_dat[id][6]
               pistoll[id]=player_dat[id][7]
               lightl[id]=player_dat[id][8]
               shoplicencelevel[id]=player_dat[id][9]
               shoplicencepoint[id]=player_dat[id][10]
end
end
end

is that true?

old Re: save&load error.

Apache uwu
User Off Offline

Quote
user Lee has written
You could just use a more generalized solution that splits a string via whitespace. This ensures that adding additional entries in the data scheme won't require rewriting of the code

1
2
3
4
5
6
7
8
9
10
function string.split(t, s)
	local cmd = {}
	for word in t:gmatch "[^" .. (s and s or "%s") .."]+" do
		table.insert(cmd, word)
	end
	return cmd
end

...
               player_dat[id]=line:split()



You just lua raped me !!

Yeah that is the best method here, this code wouldn't work in most cases, since the delimiter could be more than just whitespace. Ex. "Username Password ;".

@Headhunter

You could just create the lua with player_dat[id][#] however if you are planning to use variables that you can understand I recommend you rewrite so it's like...

1
2
3
4
5
player={}
player.career=player_dat[id][1]
player.money=player_dat[id][2]
player.moral=player_dat[id][3]
--etc etc

Use string.split, it's more effective for your lua. Good luck !
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview