I'm SDKey.I'm construct the menu system.
Please help me to change style for using menu system in scripts:
Help:
Spoiler 

Function to show menu in script
menu_show([name of menu],[player id],[user arguments...])
This is main function of create menu:
menu_create(name of menu, "big"|"invisible", function(id, user args...)
--code for generate buttons
end)
Function for generate button:
menu_button(caption, info)
Button with event:
menu_button("Get money", "16000$").event(parse, "setmoney 1 16000")
Button with submenu:
menu_button("Get weapon").show("weapon menu", id)
Button with refresh menu:
menu_button("Refresh" ).refresh()
Multi attach:
menu_button("Get all").show("weapon menu",id).event(parse, "setmoney 1 16000").event(parse, "sethealth 1 100")
menu_show([name of menu],[player id],[user arguments...])
This is main function of create menu:
menu_create(name of menu, "big"|"invisible", function(id, user args...)
--code for generate buttons
end)
Function for generate button:
menu_button(caption, info)
Button with event:
menu_button("Get money", "16000$").event(parse, "setmoney 1 16000")
Button with submenu:
menu_button("Get weapon").show("weapon menu", id)
Button with refresh menu:
menu_button("Refresh" ).refresh()
Multi attach:
menu_button("Get all").show("weapon menu",id).event(parse, "setmoney 1 16000").event(parse, "sethealth 1 100")
Examples:
Spoiler 

Example 1: Kick player menu


1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
-- Build menu
menu.create("Kick player menu", "big", function(id)
	for _, x in pairs(player(0,"table")) do
		menu.button("Kick "..player(x,"name"))
			.event(parse, "kick " .. x)
			.event(msg, "Player " .. player(id,"name") .. " kick " .. player(x,"name"))
	end
end)
-- When admin call menu
addhook("serveraction", "kick_action")
function kick_action(id)
	menu.show("Kick player menu", id)
end


Spoiler 

Example 2: The panel of sale of the weapon


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- Build menu
menu.create("Sale panel", function(id)
	for _, ww in pairs(playerweapons(id)) do
		local price = itemtype(ww,"price")
		menu.button("Sell "..itemtype(ww,"name"), price.."$")
			.event(parse, "strip "..id.." "..ww)
			.event(parse, "setmoney "..id.." "..(player(id, "money") + price))
			.refresh() -- draw this menu again
	end
end)
-- When player press "E"
addhook("use", "use")
function use(id, action)
	menu.show("Sale panel", id)
end


Variants of style:
Spoiler 

For example: this "Admin menu" contains 2 buttons.
First button: open other menu for change player
Second button: restart the game
If you close menu (button (0)): msg(id,"You close admin menu")
1. standart
2. with )(
3. flat style
4. flat style with )(
5. Your variants)
First button: open other menu for change player
Second button: restart the game
If you close menu (button (0)): msg(id,"You close admin menu")
1. standart1
2
3
4
5
2
3
4
5
menu_create("Admin menu", "big", function(id)
	menu_button("Kick player").show("Change player menu", id)
	menu_button("Restart map").event(parse, "restart").event(msg, "Restart map")
	menu_button(0).event(msg2,id,"You close admin menu")
end)
2. with )(1
2
3
4
5
6
2
3
4
5
6
menu_create("Admin menu", "big")(
function(id)
	menu_button("Kick player").show("Change player menu", id)
	menu_button("Restart map").event(parse, "restart").event(msg, "Restart map")
	menu_button(0).event(msg2,id,"You close admin menu")
end)
3. flat style1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
menu_create("Admin menu", "big", function(id)
	menu_button("Kick player")
		menu_show("Change player menu", id)
	menu_button("Restart map")
		menu_event(parse, "restart")
		menu_event(msg, "Restart map")
	menu_button(0)
		menu_event(msg2,id,"You close admin menu")
end)
4. flat style with )(1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
menu_create("Admin menu", "big")(
function(id)
	menu_button("Kick player")
		menu_show("Change player menu", id)
	menu_button("Restart map")
		menu_event(parse, "restart")
		menu_event(msg, "Restart map")
	menu_button(0)
		menu_event(msg2,id,"You close admin menu")
end)
5. Your variants)Thanks you for reading. Really!
Write the judgement.
Don't forget to vote. Though for the last point.
edited 14×, last 14.04.11 02:24:24 pm
menu system
1 
Offline
.
Gaios