Forum

> > CS2D > Scripts > Timer issue.
Forums overviewCS2D overview Scripts overviewLog in to reply

English Timer issue.

14 replies
To the start Previous 1 Next To the start

old Timer issue.

Mami Tomoe
User Playing CS2D

Quote
1
timer(time,unmute(pl))

This timer should have the time as "time" from this:
1
local time = tonumber(p[3])

And to send it to a function after the time is over...
(Some kind of a mute script)

old Re: Timer issue.

Mami Tomoe
User Playing CS2D

Quote
I seem to still have a problem.
Here's the command code and the function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
elseif cmd == "!mute" then
				if rp_Adminlevel[id] >= 2 then
					local pl = tonumber(p[2])
					local time = tonumber(p[3])
					if pl ~= nil then
						if time ~= nil then
							if time <= 3600 then
								if player(pl,"exists") then
									if 	rp_mute[pl] == false then
									gmsg("255255000","[Server]: \169255000000"..player(id,"name").." has muted "..player(pl,"name").." for "..time.." seconds.")
									rp_mute[pl]=true
									timer(time,"unmute",pl)
									end
								end
							else
							gmsg2(id,"255255000","[Server]: \169255000000You can't enter more than 1 hour.")
							end
						else
						gmsg2(id,"255255000","[Server]: \169255000000You need to enter time.")	
						end
					end
				else
				gmsg2(id,"255255000","[Server]: \169255000000You don't have permission.")	
				end
1
2
3
4
5
6
7
8
9
10
function unmute(pl)
	if pl ~= nil then
		if player(pl,"exists") then
			if 	rp_mute[pl] == true then
				gmsg("255255000","[Server]: \169000255000"..player(pl,"name").." is no longer muted.")
				rp_mute[pl]=false
			end
		end
	end
end

old Re: Timer issue.

Gaios
Reviewer Off Offline

Quote
Maybe in unmute function do local pl = tonumber(pl) at the start.
Anyway this algorithm is bad because of if player leave a server and there won't any player with ID that was send in timer function, will generate error that this user doesn't exist. Better to use os.time and save its to a variable of specific player.

Send me here a part of the code with say and leave hook only. I will try to change there something.
edited 1×, last 19.10.15 06:13:10 pm

old Re: Timer issue.

Mami Tomoe
User Playing CS2D

Quote
The time seems to work but I can't convert it from milliseconds to seconds... I tried adding this:
1
2
time=time*10
timer(time,"unmute",pl)
It didn't worked... Since I don't know if its possible to use * to multiple in lua I made it longer like that:
1
2
time=time+time+time+time+time+time+time+time+time+time
timer(time,"unmute",pl)
It didn't worked either so I added time2 to make it more... Understandable I guess...
1
2
time2=time+time+time+time+time+time+time+time+time+time
timer(time2,"unmute",pl)

None worked... Stays as milliseconds.
Any help will be grateful.

old Re: Timer issue.

Mami Tomoe
User Playing CS2D

Quote
@user VADemon: Thanks it worked, guess I haven't used milliseconds in a while so I forgot their meanings, silly me

I have another problem with a different script.
I don't think I should create a new topic for it though, here's the problem, when I type !vm hello, all VIPs online should see: Player: Hello but they see Player: !vm Hello instead.
I want to remove the command from the script.
Here's the command:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
elseif cmd == "!vm" then
			local text = tostring(p[2])
				if text ~= nil then
					if rp_Adminlevel[id]== 0 and rp_vip[id]== 1 then
						for pl = 1,32 do
							if rp_vip[pl]==1 and rp_Adminlevel[pl]==0 then
								if string.sub(txt, #txt-1,#txt) == "!vm" then
								txt = string.sub(txt, 1, #txt-2)
								msg2(id,"\169128128128VM | "..player(id,"name")..": "..txt)
								end
							end
						else
						gmsg2(id,"255255000","[Server]: \169255000000You don't have permission.")
						end
					end
				end
			end

Edit: Still can't solve it :c
edited 1×, last 21.10.15 03:01:44 pm

old Re: Timer issue.

_Yank
User Off Offline

Quote
@user Mami Tomoe: Do you even know how string.sub works ?
1
2
3
4
5
6
7
8
9
10
11
12
13
local text = "!vm Hello dude"
-- If you want to get the first 3 characters you do it like this
string.sub(text, 1, 3) -- Returns "!vm" as it starts from the 1st character (!) and ends on the 3rd character (m).

-- So if you want to get the further text,
string.sub(5, #text) -- Returns "Hello dude" as it starts from the 5th character (H) and ends on the last character (e) (in this case, the string length, that you can get by using #)

-- Note that spaces also count as characters

-- Another example:
myVar = "Hello world"
string.sub(myVar, 1, 5) -- Hello
string.sub(myVar, 7,  11) -- world

old Re: Timer issue.

Mami Tomoe
User Playing CS2D

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
elseif cmd == "!vm" then
				if rp_Adminlevel[id]<= 0 and rp_vip[id]>= 1 then
				local txt = tostring(p[2])
					if txt ~= nil then
					txt = string.sub(txt, 1, 3)
						for pl = 1,32 do
							if rp_vip[pl]==1 and rp_Adminlevel[pl]==0 then
								if string.sub(txt, #txt-1,#txt) == "!vm" then
									msg2(id,"\169128128128VM | "..player(id,"name")..": "..txt)
								end
							end
						end
					end
				else
				gmsg2(id,"255255000","[Server]: \169255000000You don't have permission.")
				end

I tried this and the permission message works but when I do have permission it wont show anything (the msg2 thing should be shown to all VIPs)

pls
Edit: very pls?
edited 1×, last 24.10.15 06:00:01 pm

old Re: Timer issue.

Gaios
Reviewer Off Offline

Quote
Shall works
for _, i in pairs(player(0,'table')) do
	if rp_vip[i] == 1 then
		msg2(i,"\169128128128VM | "..player(id,"name")..": "..txt)
	end
end

old Re: Timer issue.

Mami Tomoe
User Playing CS2D

Quote
@user Gaios:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
elseif cmd == "!vm" then
				for _, i in pairs(player(0,'table')) do
					if rp_Adminlevel[i]<= 0 and rp_vip[i]>= 1 then
					local txt = tostring(p[2])
						if txt ~= nil then
						txt = string.sub(txt, 1, 3)
							for pl = 1,32 do
								if rp_vip[pl]==1 and rp_Adminlevel[pl]==0 then
									if string.sub(txt, #txt-1,#txt) == "!vm" then
										msg2(i,"\169128128128VM | "..player(i,"name")..": "..txt)
									end
								end
							end
						end
					else
					rp_msg2(i,"255255000","[Server]: \169255000000You don't have permission.")
					end
				end

I did this but there's the same problem, when I say
!vm hi
As a admin it wont allow it and will show no permission message (good!)
BUT
when I'm vip and say
!vm hi
nothing appears not in the console and not in the server.

old Re: Timer issue.

Gaios
Reviewer Off Offline

Quote
No way, I didn't notice that your alghoritm is retarded . I will help you later. You may use new Command Engine.

old Re: Timer issue.

Mami Tomoe
User Playing CS2D

Quote
@user Gaios: Oh but I'm fine with the one I already have.

All I need is when a VIP says !vm <msg> it will send to all VIPs online that message he sent without the !vm in the text.

And only VIPs can use it, not admins.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview