Forum

> > CS2D > Scripts > How to make a menu display a player name
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to make a menu display a player name

3 replies
To the start Previous 1 Next To the start

old How to make a menu display a player name

D-D3ADxPro
User Off Offline

Quote
Im not sure how to do this, but how do you make a menu display a player name for example: Player,Player2, and etc.

1
menu(id,"Mute a Player- 1/2,"..player(id,"exists")..","..player(id,"exists")..","..player(id,"exists")..","..player(id,"exists")..","..player(id,"exists")..","..player(id,"exists")..","..player(id,"name")..","..player(id,"name")..",Next")
Tried a bunch of things, but they dont seem to work.

old Re: How to make a menu display a player name

Avo
User Off Offline

Quote
player(id, "exists") return a boolean value. You need to use player(id, "name") (of course player must exist)

Sth like:
1
2
3
4
local players = "Menu name"
for _,v in pairs(player(0, "table")) do
	players = players..","..player(v,"name")
end
Of course it is only an example, you should use inf. menus for that to make it look better.

old Re: How to make a menu display a player name

D-D3ADxPro
User Off Offline

Quote
Heres the full menu:

1
menu(id,"Mute a Player- 1/2,"..name[1]..","..name[2]..","..name[3]..","..name[4]..","..name[5]..","..name[6]..","..name[7]..","..name[8]..",Next")

But in console it shows this:
1
LUA ERROR: maps/as_mars.lua:123: attempt to index global 'name' (a nil value)

old Re: How to make a menu display a player name

Bowlinghead
User Off Offline

Quote
"name" is an unknown table in your code. So you have to say the compiler "this is the table 'name'"!

Maybe this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function initArray(m)
	local array = {}
	for i = 1, m do
		array[i]="0"
	end
	return array
end
name = initArray(32)

addhook("serveraction","Deutsches_Wort")
function Deutsches_Wort(id,b)
	for p=1,#player(0, "table") do
		if player(p,"exists")==true then
			name[p]=player(p,"name")
		end
	end
	menu(id,"Mute a Player- 1/2,"..name[1]..","..name[2]..","..name[3]..","..name[4]..","..name[5]..","..name[6]..","..name[7]..","..name[8]..",Next")

-- Untested

The first 8 lines are nothing else than:
1
name = {"0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"}
This are 32 strings, with zeros in it.
At line 12 until 14 it says:
If player with ID p exists, then write his name at the table.

Example:
There are only two players at the server.
Player with ID 5 that is called "Name1" and ID 9 that is called "Name2" exists.
The table is like:
1
name = {"0","0","0","0","Name1","0","0","0","Name2","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"}

The menu looks like:
1
menu(id,"Mute a Player- 1/2,0,0,0,0,Name1,0,0,0,0,Next")

Mhh... Now there must be a
1
2
for x=1,#player(0, "table") do
if name[x]~="0" then
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview