Forum

> > CS2D > Scripts > Save/load stats
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Save/load stats

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Save/load stats

HedShot
User Off Offline

Zitieren
Hi!

I tried to search how to save/load variables in lua, but I couldn't find it in one place. I tried:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
addhook("say","_say")
function _say(p,txt)
	if txt == "!savestat" then
		local file = io.open("savedstats/"..player(p,'usgn')..".txt","w")
		file.write(player(p,'score'))
		file.write(player(p,'deaths'))
		file:close()
	end
	if txt == "!loadstat" then
		local file = io.open("savedstats/"..player(p,'usgn')..".txt","r")
		parse("setscore "..p.." "..!don't_know_this!)
		parse("setdeaths "..p.." "..!and_this!)
		file:close()
	end
end

The USGN only is turned on on the server...
Thanks for the answers! (and sry for my english :/)

alt Re: Save/load stats

AlcatrazZ
BANNED Off Offline

Zitieren
Not tested but something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
addhook("say","_say")
function _say(p,txt)
     if txt == "!savestat" then
          local file = io.open("savedstats/"..player(p,'usgn')..".txt","w")
          file:write(player(p,'score'))
          file:write(player(p,'deaths'))
          file:close()
     end
     if txt == "!loadstat" then
          local file = io.open("savedstats/"..player(p,'usgn')..".txt","r")
          parse("setscore "..p.." "..file:read())
          parse("setdeaths "..p.." "..file:read())
          file:close()
     end
end
You know that you seved files in Counter-Strike 2D/savedstats
1× editiert, zuletzt 22.04.14 13:18:00

alt Re: Save/load stats

Dousea
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
addhook ("say", "sayhook")

function sayhook (id, message)
	if (message == "!savestats") then
		local file = io.open ("sys/lua/savedstats/" .. player (id, "usgn") .. ".txt", "w+")
		
		file:write (player (id, "score") .. " " .. player (id, "deaths"))
		file:close ()
	elseif (message == "!loadstats") then
		local file = io.open ("sys/lua/savedstats/" .. player (id, "usgn") .. ".txt", "r")
		local values = {}
		
		for value in file:read ():gmatch ("[^%s]+") do
			table.insert (values, value)
		end
		
		parse ("setscore " .. id .. " " .. values[1])
		parse ("setdeaths " .. id .. " " .. values[2])
		
		file:close ()
	end
end
Opening file is relative to CS2D folder, so you gonna need to create a folder named "savedstats" inside "lua" folder.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht