Forum

> > CS2D > Scripts > LUA question - Saving
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch LUA question - Saving

5 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt LUA question - Saving

Infinite Rain
Reviewer Off Offline

Zitieren
Guys i need help to save arrays

for example:
when player leave the server arrays
x[id]
y[id]
save in another file on server's cs2d dir (USGNS)

when he join the server file will be loaded

can someone help mke with this pleeasE?

alt Re: LUA question - Saving

Yasday
User Off Offline

Zitieren
Here some functions:
1
2
3
4
5
6
7
8
9
10
11
12
13
function save(what, where, how)
if how == nil or how == "r" then how = "w" end
local f = io.open(where, how)
f:write(what)
f:close()
end

function load(what, where)
local f = io.open(where, "r")
local r = f:read("*"..what)
f:close()
return r
end
Use them like this:
1
2
save(x[id], "sys/lua/saves/"..player(id, "usgn")..".txt")
x[id] = load("n", "sys/lua/saves/"..player(id, "usgn")..".txt")

But I would prefer to save everything in one file.

alt Re: LUA question - Saving

Vectarrio
User Off Offline

Zitieren
I think you want to save whole array in one file
then you just must save it with "for" loop.
and of course, you must then know, where is array, and where are other vars.
But I don't have a code right now, sry.

alt Re: LUA question - Saving

TimeQuesT
User Off Offline

Zitieren
just split them with a ";". like ";5;;3;;22;"
then when you let the file read just the the values between them and put them in a table..

edit:

i copied it from my dm script so don't wonder about "dm"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
local text = ""
for l in io.lines("sys/lua/einstellung") do
text = string.format("%s %s",text,l)
end

local current = 0
local charpos = 0
for char = 1,string.len(text) do
if string.sub(text,char,char)==";" then

if charpos~=0 then
current = current + 1
dm.options[current] = tonumber(string.sub(text,charpos+1,char-1))
charpos = 0
elseif charpos==0 then
charpos = char
end
end
end
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht