Forum

> > CS2D > Scripts > Adding Usgn to Table
Forums overviewCS2D overview Scripts overviewLog in to reply

English Adding Usgn to Table

11 replies
To the start Previous 1 Next To the start

old Adding Usgn to Table

Cons
User Off Offline

Quote
Hi, i am improving on my script, and everything works, when i type:
1
!admin +usgn
then sucessful add a table on my script, BUT, it adds on a new line like:
1
2
adminlist = {playerUsgn1}
adminlist = {playerUsgn2}

But when this is done, only one of the currents usgn can be the Admin. So what i want is, instead creating a new line, just make a >,< on it, so many people can be Admins, like:
1
adminlist = {playerUsgn1,playerUsgn2}

You know? So i will be very gratefull if you help me

More >


More >


old Re: Adding Usgn to Table

EngiN33R
Moderator 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
39
40
41
42
43
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

function saveToFile()
	local script={}
	File = io.open("maps/users.lua", "r")
	for line in File:lines() do
		if line~="adminlist = {" then
			table.insert(script,line)
		else
			break
		end
	end
	File:close()
	
	File = io.open("maps/users.lua", "w")
	for _,l in pairs(script) do
		File:write(l)
	end
	File:write("\nadminlist = {")
	for k,u in pairs(adminlist) do
		File:write("["..k.."] = "..us)
	end
	File:write("}")
	File:close()
end

addhook("say","dresadd")
function dresadd(id,txt)
	local p = totable(txt)
	local cmd = (p[1])
	if cmd == "!admin" then
		local us = tonumber(p[2])
		table.insert(adminlist,us)
		saveToFile()
	end
end

It would be easier if you saved it to an external file and not the script, but I think the above code should work. It's longer because I save the whole actual script before adding the admin list thing.

old Re: Adding Usgn to Table

Cons
User Off Offline

Quote
@user EngiN33R Dresa: !admin 44092
LUA ERROR: sys/lua/[D]Arena/Dfunc.lua:294: attempt to index global 'File' (a nil value)

Help? '-' pls

old Re: Adding Usgn to Table

Cons
User Off Offline

Quote
user sheeL has written
LUA ERROR: sys/lua/lvl.lua:15: attempt to index global 'File' (a nil value)

line 15 = table.insert(script,line)



Thanks

old Re: Adding Usgn to Table

Cons
User Off Offline

Quote
user EngiN33R has written
How is that possible? The File variable is not used on line 15.


Please if you can, just test it on your sv '-'

old Re: Adding Usgn to Table

sheeL
User Playing CS2D

Quote
user Cons has written
user EngiN33R has written
How is that possible? The File variable is not used on line 15.


Please if you can, just test it on your sv '-'


use

More >

old Re: Adding Usgn to Table

EngiN33R
Moderator Off Offline

Quote
Code >


This works perfectly on my server.

old Re: Adding Usgn to Table

Jhony
User Off Offline

Quote
user Cons has written
user EngiN33R has written
This works perfectly on my server.


In mine too! Thanks again @user EngiN33R: you re the best


no , no works

look the error
1
LUA ERROR: sys/lua/adv.lua:13: attempt to index local 'File' (a nil value)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview