Forum

> > CS2D > Scripts > Lock buton when
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lock buton when

17 replies
To the start Previous 1 Next To the start

old Lock buton when

Cons
User Off Offline

Quote
Hello again guys, i just need some help with this:

When i press a buton:
1
(id,title,buton)

Then Locks the pressed buton, making that i cant press it again until unlocks pressing another buton...

Please help me

==SOVED==
edited 1×, last 05.03.12 09:56:27 pm

old Re: Lock buton when

EP
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
pressed = {} for i = 1,32 do pressed[i] = false 
addhook("join","a")
function a(id)
pressed[id] = false
end

addhook("serveraction","b")
function b(id,button)
	if button == 1 then
		if pressed[id] == false then
			--YOUR THING HERE
			pressed[id] = true
		end
	end
end
hope it will give you the idea for how to do it

old Re: Lock buton when

Cons
User Off Offline

Quote
user EP has written
hope it will give you the idea for how to do it


Thanks i am gonna try it!

old Re: Lock buton when

EngiN33R
Moderator Off Offline

Quote
You forgot an end at the top after the for loop.

Also, user Cons, is it a menu button or a trigger button?

old Re: Lock buton when

Cons
User Off Offline

Quote
user EngiN33R has written
Also, user Cons, is it a menu button or a trigger button?


Is a Menu buton.

And it didnt work

Please help me to fix 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
addhook("serveraction","dresamenu0")
function dresamenu0(id,act)
if act==1 then
menu(id,"TEST,tab1,tab2")
end
return 1
end


pressed = {} for i = 1,32 do pressed[i] = false
addhook("join","a")
function a(id)
pressed[id] = false
end
end

addhook("menu","dresamenu1")
function dresamenu1(id,title,buton)
if title=="TEST" then
     if b == 1 then
          if pressed[id] == false then
               msg2(id,"©255000000It Works!")
               pressed[id] = true
          end
     end
end
end

old Re: Lock buton when

Anders4000
User Off Offline

Quote
Try 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
addhook("serveraction","dresamenu0")
function dresamenu0(id,act)
	if act==1 then
		menu(id,"TEST,tab1,tab2")
	end
	return 1
end

pressed = {}
for i = 1,32 do
	pressed[i] = false
end

addhook("join","a")
function a(id)
	pressed[id] = false
end

addhook("menu","dresamenu1")
function dresamenu1(id,title,buton)
	if title=="TEST" then
		if b == 1 then
			if pressed[id] == false then
				msg2(id,"©255000000It Works!")
				pressed[id] = true
			end
		end
	end
end

old Re: Lock buton when

EngiN33R
Moderator Off Offline

Quote
@user Anders4000: It's kind of messy, to be more precise - the arguments for the menu 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function dresamenu0(id)
	menu(id,"TEST,tab1,tab2")
end

addhook("serveraction","dresamenu0")
function dresamenu1(id,act)
	if act==1 then
		dresamenu0(id)
	end
	return 1
end

pressed = {}
for i = 1,32 do
	pressed[i] = false
end

addhook("join","a")
function a(id)
	pressed[id] = false
end

addhook("menu","dresamenu1")
function dresamenu2(id,title,b)
	if title=="TEST" then
		if b == 1 then
			if pressed[id] == false then
				msg2(id,"©255000000It Works!")
				pressed[id] = true
			else
				dresamenu0(id)
			end
		end
		if b == 2 then
			if pressed[id] == true then
				msg2(id,"©000255000Turn It Back On!")
				pressed[id] = false
			else
				dresamenu0(id)
			end
		end
	end
end

It's pretty much the same, this thing, just a little bit modified.

old Re: Lock buton when

Cons
User Off Offline

Quote
user Anders4000 has written
Try this:


Yeah it works but, do you know how to really lock the buton, like, show its really locked like levels for example.

1
2
3
4
5
addhook("serveraction","dresamenu0")
function dresamenu0(id,act)
     if act==1 then
if buton == 1 then
menu(id,"Unlock Weapows with Levels,DEAGLE|Level one,TMP|Level two)

Like that, TMP is a two level required weapown, so just show its really locked like you cant click anyway.

This is just an example, i want this for my other script.

old Re: Lock buton when

Cons
User Off Offline

Quote
user EngiN33R has written
@user Anders4000: It's kind of messy, to be more precise - the arguments for the menu function.

It's pretty much the same, this thing, just a little bit modified.


Doesnt work omg

old Re: Lock buton when

EP
User Off Offline

Quote
okey, use an array, its a more secure way:
1
2
3
4
5
6
7
8
9
function Array(size,value) 
    local array = {}
    for i = 1, size do
        array[i]=value
    end
    return array
end pressed = Array(32,false)

addhook("join","a") function a(id) pressed[id] = false end

old Re: Lock buton when

EngiN33R
Moderator 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
function Array(size,value) --nasty function
local array = {}
for i = 1, size do
array[i]=value
end
return array
end

menus = {
	weapon_menu = {
		title = "Weapons",
		buttons = {
			[1] = {
				locked = "(Deagle)|Lvl 1",
				unlocked = "Deagle",
				state = {},
				dstate = false,
				func = function(id)
					parse("equip "..id.." 3")
					menus.weapon_menu.buttons[2].state = false --unlock second button
				end
			},
			[2] = {
				locked = "(TMP)|Lvl 2",
				unlocked = "TMP",
				state = {},
				dstate = true,
				func = function(id)
					parse("equip "..id.." 21")
				end
			}
		}
	}
}

for _,menu in pairs(menus) do
	for _,button in pairs(menu.buttons) do
		button.state=Array(32,button.dstate)
	end
end

function mmenu(id,menu)
	local m=menu.title..","
	for k,b in pairs(menu.buttons) do
		if b.state then
			m=m..b.unlocked
		else
			m=m..b.locked
		end
		if k~=#menu.buttons then
			m=m..","
		end
	end
	menu(id,m)
end

addhook("serveraction","openmenu")
function openmenu(id,a)
	if a==3 then
		mmenu(id,menus.weapon_menu) --syntax
	end
end

I'm not sure if this works, but in theory it should. Also a bit complex, but when you get it it's quite useful.

old Re: Lock buton when

EngiN33R
Moderator Off Offline

Quote
user Cons has written
argh i give up


Well, you just did something one must never do if one is learning. Your decision though. If the script requires further explanation - tell me.

old Re: Lock buton when

Anders4000
User Off Offline

Quote
user EngiN33R has written
...If the script requires further explanation - tell me.

And when Engineer explains... He does it loke a BOSS! Trust me, I know what I'm talking about

old Re: Lock buton when

Cons
User Off Offline

Quote
user EngiN33R has written
If the script requires further explanation - tell me.


Alright, i just want a simple explain to how lock a menu buton when we click on it, and another explain of other buton with a function and that automaticly unlocks it. '-'

old Re: Lock buton when

EngiN33R
Moderator Off Offline

Quote
Code >


The main thing you should be operating with is the upper table. You can see that in there, there's a table for a menu called weapon_menu.

In it, there are two fields - the string title, which is the menu title, and the table buttons, which contains data about its buttons.

In the buttons table, you can see a few values - locked is the text for the locked button, unlocked - for the unlocked, dstate is the default state of the button for all players, func is the function that will be executed when that function will be parsed. The state table is a table that contains the button states for every player - as they may differ from person to person.

The button state is true if it's unlocked and false if it's locked.

Also, the script only supplies the player ID as the argument to the button function, so be wary.

Now, you can see that as an example, I made the first button give you a deagle and unlock the second one.
1
menus.weapon_menu.buttons[2].state[id] = true

menus.weapon_menu - accessing the table of our weapon menu
buttons - accessing the buttons table
[2] - second button
state - state for all players
[id] - state for the player who pressed it
true - unlock

If you still don't understand something - let me know.

old Re: Lock buton when

Cons
User Off Offline

Quote
user EngiN33R has written
Code >


The main thing you should be operating with is the upper table. You can see that in there, there's a table for a menu called weapon_menu.

In it, there are two fields - the string title, which is the menu title, and the table buttons, which contains data about its buttons.

In the buttons table, you can see a few values - locked is the text for the locked button, unlocked - for the unlocked, dstate is the default state of the button for all players, func is the function that will be executed when that function will be parsed. The state table is a table that contains the button states for every player - as they may differ from person to person.

The button state is true if it's unlocked and false if it's locked.

Also, the script only supplies the player ID as the argument to the button function, so be wary.

Now, you can see that as an example, I made the first button give you a deagle and unlock the second one.
1
menus.weapon_menu.buttons[2].state[id] = true


Ahh Thanks Again My hero,you are always saving me

==Problem Soved==

==Topic Closed==
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview