Forum

> > CS2D > Scripts > save file
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch save file

7 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt save file

Homura Kami
User Off Offline

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

alt Re: save file

Apache uwu
User Off Offline

Zitieren
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.

alt Re: save file

Rainoth
Moderator Off Offline

Zitieren
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...)

alt Re: save file

Homura Kami
User Off Offline

Zitieren
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?

alt Re: save file

MikuAuahDark
User Off Offline

Zitieren
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"
1× editiert, zuletzt 04.08.13 03:43:17
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht