Forum

> > CS2D > Scripts > Menu Disappears
Forums overviewCS2D overview Scripts overviewLog in to reply

English Menu Disappears

8 replies
To the start Previous 1 Next To the start

old Menu Disappears

Dovahkin
User Off Offline

Quote
Hello! How can I make a script that whenever I press something the choice disappears. Example :
1
menu(id,"Container,Take coins,Take garbage")
But when I press the "Take Coins" How do I make it disappear on the choices? After I presses the "take coins" it must be like this
1
menu(id,"Container,,Take garbage")

old Re: Menu Disappears

Livia
User Off Offline

Quote
You can store the buttons in a table and remove/modify the values when user makes his selection. Then you'll generate a string for your new menu based on this table.

old Re: Menu Disappears

EngiN33R
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
menutbl = {"Take coins","Take garbage"}

addhook("serveraction","openmenu")
function openmenu(id,a)
	if (a == 1) then
		menu(id,"Container,"..table.concat(menutbl,","))
	end
end

addhook("menu","selectinmenu")
function selectinmenu(id,title,b)
	if (title == "Container") then
		menutbl[b] = ""
		menu(id,"Container,"..table.concat(menutbl,","))
	end
end

This is the general structure of how this could be done. When you press F2, you open the menu, and upon pressing each button, the button disappears and the updated menu reopens.

old Re: Menu Disappears

Dovahkin
User Off Offline

Quote
Oh my. This is fantastic. Thank you.

EDIT!

Whenever I press the button it gives me an error.

The error :
1
server.lua:13: table index is nil

Still the same code that you used @user EngiN33R:
edited 3×, last 04.10.13 05:31:27 pm

old Re: Menu Disappears

pbeloto
User Off Offline

Quote
user Dovahkin has written
Oh my. This is fantastic. Thank you.

EDIT!

Whenever I press the button it gives me an error.

The error :
1
server.lua:13: table index is nil

Still the same code that you used @user EngiN33R:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
menu_action = {"Take coins","Take garbage"}

addhook("serveraction","_serveraction")
function _serveraction(id,action)
     if action == 1 then
          menu(id,"Container,"..table.concat(menu_action,","))
     end
end

addhook("menu","_menu")
function _menu(id,title,buton)
     if title == "Container" then
          menu_action[buton] = "(None)"
          menu(id,"Container,"..table.concat(menu_action,","))
    end
end

or

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
menu_action = {"Medic Armor","Laser"}

addhook("serveraction","_serveraction")
function _serveraction(id,action)
     if action == 1 then
          menu(id,"Container,"..table.concat(menu_action,","))
     end
end

addhook("menu","_menu")
function _menu(id,title,buton)
     if title == "Container" then
		if buton == 1 then
			parse ("equip "..id.." 82")
		elseif buton == 2 then
			parse ("equip "..id.." 45")
		end
          menu_action[buton] = "(None)"
          menu(id,"Container,"..table.concat(menu_action,","))
    end
end

Credits : user EngiN33R:

old Sorry for being late :)

Avo
User Off Offline

Quote
Sorry for reviving this (not so old, but whatever) thread, but I haven't seen it and I think I can help you if you're interested in more universal version of script you asked for. I'm providing it here:
Code >

Clicking a button doesn't remove it, but deactivates it.
Additional info >

old Re: Menu Disappears

Dovahkin
User Off Offline

Quote
@user Avo: Thank you. I will try it too.

Edit

Sorry for reviving this.

@user EngiN33R: How do you make only one button disappear? Not the other buttons?
edited 1×, last 21.10.13 12:19:59 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview