Forum

> > CS2D > Scripts > Input IDs in Menu rows
Forums overviewCS2D overview Scripts overviewLog in to reply

English Input IDs in Menu rows

4 replies
To the start Previous 1 Next To the start

old Input IDs in Menu rows

Nknz1
User Off Offline

Quote
Hey guys.
I'm working on a script and in this script I would have many menus with different items in each one.

I've already searched and looked at the documentation but I didn't find anything about how to put an IDS or some identifier on each line of the menu.

Example.

My first menu is

1.Pistol
2.Rifles

How do I know that when the player clicked on line 1 or 2 it refers to Pistol or Rifles?

For me, only the button is enough, but only the number.

I would like to do something in a dynamic way

Looking at the below and thinking about a dynamic menu, how will I know that the person clicked on the Deagle or Glock skin? You can't base it on the button IDs because this can change.

---------------------------
Menu

1. Deagle Gold
2. Glock Water Elements
------------------

I can do what I want, but not in a dynamic way. and that ends up not being so good

old Re: Input IDs in Menu rows

Bowlinghead
User Off Offline

Quote
Vanilla menus are a bit tricky. It is certainly possible, I have done something similiar in file cs2d Digital Buy and Drop Request (A Valorant Feature)
I recommend you to use a menu framework/library (there are many in the file archive).

I dont really see the point in *dynamic* menus (Do you only want certain player groups to access certain skins?).

Quote
Looking at the below and thinking about a dynamic menu, how will I know that the person clicked on the Deagle or Glock skin? You can't base it on the button IDs because this can change.

When you create the menu then you generate a list of some sort (because you need to show the menu) like:
specialMenu = "Skinz@b, Gold Deagle, Watermelon Glock"

You need to save this specific order, in best case with some ids.
specialMenuData = { 1, 2 } -- While you know 1: golden deagle and 2: watermelon glock


Then in the hit hook you can interpret the buttons easily:
1
2
3
4
5
6
7
8
9
10
function menuHook(pid, t, b) 
	if (t=="Skinz") then
		if (b~=9) then
			local skinId = specialMenuData[b]
			msg2(pid,"You have selected Weapon ID: "..skinId)
			msg2(pid,"Your skin is: "..database[skinId].name)
			applySkinToPlayer(pid, skinId)
		end
	end
end

Example skin database:
1
2
3
4
5
6
7
8
9
10
11
database = {
	[1] = { -- <-- Skin ID
		name = "Golden Deagle", <-- Skin Name
		file = "gdgl.png",
	},
	[2] = {
		name = "Watermelon Glock",
		file = "wmelglock.png",
	},
	-- ...
}

Bonus >
edited 2×, last 24.01.24 09:29:44 pm

old Re: Input IDs in Menu rows

Nknz1
User Off Offline

Quote
@user Bowlinghead: I understand what you mean, but I think in the sense that I can have several skin pages... so it becomes a little complicated to know which skin was clicked on, is there a way to look for the position of the skin in a list if I know which one? I'm on this page, I already do that.

But I tried to find out if there was a better way.

old Re: Input IDs in Menu rows

Mami Tomoe
User Off Offline

Quote
The only way to do what you want is by covering the default menu system with a better one, primary by implementing tables.

Don't re-invent the wheel, it'll just slow your progress on whatever it is that you're working on.
Embrace a framework or just summon a dynamic-menu independent module.

I suggest either this framework: file cs2d HC Admin Script 1.9.4 or this module: file cs2d [EngiN33R] UniMenu

Again, you don't need to re-invent the wheel.
Creativity and uniqueness is what makes a server, not whether you made the menu script or someone from 10 years ago.

old Re: Input IDs in Menu rows

Bowlinghead
User Off Offline

Quote
Read& understand my script and menu framworks and combine that knowledge.
Here is an example for the UniMenu Menu Script.
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
63
64
65
66
-- dofile unimenu script
dofile("superscripts/unimenu.lua")

-- Example skin database:
database = {
     [1] = { -- <-- Skin ID
          name = "Golden Deagle", --<-- Skin Name
          file = "gdgl.png",
     },
     [2] = {
          name = "Watermelon Glock",
          file = "wmelglock.png",
     },
	 [3] = {
		name = "Redline AK",
		file = "rak.png",
	 },
	[4] = {
		name = "ProtoM4",
		file = "proto.png",
	},
	[5] = {
		name = "Elegant",
		file = "ele.png",
	},
}


function applySkin(pid, skinId)
	local skin = database[skinId]
	msg2(pid,"TODO Applying "..skin.name)
	msg2(pid,"TODO File: "..skin.file)
end

-- UniMenu Menu declaration
menus["Skinz"] = {
	title = "Sk1nZ Ch4ng3r",
	items = {
		-- filled by function
		--[[
			Expected something like:
			{"GayRainbow Deagle","", func(pid) applySkin(pid, 1)},
			{"Brown MOAB Grenade","",func(pid) applySkin(pid, 17)},
			{"Skin Name", "", func(pid) applySkin(pid, skinId)},
			...
		]]
	},
}

function init()
	local menuEntry
	for skinId, skin in pairs(database) do
		menuEntry = {}
		menuEntry[1] = skin.name
		menuEntry[2] = ""
		menuEntry[3] = function(pid) applySkin(pid, skinId) end

		-- Write unimenu-menu data here
		menus["Skinz"].items[#menus["Skinz"].items+1] = menuEntry
	end
end
init()


-- Open Skinz Menu for pid=1 
unimenu(1, true,"Skinz",1)

Quote
so it becomes a little complicated to know which skin was clicked on, is there a way to look for the position of the skin in a list if I know which one? I'm on this page, I already do that.

No, there is no easy way. Thats why we use menu frameworks
edited 5×, last 22.02.24 02:19:54 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview