Forum

> > CS2D > Scripts > Adding Usgn to Table
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Adding Usgn to Table

11 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Adding Usgn to Table

Cons
User Off Offline

Zitieren
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

Mehr >


Mehr >


alt Re: Adding Usgn to Table

EngiN33R
Moderator Off Offline

Zitieren
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.

alt Re: Adding Usgn to Table

sheeL
User Off Offline

Zitieren
LUA ERROR: sys/lua/lvl.lua:15: attempt to index global 'File' (a nil value)

line 15 = table.insert(script,line)

alt Re: Adding Usgn to Table

Cons
User Off Offline

Zitieren
user sheeL hat geschrieben
LUA ERROR: sys/lua/lvl.lua:15: attempt to index global 'File' (a nil value)

line 15 = table.insert(script,line)



Thanks

alt Re: Adding Usgn to Table

Cons
User Off Offline

Zitieren
user EngiN33R hat geschrieben
How is that possible? The File variable is not used on line 15.


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

alt Re: Adding Usgn to Table

sheeL
User Off Offline

Zitieren
user Cons hat geschrieben
user EngiN33R hat geschrieben
How is that possible? The File variable is not used on line 15.


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


use

Mehr >

alt Re: Adding Usgn to Table

EngiN33R
Moderator Off Offline

Zitieren
Code >


This works perfectly on my server.

alt Re: Adding Usgn to Table

Jhony
User Off Offline

Zitieren
user Cons hat geschrieben
user EngiN33R hat geschrieben
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)
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht