English Menu Cooldown

4 replies
Goto Page
To the start Previous 1 Next To the start
01.05.19 11:46:15 am
Up
Ranw-X
User
Offline Off
Hello, How to make a cooldown(anti-spam) for a menu.

For this:-
Code:
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
edited 1×, last 01.05.19 12:51:05 pm
VTA Community Discord: https://discord.gg/6rHKWvJ
01.05.19 01:31:36 pm
Up
Bowlinghead
User
Offline Off
Code:
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
Share time limited free games here
01.05.19 01:42:55 pm
Up
Goo
User
Offline Off
Why not use a timer to call a function that allows the usage of the menu for the specific ID?
01.05.19 02:58:59 pm
Up
deletemyacc
User
Offline Off
Code:
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)
01.05.19 03:10:55 pm
Up
Ranw-X
User
Offline Off
Well, Thanks guys
VTA Community Discord: https://discord.gg/6rHKWvJ
To the start Previous 1 Next To the start