Forum

> > CS2D > Scripts > Mute with minute
Forums overviewCS2D overview Scripts overviewLog in to reply

English Mute with minute

14 replies
To the start Previous 1 Next To the start

old Mute with minute

limonata
User Off Offline

Quote
Hello guys can you do this script ?

!mute [id] [minute]
------------------------------

!mute 2 9 --> ID 2 muted for 9 minute.

!mute 2 --> ID 2 no longer muted.

Thanks.

old Re: Mute with minute

gotya2
GAME 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
34
35
36
37
38
39
40
41
42
43
44
45
mute = {}


function split(str, pat)
   local t = {}
   local fpat = "(.-)" .. pat
   local last_end = 1
   local s, e, cap = str:find(fpat, 1)
   while s do
      if s ~= 1 or cap ~= "" then
	 table.insert(t,cap)
      end
      last_end = e+1
      s, e, cap = str:find(fpat, last_end)
   end
   if last_end <= #str then
      cap = str:sub(last_end)
      table.insert(t, cap)
   end
   return t
end


function unmute(id)
	local id = tonumber(id)
	mute[id] = false
end

addhook("say","_say")
function _say(id,txt)
	if mute[id] then return 1

	else
		local t = split(txt," ")
		if t[1] == "!mute" and #t == 3 then
			local id = tonumber(t[2])
			local minutes = tonumber(t[3])
			mute[id] = true


			timer(minutes * 1000 * 60, "unmute",""..id,1)

		end
	end
end

u could enhance it by muting on ip instead of id, and fixing when player leaves/joins. But i leave that as an exercise for you...

old Re: Mute with minute

limonata
User Off Offline

Quote
Thank you so much

Man, It isnt work. I used !mute 2 2 but he can write
also it should be for admins and there is no any message like ..... muted for ... minute

Can somebody help me ?
edited 2×, last 29.01.13 04:39:47 pm

old Re: Mute with minute

Alistaire
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
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
function array(b)
	local a = {}
	for i = 1, 32 do
		a[i] = b
	end
	return a
end

function splitString(string)
	local c = {}
	for word in string.gmatch(string, '[^%s]+') do
		table.insert(c, word)
	end
	return c
end

plr = {}
plr.mute = array(0)
plr.admin = {
	[usgn1] = 1,
	[usgn2] = 1,
	[usgn3] = 1
}		--// Write USGN's here

addhook('say', '_sayFunc')
addhook('second', '_secondFunc')

function _muteFunc(id, time)
	if not time then
		plr.mute[id] = 0
		return 1
	else
		plr.mute[id] = time * 60
		return 2
	end
end

function _secondFunc()
	for _, id in pairs(player(0, 'tableliving')) do
		if plr.mute[id] > 0 then
			plr.mute[id] = plr.mute[id] - 1
		end
	end
end

function _sayFunc(id, msg)
	if plr.mute[id] == 0 then
		--// Saycommands
		local a = splitString(msg)
		if string.sub(a[1], 1, 1) == '!' then
			if plr.admin[player(id, 'usgn')] then	--// All admin functions
				if string.upper(string.sub(a[1], 2, string.len(a[1]))) == 'MUTE' then		--// Mute syntax
					local b = _muteFunc(a[2], a[3])
					if b == 1 then
						print(player(id, 'name')..'('..player(id,'usgn')..'): muted '..player(a[2], 'name')..'('..player(a[2], 'usgn')..') for '..a[3]..' minutes.')
					elseif b == 2 then
						print(player(id, 'name')..'('..player(id,'usgn')..'): unmuted '..player(a[2], 'name')..'('..player(a[2], 'usgn')..')')
					end
				end
			end
			--// All non-admin functions
			return 1
		end
	else
		return 1
	end
end
edited 3×, last 30.01.13 05:20:26 pm

old Re: Mute with minute

limonata
User Off Offline

Quote
There is a Error LUA ERROR: sys/lua/olric.lua:36: attempt to compare number with nil

Line 36: if plr.mute[id] > 0 then


And I change here like plr.admin = {50998} --> is it true?

old Re: Mute with minute

Alistaire
User Off Offline

Quote
user limonata has written
There is a Error LUA ERROR: sys/lua/olric.lua:36: attempt to compare number with nil

Line 36: if plr.mute[id] > 0 then


And I change here like plr.admin = {50998} --> is it true?


Is the error only once? And that admin table should be in the same way it is now. Add usgn's on the usgn1 etc places.

old Re: Mute with minute

limonata
User Off Offline

Quote
I wrote my usgn in [usgn1] also I filled [usgn2] and [usgn3] it didnt give error. But now

U.S.G.N.: Ping/State 'idle' (240 ms)
starting server...
load map 'aim_shotgun'
----- Server started -----
Lua: Adding function '_sayFunc' to hook 'say'
Lua: Adding function '_secondFunc' to hook 'second'
Lua: Adding function 'eq' to hook 'startround'
Lua: Adding function 'fastreload' to hook 'reload'
LUA ERROR: sys/lua/mute.lua:39: attempt to compare number with nil
U.S.G.N.: Sending serverlist ADD-request...
U.S.G.N.: Ping/State 'playing'
U.S.G.N.: Server added to serverlist
LUA ERROR: sys/lua/mute.lua:39: attempt to compare number with nil
LUA ERROR: sys/lua/mute.lua:39: attempt to compare number with nil
LUA ERROR: sys/lua/mute.lua:39: attempt to compare number with nil

My console is full with this error.

old Re: Mute with minute

EngiN33R
Moderator Off Offline

Quote
Well, of course this won't work, id isn't defined in the _secondFunc function. You need to replace it with this:

1
2
3
4
5
6
7
function _secondFunc()
     for _,id in pairs(player(0,"table")) do
          if plr.mute[id] > 0 then
               plr.mute[id] = plr.mute[id] - 1
          end
     end
end

old Re: Mute with minute

limonata
User Off Offline

Quote
Engineer thank you. Now there isn't any error. But I tested lua. I wrote !mute 3 2 and the error is:

LUA ERROR: sys/lua/olric.lua:52: attempt to call field 'uppercase' (a nil value)

Line 52: if string.uppercase(string.sub(a[1], 2, string.len(a[1]))) == 'MUTE' then


Thank you all for helping but I will be happy if you dont give codes without test.

old Re: Mute with minute

Alistaire
User Off Offline

Quote
user limonata has written
Engineer thank you. Now there isn't any error. But I tested lua. I wrote !mute 3 2 and the error is:

LUA ERROR: sys/lua/olric.lua:52: attempt to call field 'uppercase' (a nil value)

Line 52: if string.uppercase(string.sub(a[1], 2, string.len(a[1]))) == 'MUTE' then


Thank you all for helping but I will be happy if you dont give codes without test.


Take the script from my comment with code in it. It's been updated several times.

old Re: Mute with minute

limonata
User Off Offline

Quote
I am testing with bots. Bot's ID was 2 i wrote

!mute 2 4 and there is this error

LUA ERROR: sys/lua/mute.lua:57: attempt to index local 'a' (a number value)

Line 57:
print(player(id, 'name')..'('..player(id,'usgn')..'): unmuted '..player(a[2], 'name')..'('..player(a[2], 'usgn')..')')

old Re: Mute with minute

Alistaire
User Off Offline

Quote
user limonata has written
I am testing with bots. Bot's ID was 2 i wrote

!mute 2 4 and there is this error

LUA ERROR: sys/lua/mute.lua:57: attempt to index local 'a' (a number value)

Line 57:
print(player(id, 'name')..'('..player(id,'usgn')..'): unmuted '..player(a[2], 'name')..'('..player(a[2], 'usgn')..')')


*try the new script, I updated it.

old Re: Mute with minute

limonata
User Off Offline

Quote
I opened two game. First game I joined with my usgn so i can use mute, in second game I closed my usgn. (ID 2 is other game no usgn)

I wrote !mute 2 6

It printed in console:

CA # limon ~ *(50998): unmuted CA # limon ~ * 2(0)

But I was writing.
So doesnt work dude Also there is no any message it should be write.

CA # limon ~ * muted for 6 minutes.

Dude if you cant do. Its enought, thanks for your help I can ask another.

old Re: Mute with minute

sheeL
User Playing CS2D

Quote
Like this?!
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
function Split(string)
     local c = {}
     for word in string.gmatch(string, '[^%s]+') do
          table.insert(c, word)
     end
     return c
end
muted = {} for a = 1,32 do muted[a] = false end
admins = {12345,54321,xxxxx} -- your usgn here
addhook("say","OnSay")
function OnSay(id,text)
local id = tonumber(id) -- debug
if muted[id] == true then
	msg2(id,"©255000000[ERROR] You Are Muted !")
	return 1
end
local i = Split(text)
for _, k in ipairs(admins) do
if player(id,"usgn") == k then
if i[1] == "!mute" then
	local param = tonumber(i[2])
	local mintime = tonumber(i[3])
		if (muted[param]==false) then
		msg("©255255255> "..player(id,"name").." muted "..player(param,"name").." for "..mintime.." Minute(s) !")
			muted[param] = true
				timer(mintime * 1000 * 60, "unp",""..param)
					return 1
				else
					muted[param] = false
				msg("©255255255> "..player(id,'name').." unmuted "..player(param,"name"))
				end
				return 1
			end
		end
	end
end

addhook("join","OnPlayer")
addhook("leave","OnPlayer")
function OnPlayer(id)
	muted[id] = false
end
function unp(v)
v = tonumber(v) -- debug
	msg2(v,"You are UnMuted !")
muted[v] = false
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview