Forum

> > CS2D > Scripts > Menu Cooldown
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Menu Cooldown

4 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Menu Cooldown

Ranu
User Off Offline

Zitieren
Hello, How to make a cooldown(anti-spam) for a menu.

For 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
viplist = {160926}

delay = {}

addhook("spawn","ranwspawn")
function ranwspawn(id)
delay[id] = 0
end

addbind("F7")
addhook("key","vipaction")
function vipaction(id,key)
for _, usgn in ipairs(viplist) do
if player(id,'usgn') == usgn then
if key==("F7") then
if player(id,"health") > 0 then
if delay[id] == 0 then
menu(id,"VIP Menu,Spawn Item,Set Health,,,,,,,Close")
delay[id]=delay[id] + 1
end
return 1
end
end
end
end
end

addhook("second","hookminute")
function hookminute()
if delay[id] >= 0 then
delay[id] = 0
end
end
1× editiert, zuletzt 01.05.19 12:51:05

alt Re: Menu Cooldown

Bowlinghead
User 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
viplist = {160926}

delay = {}
maxDelay = 5 -- 5 secs cooldwon

addhook("spawn","ranwspawn")
function ranwspawn(id)
delay[id] = 0
end

addbind("F7")
addhook("key","vipaction")
function vipaction(id,key)
for _, usgn in ipairs(viplist) do
if player(id,'usgn') == usgn then
if key==("F7") then
if player(id,"health") > 0 then
if delay[id] <= 0 then
menu(id,"VIP Menu,Spawn Item,Set Health,,,,,,,Close")
delay[id]=  maxDelay -- set max delay initally
end
return 1
end
end
end
end
end

addhook("second","hooksecbutidc")
function hooksecbutidc()
for k,v in pairs(player(0,"table")) do
	if (delay[v] > 0) then
		delay[v] = delay[v] -1	-- decrease cooldown every second	
							end
end

end


Note that this will cause initial cooldowns with 4,0001 and 5,999 seconds duo to the frequence of the second hook.
The second hook can trigger just after you pressed F7, leaving you with basicly 4 seconds cooldown. To prevent this use miliseconds

alt Re: Menu Cooldown

Mami Tomoe
User Off Offline

Zitieren
Why not use a timer to call a function that allows the usage of the menu for the specific ID?

alt Re: Menu Cooldown

deletemyacc
User 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
KEY_VIPMENU = "F7"
MENU_DELAY = 1		-- in seconds

viplist = {160926}

plr_clock = {}

addhook("join", "join_hook")
function join_hook(id)
	plr_clock[id] = os.clock()
end

addhook("key","key_hook")
function key_hook(id, key, state)
	if (key == KEY_VIPMENU) and (state == 1) then
		for _, usgn in pairs(viplist) do
			if (player(id, "usgn") == usgn) and (player(id, "health") > 0) then
				if (plr_clock[id] <= os.clock()) then
					menu(id,"VIP Menu,Spawn Item,Set Health,,,,,,,Close")
					plr_clock[id] = os.clock() + MENU_DELAY
				end
				break
			end
		end
	end
end

addbind(KEY_VIPMENU)
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht