Forum

> > CS2D > Scripts > Lua Error
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Error

9 replies
To the start Previous 1 Next To the start

old Lua Error

limonata
User Off Offline

Quote
LUA ERROR: sys/lua/ca3.lua:69: attempt to compare number with nil

Line 69:
1
if muted[id]>0 then

1
2
3
4
5
6
7
8
addhook("minute","mutesec")
function mutesec()
for id=1,32 do
if muted[id]>0 then
muted[id]=muted[id]-1
end
end
end

Hello guys I have a mute script it works like this
!mute <id> <minute> when the times up this error appears Please helpme. I want to a msg like " You are unmuted now!"

Here is the codes for this message but doesnt work
1
2
3
4
5
6
7
8
9
10
11
addhook("join","OnPlayer")
addhook("leave","OnPlayer")
function OnPlayer(id)
     muted[id] = 0
end

function unp(v)
v = tonumber(v) -- debug
     msg2(v,"You are UnMuted !")
muted[v] = 0
end
And mute script is here:
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function Split(stringl)
local c = {}
for word in string.gmatch(stringl, '[^%s]+') do
table.insert(c, word)
end
return c
end
muted = {}

admins = {50998}

addhook("minute","mutesec")
function mutesec()
for id=1,32 do
if muted[id]>0 then
muted[id]=muted[id]-1
end
end
end

function isAdmin(id)
     for _, usgn in ipairs(admins) do
          if player(id,'usgn')== usgn then
               return true
          end
     end
     return false
end


addhook("say","adminsay")
function adminsay(id,txt)
for i=1,#admins do
if (player(id,"usgn")==admins[i]) then
          local id = tonumber(id) -- debug
local i = Split(txt)
local param = tonumber(i[2])
local mintime = tonumber(i[3])
if isAdmin(id) then
if i[1] == "!mute" then
            if mintime == nil and muted[param] == 0 then 
                muted[param] = 10000
                msg("©200000000"..player(param,"name").." Muted forever")
                return 1
            elseif mintime == nil and muted[param] > 0 then
                muted[param] = 0
                msg("©200000000"..player(param,"name").." Unmuted")
                return 1
            elseif mintime > 0 and muted[param] == 0 then
                msg("©200000000"..player(param,"name").." muted for "..mintime.." minutes")
                
                muted[param] = mintime
                return 1
            else
                muted[param] = 0
                msg("©200000000"..player(param,"name").." Unmuted")
               return 1
            end
end
    end
          end
          end
		  if muted[id] == 10000 then
		  msg2(id,"©255000000You muted forever")
		  return 1
elseif muted[id] > 0 then
msg2(id,"©255000000You muted you cant write for"..muted[id].." minutes!")
return 1
else
for _, usgn in ipairs(admins) do
if player(id,'usgn') == usgn then
msg("©255000060"..player(id,"name").." : "..txt)
return 1
end
end
end
addhook("join","OnPlayer")
addhook("leave","OnPlayer")
function OnPlayer(id)
     muted[id] = 0
end

function unp(v)
v = tonumber(v) -- debug
     msg2(v,"You are UnMuted !")
muted[v] = 0
end

old Re: Lua Error

Flacko
User Off Offline

Quote
Add
1
2
3
for i=1,32 do
	muted[i] = 0
end
After
1
muted = {}

old Re: Lua Error

Avo
User Off Offline

Quote
You can add this at beginning of script
1
2
3
4
5
6
7
8
array=function(m, v)
	if not v then v = 0 end
	local t = {}
	for i = 1, m do
		t[i] = v
	end
	return t
end
and use
1
muted = array(32, 0)

old Re: Lua Error

limonata
User Off Offline

Quote
@user Avo: Your code didnt help me

@user Flacko: LUA ERROR: sys/lua/ca3.lua:50: attempt to index global 'muted' (a nil value)

Line 50:
1
muted[i] = 0

old Re: Lua Error

Flacko
User Off Offline

Quote
I told you to put that snippet after you declared muted. Please do so. You've pasted it in the wrong place.

old Like this

Gajos
BANNED 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
adminsList = {1,108942}
moderatorsList = {}
membersList = {}

mute = {}
Player = {}
addhook("join","mute.join")
addhook("say","mute.say")

function mute.join(id)
	Player[id] = {}
	Player[id].level = 0
	Player[id].mute = 0
	for _, i in pairs(adminsList) do
		if player(id,"usgn") == i then
			Player[id].level = 3
		end
	end
	for _, i in pairs(moderatorsList) do
		if player(id,"usgn") == i then
			Player[id].level = 2
		end
	end
	for _, i in pairs(membersList) do
		if player(id,"usgn") == i then
			Player[id].level = 1
		end
	end
end

function mute.say(id,txt)
	return 0
end

I'll add more later.

old Re: Lua Error

limonata
User Off Offline

Quote
@user Flacko: pff :S I couldn't find to where I should put the your code, i gave the lua please edit it.

@user Gajos: Sorry I dont understand what did u do ?
edited 1×, last 23.02.13 11:07:20 am

old Re: Lua Error

Avo
User Off Offline

Quote
Quote
please edit it.


You won't learn anything if you even don't try tu understand what Flacko already said. Unless you declare muted with all 32 values properly(before using), your script won't work. You should use tabs to make script looking more clearly btw.

old Re: Lua Error

Flacko
User Off Offline

Quote
user Avo has written
Quote
please edit it.


You won't learn anything if you even don't try tu understand what Flacko already said. Unless you declare muted with all 32 values properly(before using), your script won't work. You should use tabs to make script looking more clearly btw.

Indeed, I won't dare to touch that script as long as it remains without tabs.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview