Forum

> > CS2D > Scripts > Load function !
Forums overviewCS2D overview Scripts overviewLog in to reply

English Load function !

11 replies
To the start Previous 1 Next To the start

old Load function !

minos
User Off Offline

Quote
Hello guys i have made a command with save and load function and when i write !password <code> it saves perfectly but when I want to load my data with !login command it doesn't work !
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
elseif string.sub(txt,1,7)=="!login " then
USGN[id] = string.sub(txt,8,13)
password[id] = string.sub(txt,14,string.len(txt))
parse(USGN[id].." "..password[id])
  local file = io.open ("sys/lua/goRANK/"..USGN[id]..".txt","r")
          if file then
               local pid = file:read("*n")
			   password[id] = pid
               file:close ()
               msg2(id,"\169255255255Profile successfully loaded.")
  local file2 = io.open ("sys/lua/goRANK/"..USGN[id].."(2).txt","r")
          elseif file2 then 
		      local nid = file2:read("*n")
			  nickteam[id] = nid
			  file2:close ()
			  else
			   msg2(id,"failed")
          end
return 1

old Re: Load function !

Cebra
User Off Offline

Quote
maybe you look for something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
elseif string.sub(txt,1,7)=="!login " then
	USGN[id] = string.sub(txt,8,13)
	password[id] = string.sub(txt,14,string.len(txt))

	local file = io.open ("sys/lua/goRANK/"..USGN[id]..".txt","r")
	if file then
		local pid = file:read("*n")
		file:close ()
		if pid==password[id] then
			
			local file2 = io.open ("sys/lua/goRANK/"..USGN[id].."(2).txt","r")
			if file2 then
				nickteam[id] = file2:read("*n")
				file2:close()
				msg2(id,"\169255255255Profile successfully loaded.")
			end
		else
			msg2(id,"failed")
		end
return 1

old Re: Load function !

minos
User Off Offline

Quote
@user Cebra: Here is the !password part :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
elseif string.sub(txt,1,10)=="!password " then
local pid = string.sub(txt,11,string.len(txt)) 
password[id] = pid
parse(pid)
          local file = io.open ("sys/lua/goRANK/"..player(id,"usgn")..".txt","w")
          local pid = password[id]
          file:write (pid)
          file:close ()
		  local file2 = io.open("sys/lua/goRANK/"..player(id,"usgn").."(2).txt","w")
		  local nid = nickteam[id] 
		  file2:write(nid)
		  file2:close()
		  
		  msg2(id,"Saved")
		  return 1
		  else
		  msg2(id,"Failed")

old Re: Load function !

Cebra
User Off Offline

Quote
1
parse(USGN[id].." "..password[id])
and
1
parse(pid)
do nothing.
and post the error-message from the console, it helps you to find the bug

old Re: Load function !

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

password = initArray(32,null)
nickteam = initArray(32,null)

addhook("say","_say")
function _say(id,txt)
	if string.sub(txt,1,10)=="!password " then
		password[id] = string.sub(txt,11,string.len(txt))
		local file = io.open ("sys/lua/goRANK/"..player(id,"usgn")..".txt","w")
		file:write(password[id].."\n")
		file:write(nickteam[id])
		file:close ()
		msg2(id,"Saved")
		return 1
	elseif string.sub(txt,1,7)=="!login " then
		password[id] = string.sub(txt,8,string.len(txt))
		file = io.open ("sys/lua/goRANK/"..player(id,"usgn")..".txt","r")
		if file~=null then
			savedPW = file:read("*line")
			savedNID = file:read("*n")
			file:close()
			if password[id]==savedPW then
				nickteam[id] = savedNID
				msg2(id,"\169255255255Profile successfully loaded.")
			else
				msg2(id,"failed, pw incorrect")
			end
		end
		return 1
	end
end

old Re: Load function !

Waldin
User Off Offline

Quote
read cs2d lua cmd parse please, it executes console commands, that doesnt help you with writing/reading passwords.

also remember that Jesus loves you

old Re: Load function !

VaiN
User Off Offline

Quote
If you are planning to save/load player data, you could make things easier on yourself by just saving it as a table.
check out file cs2d [SALT] Save and Load Tables

Also, here I gave an example of saving/loading player data.

The use of string.sub() for commands just makes my head hurt. If you plan on making something more advanced you may want to consider creating a command processor. Here's a basic example of one.

Hope that helps.

old Re: Load function !

minos
User Off Offline

Quote
user VaiN has written
If you are planning to save/load player data, you could make things easier on yourself by just saving it as a table.
check out file cs2d [SALT] Save and Load Tables

Also, here I gave an example of saving/loading player data.

The use of string.sub() for commands just makes my head hurt. If you plan on making something more advanced you may want to consider creating a command processor. Here's a basic example of one.

Hope that helps.

Thank you mate your save lua is quite good but i don't know how to make it as a command to save only the user command player.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview