Lua Error
23 repliesCode:
1
for _, usgn in ipairs(sys/lua/usgns/"..player(id,"usgn")..".txt"") do
You haven't closed quotes properly. Append this fix.
Code:
1
for _, usgn in ipairs("sys/lua/usgns/"..player(id,"usgn")..".txt") do

Code:
1
for _, usgn in ipairs(sys/lua/usgns/"..player(id,"usgn")..".txt"") do
You haven't closed quotes properly. Append this fix.
Code:
1
for _, usgn in ipairs("sys/lua/usgns/"..player(id,"usgn")..".txt") do
New ERROR D=
LUA ERROR: sys/lua/userxd.lua:48: bad argument #1 to 'ipairs' (table expected, got string)
Make sure you've totally restarted your CS2D server. Try using dedicated version. That error is very odd and it keeps confusing Lua coders for a long time.

Make sure you've totally restarted your CS2D server. Try using dedicated version. That error is very odd and it keeps confusing Lua coders for a long time.
When Start the server
No Have error in console
when press the button F2 ( Action 1 )
Appears the error in console :
LUA ERROR: sys/lua/userxd.lua:48: bad argument #1 to 'ipairs' (table expected, got string)
Code:
1
2
3
4
5
2
3
4
5
for _, usgn in ipairs(sys/lua/usgns/"..player(id,"usgn")..".txt"") do
if act == 1 then -- F2
menu(id,"Menu,lol")
end
end
if act == 1 then -- F2
menu(id,"Menu,lol")
end
end
Doesn't make sense, are you trying to show the menu to everyone or just a single player?
If it's a single player simply remove the for statement like so:
Code:
1
2
3
2
3
if act == 1 then -- F2
menu(id,"Menu,lol")
end
menu(id,"Menu,lol")
end
If it's to everyone replace ID with 0:
Code:
1
2
3
2
3
if act == 1 then -- F2
menu(0,"Menu,lol")
end
menu(0,"Menu,lol")
end

Code:
1
2
3
4
5
2
3
4
5
for _, usgn in ipairs(sys/lua/usgns/"..player(id,"usgn")..".txt"") do
if act == 1 then -- F2
menu(id,"Menu,lol")
end
end
if act == 1 then -- F2
menu(id,"Menu,lol")
end
end
Doesn't make sense, are you trying to show the menu to everyone or just a single player?
If it's a single player simply remove the for statement like so:
Code:
1
2
3
2
3
if act == 1 then -- F2
menu(id,"Menu,lol")
end
menu(id,"Menu,lol")
end
If it's to everyone replace ID with 0:
Code:
1
2
3
2
3
if act == 1 then -- F2
menu(0,"Menu,lol")
end
menu(0,"Menu,lol")
end
That's not what I want
read the topic again
If you can not explain you problem, none of us can help you. If you're going to be rude, I'm not going to help you.

If you can not explain you problem, none of us can help you. If you're going to be rude, I'm not going to help you.
When player join in server
if the usgn of player is puted in USGNS folder (sys/lua/usgns)
he can open the menu
if usgn NOT puted
he can not open the menu
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--Replace these parts
addhook("serveraction","_serveraction")
addhook("serveraction","update")
function update(id,act)
if fileExists("sys/lua/usgns/"..player(id,"usgn")..".txt") then
if act == 1 then -- F2
menu(id,"Menu,lol")
end
end
end
--Add this part
function fileExists(location)
local f=io.open(location)
if f~=nil then
io.close(f)
end
return f~=nil
end
addhook("serveraction","_serveraction")
addhook("serveraction","update")
function update(id,act)
if fileExists("sys/lua/usgns/"..player(id,"usgn")..".txt") then
if act == 1 then -- F2
menu(id,"Menu,lol")
end
end
end
--Add this part
function fileExists(location)
local f=io.open(location)
if f~=nil then
io.close(f)
end
return f~=nil
end

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--Replace these parts
addhook("serveraction","_serveraction")
addhook("serveraction","update")
function update(id,act)
if fileExists("sys/lua/usgns/"..player(id,"usgn")..".txt") then
if act == 1 then -- F2
menu(id,"Menu,lol")
end
end
end
--Add this part
function fileExists(location)
local f=io.open(location)
if f~=nil then
io.close(f)
end
return f~=nil
end
addhook("serveraction","_serveraction")
addhook("serveraction","update")
function update(id,act)
if fileExists("sys/lua/usgns/"..player(id,"usgn")..".txt") then
if act == 1 then -- F2
menu(id,"Menu,lol")
end
end
end
--Add this part
function fileExists(location)
local f=io.open(location)
if f~=nil then
io.close(f)
end
return f~=nil
end
Code:
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function readfile(filelocation, linenum)
savestr = {}
saveline=1
for line in io.lines(filelocation) do
savestr[saveline]=line
saveline=saveline+1
end
return savestr[linenum]
end
function totable(t,match)
local cmd = {}
if not match then match = "[^%s]+" end
for word in string.gmatch(t, match) do
table.insert(cmd, word)
end
return cmd
end
addhook("say","a")
function a(id,txt)
local p = totable(txt)
local cmd = (p[1])
if cmd == "@give" then
local us = tonumber(p[2])
if us > 0 then
File = io.open("sys/lua/usgns/"..us..".txt", "a")
return 1
end
return 1
end
end
addhook("join","save_join") -- When join load
function save_join(id)
if player(id,"usgn") > 0 then
local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
local file = io.open(filename)
if file then
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
end
end
addhook("serveraction","update")
function update(id,act)
if fileExists("sys/lua/usgns/"..player(id,"usgn")..".txt") then
if act == 1 then -- F2
menu(0,"Menu,lol")
end
end
end
addhook("menu","menus")
function menus(id,t,b)
if t == "Menu" then
if b == 1 then
msg2(id,"Works!")
end
end
end
function fileExists(location)
local f=io.open(location)
if f~=nil then
io.close(f)
end
return f~=nil
end
savestr = {}
saveline=1
for line in io.lines(filelocation) do
savestr[saveline]=line
saveline=saveline+1
end
return savestr[linenum]
end
function totable(t,match)
local cmd = {}
if not match then match = "[^%s]+" end
for word in string.gmatch(t, match) do
table.insert(cmd, word)
end
return cmd
end
addhook("say","a")
function a(id,txt)
local p = totable(txt)
local cmd = (p[1])
if cmd == "@give" then
local us = tonumber(p[2])
if us > 0 then
File = io.open("sys/lua/usgns/"..us..".txt", "a")
return 1
end
return 1
end
end
addhook("join","save_join") -- When join load
function save_join(id)
if player(id,"usgn") > 0 then
local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
local file = io.open(filename)
if file then
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
end
end
addhook("serveraction","update")
function update(id,act)
if fileExists("sys/lua/usgns/"..player(id,"usgn")..".txt") then
if act == 1 then -- F2
menu(0,"Menu,lol")
end
end
end
addhook("menu","menus")
function menus(id,t,b)
if t == "Menu" then
if b == 1 then
msg2(id,"Works!")
end
end
end
function fileExists(location)
local f=io.open(location)
if f~=nil then
io.close(f)
end
return f~=nil
end
Yeah, Works but have error in console , if usgn puted
when press F2 , the menu appears , but when press F2
appears error in console :
LUA ERROR: sys/lua/userxd.lua:4: bad argument #1 to 'lines' (string expected, got userdata)
This error does something?
Well since /usgns/89367.txt is empty,
Can't read properly, it seems you are trying to create a save system, however you give does nothing but create the file.
Code:
1
2
2
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
VALUE[id] = readfile(file, 2) --same but in the line 2
Can't read properly, it seems you are trying to create a save system, however you give does nothing but create the file.

Well since /usgns/89367.txt is empty,
Can't read properly, it seems you are trying to create a save system, however you give does nothing but create the file.
Code:
1
2
2
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
VALUE[id] = readfile(file, 2) --same but in the line 2
Can't read properly, it seems you are trying to create a save system, however you give does nothing but create the file.
No offense
not want to create anything within USGNS/89367
but if it is empty, with nothing
this hurts, I keep it empty?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I Deleted the line :
Code:
1
2
3
4
2
3
4
if file then
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
and works
solved

Since you don't want to load anything simply remove
Code:
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
addhook("join","save_join") -- When join load
function save_join(id)
if player(id,"usgn") > 0 then
local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
local file = io.open(filename)
if file then
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
end
end
function save_join(id)
if player(id,"usgn") > 0 then
local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
local file = io.open(filename)
if file then
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
end
end

Since you don't want to load anything simply remove
Code:
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
addhook("join","save_join") -- When join load
function save_join(id)
if player(id,"usgn") > 0 then
local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
local file = io.open(filename)
if file then
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
end
end
function save_join(id)
if player(id,"usgn") > 0 then
local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
local file = io.open(filename)
if file then
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
end
end
no no no no no @

Code:
1
2
3
4
2
3
4
if file then
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
Works



Since you don't want to load anything simply remove
Code:
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
addhook("join","save_join") -- When join load
function save_join(id)
if player(id,"usgn") > 0 then
local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
local file = io.open(filename)
if file then
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
end
end
function save_join(id)
if player(id,"usgn") > 0 then
local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
local file = io.open(filename)
if file then
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
end
end
no no no no no @

Code:
1
2
3
4
2
3
4
if file then
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
end
Works

Thanks @

you help i
SOLVED
@
sheeL: Well since there is nothing else in the join hook it is much better just to remove all of it. Less hooks = faster and more efficient.


@
sheeL: Well since there is nothing else in the join hook it is much better just to remove all of it. Less hooks = faster and more efficient.

He did not want to read a file (read out, what's inside the file)
he only wants USGN is run when the player enters the server
@

sorry for my english
~~
Code:
1
2
3
4
5
6
7
2
3
4
5
6
7
addhook("join","save_join") -- When join load
function save_join(id)
if player(id,"usgn") > 0 then
local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
local file = io.open(filename)
end
end
function save_join(id)
if player(id,"usgn") > 0 then
local filename = "sys/lua/usgns/"..player(id,"usgn")..".txt"
local file = io.open(filename)
end
end
Line Deleted
Code:
1
2
2
VALUE[id] = readfile(file, 1) --read a value in the line 1
VALUE[id] = readfile(file, 2) --same but in the line 2
VALUE[id] = readfile(file, 2) --same but in the line 2
edited 1×, last 21.04.12 01:28:54 am
Well if you look closely at the join hook it does nothing but read 2 values. Since you don't need to read anything, or check if the file exists you can remove it all together.

Well if you look closely at the join hook it does nothing but read 2 values. Since you don't need to read anything, or check if the file exists you can remove it all together.
Further loading of the players USGN
we must gain a hook "join" to do this
to delete everything, it would be necessary to change a map
to load