Forum

> > CS2D > Scripts > Login System Lua
Forums overviewCS2D overview Scripts overviewLog in to reply

English Login System Lua

15 replies
To the start Previous 1 Next To the start

old Login System Lua

Marcell
Super User Off Offline

Quote
Hey Guys,


I asking for a bit help for you. I just cant fix this script to get work..

Would be nice if there is someone, who can help me.

> Script:
Spoiler >

old Re: Login System Lua

VADemon
User Off Offline

Quote
Fixed ends of the last function: >


You need to use even proper tabbing to avoid mistakes. By the way do you even use Notepad++ or any other editor with a decent Lua syntax highlighting?
http://lua-users.org/wiki/LuaStyleGuide

Another piece of the same function, with what I call proper tabbing
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
-- Functions -- 

function onSay(id,txt)
	local space = txt:find(" ") or (#txt + 1)
	local cmd = txt:sub(1, space - 1)
-- LOGIN
	if cmd == "!login" then
		cur = con:execute("select * from users")
		row = cur:fetch({}, 'a')
		for k, v in pairs(row) do
			print(k, v)
		end
    end
-- REGISTER
    if cmd=="!register" then
		local regName = txt:sub(cmd+2)
		local regPW = string.len(regName)+2
		local regDate = os.date("%c")
		
		if usgn > 0 then
			res = assert (con:execute(string.format([[
INSERT INTO users VALUES ('%s', '%s', '%s')]],	-- if you use [[ ]] then you have to avoid newlines in your code, AFAIK
			regName, regPW, regDate)))
			msg2(id,"Your account has been registered under: ")
			msg2(id,"Username: "..regName)
			msg2(id,"Password: "..regPW)
			msg2(id,"You can now login using "..color[2].."!login <username> <password>")
			-- Variable from database
		end
	end
end

old Re: Login System Lua

Marcell
Super User Off Offline

Quote
Thanks, but its not fixed the issue at all..

I getting LUA ERROR: sys/lua/autorun/index.lua:126: attempt to perform arithmetic on local 'cmd' a string value

I also tried it with player[id].registerPW etc
but if i create player = {} table
its still bad.

old Re: Login System Lua

_Yank
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
-- Functions -- 

function onSay(id,txt)
     local space = txt:find(" ") or #txt + 1
     local cmd = txt:sub(1, space - 1)
-- LOGIN
     if cmd == "!login" then
          cur = con:execute("select * from users")
          row = cur:fetch({}, 'a')
          for k, v in pairs(row) do
               print(k, v)
          end
    end
-- REGISTER
    if cmd=="!register" then
          local regName = txt:sub(#cmd+2)
          local regPW = #regName+2
          local regDate = os.date("%c")
          
          if usgn > 0 then
               res = assert (con:execute(string.format([[
INSERT INTO users VALUES ('%s', '%s', '%s')]],     -- if you use [[ ]] then you have to avoid newlines in your code, AFAIK
               regName, regPW, regDate)))
               msg2(id,"Your account has been registered under: ")
               msg2(id,"Username: "..regName)
               msg2(id,"Password: "..regPW)
               msg2(id,"You can now login using "..color[2].."!login <username> <password>")
               -- Variable from database
          end
     end
end

old Re: Login System Lua

Marcell
Super User Off Offline

Quote
@user _Yank:

LUA ERROR: sys/lua/autorun/index.lua:130: attempt to compare number with nil

Ohh, nevermind, my fault

added local usgn = player(id, "usgn") now its a bit works.

At least its stores data but with a problem.

check it: http://prntscr.com/7fh598

The password should be football and not 15

Also if i try to login its giving access violation :S
edited 2×, last 10.06.15 09:59:12 pm

old Re: Login System Lua

_Yank
User Off Offline

Quote
-- Functions --

function onSay(id,txt)
local usgn = player(id, "usgn")
local space = txt:find(" ") or #txt + 1
local cmd = txt:sub(1, space - 1)
-- LOGIN
if cmd == "!login" then
cur = con:execute("select * from users")
row = cur:fetch({}, 'a')
for k, v in pairs(row) do
print(k, v)
end
end
-- REGISTER
if cmd=="!register" then
local regName = txt:sub(#cmd+2)
local regPW = #regName+2
local regDate = os.date("%c")

if usgn > 0 then
res = assert (con:execute(string.format([[
INSERT INTO users VALUES ('%s', '%s', '%s')]], -- if you use [[ ]] then you have to avoid newlines in your code, AFAIK
regName, regPW, regDate)))
msg2(id,"Your account has been registered under: ")
msg2(id,"Username: "..regName)
msg2(id,"Password: "..regPW)
msg2(id,"You can now login using "..color[2].."!login <username> <password>")
-- Variable from database
end
end
end

old Re: Login System Lua

_Yank
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
-- Functions -- 

function onSay(id,txt)
     local usgn = player(id, "usgn")
     local space = txt:find(" ") or #txt + 1
     local cmd = txt:sub(1, space - 1)
-- LOGIN
     if cmd == "!login" then
          cur = con:execute("select * from users")
          row = cur:fetch({}, 'a')
          for k, v in pairs(row) do
               print(k, v)
          end
    end
-- REGISTER
    if cmd=="!register" then
          local regName = txt:sub(#cmd+2)
          local regPW = txt:sub(#regName+2)
          local regDate = os.date("%c")
          
          if usgn > 0 then
               res = assert (con:execute(string.format([[
INSERT INTO users VALUES ('%s', '%s', '%s')]],     -- if you use [[ ]] then you have to avoid newlines in your code, AFAIK
               regName, regPW, regDate)))
               msg2(id,"Your account has been registered under: ")
               msg2(id,"Username: "..regName)
               msg2(id,"Password: "..regPW)
               msg2(id,"You can now login using "..color[2].."!login <username> <password>")
               -- Variable from database
          end
     end
end

old Re: Login System Lua

VADemon
User Off Offline

Quote
@user Marcell: regarding the password issue:
1
local regName = txt:sub(cmd+2)
Returns the string from (cmd+2) to the end, you want a string from (cmd+2) until the next space, if that space exists.

old Re: Login System Lua

Marcell
Super User Off Offline

Quote
@user VADemon:

Its fixed already but thanks!

Now i have got problem with login its giving access violation.. its gonna be hard

old Re: Login System Lua

VADemon
User Off Offline

Quote
@user Marcell to debug an error of this kind: set cs2d cmd logbatch to 1, so printed() lines are wrote immediately to the log file. The next step is to put print()s all around your code so you can find out the point at which your script crashes (which is probably something around interacting with LuaSQL).
Although, when I think about it, you assert()ed pretty much every possible function and it's kinda strange that the game crashes.

old Re: Login System Lua

Marcell
Super User Off Offline

Quote
@user VADemon:

Thanks, so i cannot do anything til that?

Becase then i will upload LUA files to my Cloud, so i can continue project later.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview