Forum

> > CS2D > Scripts > Save/load stats
Forums overviewCS2D overview Scripts overviewLog in to reply

English Save/load stats

6 replies
To the start Previous 1 Next To the start

old Save/load stats

HedShot
User Off Offline

Quote
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 :/)

old Re: Save/load stats

AlcatrazZ
BANNED Off Offline

Quote
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
edited 1×, last 22.04.14 01:18:00 pm

old Re: Save/load stats

Dousea
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
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.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview