Forum

> > CS2D > Scripts > save file
Forums overviewCS2D overview Scripts overviewLog in to reply

English save file

7 replies
To the start Previous 1 Next To the start

old save file

Homura Kami
User Off Offline

Quote
I try to addhook for usgn user save file but i still can't please tell me what should i do.

old Re: save file

Apache uwu
User Off Offline

Quote
Hi. There's isn't a defined hook for saves and loads. However, the two hooks that you may want to look at are:

cs2d lua hook join and cs2d lua hook leave

With conjunction with file:open, file:write, file:read, and file:close, as well as the datatype of your choice (plaintext, json, serialized, pickle, custom), you can load and read usgn save files.

To get player USID you can use player(id,"usgn"), cs2d lua cmd player.

old Re: save file

Rainoth
Moderator Off Offline

Quote
I'd also advise to use some other hook that triggers occasionally like minute or startround. Because if you use map change, it's not counted as leave (obviously) and some players don't trigger leave hook cause of lag (at least it seems so...)

old Re: save file

Homura Kami
User Off Offline

Quote
Hook minute is to save and hook join is to load but how create save file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if a==nil then a={}
function initArray(m)
	local array = {}
	for i = 1,m do
		array[i]=0
	end
	return array
end

level=initarray(32)
addhook("kill","a.kill")
function a.kill(id)
	level[id]=level[id]+1
	end
end

How to make save file for it?

old Re: save file

MikuAuahDark
User Off Offline

Quote
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
a=a or {}
function initArray(m)
	local array = {}
	for i = 1,m do
		array[i]=0
	end
	return array
end

level=initarray(32)
addhook("kill","a.kill")
function a.kill(id)
	level[id]=level[id]+1
end

addhook("leave","a.leave")
function a.leave(id)
	if player(id,"usgn")>0 then
		local temp=io.open("sys/lua/gelap/"..player(id,"usgn")..".txt","w")
		temp:write(level[id])
		temp:close()
	end
	level[id]=0
end

addhook("join","a.join")
function a.join(id)
	level[id]=0
	if player(id,"usgn")>0 then
		local temp=io.open("sys/lua/gelap/"..player(id,"usgn")..".txt","r")
		if temp then
			level[id]=tonumber(temp:read("*a"))
		end
	end
end

addhook("minute","a.minute")
function a.minute()
	for _, id in pairs(player(0,"table")) do
		if player(id,"usgn")>0 then
			local temp=io.open("sys/lua/gelap/"..player(id,"usgn")..".txt","w")
			temp:write(level[id])
			temp:close()
		end
	end
end

I also add a cs2d lua hook leave hook for saving.
Also you need to add "gelap" folder at "sys/lua"
edited 1×, last 04.08.13 03:43:17 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview