Forum
CS2D Scripts Only hats for a menu1
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
hats = {} hats.hooks = {"serveraction","menu","startround","usebutton"} hats.items = { ["Angel"] = {view = "2D", path = "angel.png"}, ["Devil"] = {view = "2D", path = "16.png"} } -- hats.count = #hats.items hats.counter = 0 hats.menus = {} hats.player = {} for k,_ in pairs (hats.items) do hats.counter = hats.counter + 1 hats.items[k].ID = hats.counter end hats.count = hats.counter for _,hook in pairs (hats.hooks) do addhook(hook,"h_"..hook) end if hats.count <= 9 then hats.menus[1] = "Hats Menu" for k,v in pairs (hats.items) do hats.menus[1] = hats.menus[1] .. "," .. k .. "|" .. v.view end elseif hats.count > 9 then local index = 1 local counter = 0 hats.menus[index] = "Hats Menu ["..index.."]" for k,v in pairs (hats.items) do hats.menus[index] = hats.menus[index] .. "," .. k .. "|" .. v.view counter = counter + 1 if counter == 7 then if index == 1 then hats.menus[index] = hats.menus[index] .. ",(Previous Page),Next Page" else hats.menus[index] = hats.menus[index] .. ",Previous Page,Next Page" end counter = 0 index = index + 1 hats.menus[index] = "Hats Menu ["..index.."]" end end index = nil counter = nil end function h_serveraction(id, b) if player(id,"team")== 1 then menu(id,hats.menus[1]) end end function findHat(ID) for k,v in pairs (hats.items) do if v.ID == ID then return k end end end function removeHat(id) if hats.player[id] then freeimage(hats.player[id]) hats.player[id] = nil end end function h_menu(id, t, b) if b > 0 and b < 10 then if t == "Hats Menu" then hats.player[id] = image("gfx/hide and seek/"..hats.items[findHat(b)].path,1,1,200+id) elseif t:find("Hats Menu") then local page = t:sub(12,12) if tonumber(t:sub(12,13)) then page = page .. t:sub(12,13) end end end page = tonumber(page) local ID = page*7+b-7 if b <= 7 then removeHat(id) hats.player[id] = image("gfx/hide and seek/"..hats.items[findHat(ID)].path,1,1,200+id) elseif b == 8 then menu(id,hats.menus[page-1]) elseif b == 9 then menu(id,hats.menus[page+1]) end ID = nil page = nil end function h_startround() for _,id in pairs (player(0,"tableliving")) do removeHat(id) end end function h_usebutton(id, b) if player(id,"team")== 1 then removeHat(id) end end hats.count = nil hats.counter = nil hats.hooks = nil
It means you REMOVE one 'end' and then place one 'end' where you're told. Common sense is nil with you guys.
Logs ;
ends.
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
hats = {} hats.hooks = {"serveraction","menu","startround","usebutton"} hats.items = { 	["Devil"] = {view = "2D", path = "16.png"}, 	["Bed"] = {view = "2D", path = "bed.PNG"}, } -- hats.count = #hats.items hats.counter = 0 hats.menus = {} hats.player = {} for k,_ in pairs (hats.items) do 	hats.counter = hats.counter + 1 	hats.items[k].ID = hats.counter end hats.count = hats.counter for _,hook in pairs (hats.hooks) do 	addhook(hook,"h_"..hook) end if hats.count <= 9 then 	hats.menus[1] = "Hats Menu" 	for k,v in pairs (hats.items) do 		hats.menus[1] = hats.menus[1] .. "," .. k .. "|" .. v.view 	end elseif hats.count > 9 then 	local index = 1 	local counter = 0 	hats.menus[index] = "Hats Menu ["..index.."]" 	for k,v in pairs (hats.items) do 		hats.menus[index] = hats.menus[index] .. "," .. k .. "|" .. v.view 		counter = counter + 1 		if counter == 7 then 			if index == 1 then 				hats.menus[index] = hats.menus[index] .. ",(Previous Page),Next Page" 			else 				hats.menus[index] = hats.menus[index] .. ",Previous Page,Next Page" 			end 			counter = 0 			index = index + 1 			hats.menus[index] = "Hats Menu ["..index.."]" 		end 	end 	index = nil 	counter = nil end function h_serveraction(id, b)	 	if player(id,"team")== 1 then 		menu(id,hats.menus[1]) 	end end function findHat(ID) 	for k,v in pairs (hats.items) do 		if v.ID == ID then 			return k 		end 	end end function removeHat(id) 	if hats.player[id] then 		freeimage(hats.player[id]) 		hats.player[id] = nil 	end end function h_menu(id, t, b) 	if b > 0 and b < 10 then 		if t == "Hats Menu" then 			hats.player[id] = image("gfx/hide and seek/"..hats.items[findHat(b)].path,1,1,200+id) 		elseif t:find("Hats Menu") then 			local page = t:sub(12,12) 			if tonumber(t:sub(12,13)) then 				page = page .. t:sub(13,13) 			end 			page = tonumber(page) 			local ID = page*7+b-7 			if b <= 7 then 				removeHat(id) 				hats.player[id] = image("gfx/hide and seek/"..hats.items[findHat(ID)].path,1,1,200+id) 			elseif b == 8 then 				menu(id,hats.menus[page-1]) 			elseif b == 9 then 				menu(id,hats.menus[page+1]) 			end 			ID = nil 			page = nil 		end 	end end function h_startround() 	for _,id in pairs (player(0,"tableliving")) do 		removeHat(id) 	end end function h_usebutton(id, b) 	if player(id,"team")== 1 then 		removeHat(id) 	end end hats.count = nil hats.counter = nil hats.hooks = nil
edited 3×, last 06.12.16 07:21:45 am
The script:
1
local page = t:match("Hats Menu %[(%d+)%]")
titlewhilst in the local variable there's
t. As long it is not defined anywhere in the code, Lua thinks
tas nil hence the error. Therefore it should be like this:
1
local page = title:match("Hats Menu %[(%d+)%]")
The current 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
--Hats Menu addhook("serveraction", "hatsmenu") function hatsmenu(id, g) if g== 1 then menu(id, "Hats Menu, Sonic | Head, Goku | Hair, Devil | Horns, Shadow | Hat, Soldado | Hat, Brasil | Hat, Yoshi | Head,, Next|>>>") return 1 end end 		addhook("menu", "menuhats") 		function menuhats(id, title, but) if (title=="Hats Menu") then if(but==1) then 	freeimage(id) 	id=image("gfx/hats/New_Sonic.png",1,1,200+id) end if(but==2) then 	freeimage(id) 	id=image("gfx/skins menu/goku.bmp",1,1,200+id) end if(but==3) then 	freeimage(id) 	id=image("gfx/skins menu/devil.png",1,1,200+id) end if(but==4) then 	freeimage(id) 	id=image("gfx/hats/Shadow.png",1,1,200+id)		 end if(but==5) then 	freeimage(id) 	id=image("gfx/hats/soldadoroxo.png",1,1,100+id) end if(but==6) then 	freeimage(id) 	id=image("gfx/skins menu/brasil.png",1,1,200+id) end if(but==7) then 	freeimage(id) 	id=image("gfx/skins menu/yoshi.png",1,1,200+id) end if(but==9) then 	menu(id, "Hats Menu 2, Drag | Wings, Dragon | Transformation, Dark Demon | Wings, Dark Devil | Wings, Gold Angel | Wings, Titan | Transformation,, Back|<<<,Next|>>>") end end if (title=="Hats Menu 2") then if(but==1) then 	freeimage(id) 	id=image("gfx/skins menu/dragon.png",1,1,200+id) end if(but==2) then 	freeimage(id) 	id1=image("gfx/skins menu/drago.png",1,1,200+id) end if(but==3) then 	freeimage(id) 	id1=image("gfx/skins menu/dark.png",1,1,200+id) end if(but==4) then 	freeimage(id) 	id1=image("gfx/skins menu/evil.png",1,1,200+id) end if(but==5) then 	freeimage(id) 	id1=image("gfx/skins menu/goldw.png",1,1,200+id) end if(but==6) then 	freeimage(id) 	id=image("gfx/zombie/titan.png",1,1,200+id) end if(but==7) then end if(but==8) then menu(id, "Hats Menu, Sonic | Head, Goku | Hair, Devil | Horns, Flame | Bag, Horse | Pet, Brasil | Hat, Yoshi | Head,,Next|>>>") end if(but==9) then menu(id, "Hats Menu 3, Wolf | Head, Toad | Hair, Pirate | Hat, Angel | Wings, Umbrella Blue | Shadow, Umbrella Red | Shadow,,Back|<<<,Next|>>>") end end if (title=="Hats Menu 3") then if(but==1) then 	freeimage(id) 	id=image("gfx/skins menu/wolf.png",1,1,200+id) end if(but==2) then 	freeimage(id) 	id=image("gfx/skins menu/toad.png",1,1,200+id) end if(but==3) then 	freeimage(id) 	id=image("gfx/skins menu/pirate_hat.png",1,1,200+id) end if(but==4) then 	freeimage(id) 	id=image("gfx/skins menu/angel.png",1,1,200+id) end if(but==5) then 	freeimage(id) 	id=image("gfx/skins menu/umbrella_ct.png",1,1,100+id) end if(but==6) then 	freeimage(id) 	id=image("gfx/skins menu/umbrella_t.png",1,1,100+id) end if(but==7) then end if(but==8) then menu(id, "Hats Menu 2, Drag | Wings, Dragon | Transformation, Dark Demon | Wings, Dark Devil | Wings, Gold Angel | Wings, Titan | Transformation,, Back|<<<,Next|>>>") end if(but==9) then menu(id, "Hats Menu 4, Fairy | Wings, Pikachu | Head, Phoenix | Helm, MegaMan | Head, Spear | Hat, Knife | Hat, S.W.A.T | Armor,,Back|<<<") end end if (title=="Hats Menu 4") then if(but==1) then 	freeimage(id) 	id1=image("gfx/skins menu/fairy.png",1,1,200+id) end if(but==2) then 	freeimage(id) 	id=image("gfx/skins menu/pikachu.png",1,1,200+id) end if(but==3) then 	freeimage(id) 	id=image("gfx/skins menu/phoenix.png",1,1,200+id) end if(but==4) then 	freeimage(id) 	id=image("gfx/skins menu/megaman.png",1,1,200+id) end if(but==5) then 	freeimage(id) 	id=image("gfx/skins menu/spear.png",1,1,200+id) end if(but==6) then 	freeimage(id) 	id=image("gfx/skins menu/29.bmp",1,1,200+id) end if(but==7) then 	freeimage(id) 	id=image("gfx/skins menu/23.bmp",1,1,200+id) end if(but==8) then end if(but==9) then menu(id, "Hats Menu 3, Wolf | Head, Toad | Hair, Pirate | Hat, Angel | Wings, Umbrella Blue | Shadow, Umbrella Red | Shadow,,Back|<<<,Next|>>>") end end end
return 1in 7 line is useless.
@ ead: I won't recommend the Scott's code just for the simple fact that the way it manages the hats (images) is very elementary and could lead to weird issues. Better you should think twice and use the Rainoth's code instead.
I also tested it by myself and I can hereby confirm it works without problems. What you have to do is just create a hat folder inside gfx and there you can put all the following hats you wish and add their path through
hats.items = {}table.
P.S: I added leave hook in case when a player leaves from the server, the image gets faded and the image ID removed.