Forum

> > CS2D > Scripts > Only hats for a menu
Forums overviewCS2D overview Scripts overviewLog in to reply

English Only hats for a menu

43 replies
Page
To the start Previous 1 2 3 Next To the start

old Re: Only hats for a menu

Rainoth
Moderator Off Offline

Quote
Take one 'end' and put it in the bottom of the 'h_menu' function. I already said in the reply before...

old Re: Only hats for a menu

ead
User Off Offline

Quote
I put however the error still continues, this and 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
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

old Re: Only hats for a menu

Rainoth
Moderator Off Offline

Quote
Do you understand the meaning of "take one and put elsewhere" ?

It means you REMOVE one 'end' and then place one 'end' where you're told. Common sense is nil with you guys.

The Code >

old Re: Only hats for a menu

ead
User Off Offline

Quote
I used this script but it does not even appear in the logs, and it does not work when I press F2

Spoiler >


Logs ;
IMG:https://hostfreeimg.com/image.php?di=GME7

old Re: Only hats for a menu

Yunuu
User Off Offline

Quote
@user ead: you should have an old version of cs2d for show errors in scripts 1.0.0.2 doesn't show script errors sometimes
Spoiler >

old Re: Only hats for a menu

Dousea
User Off Offline

Quote
I've tabbed your code so it can properly show the code's structure and see what's preventing it to work. By the looks of it, there's nothing wrong about the
end
s.
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
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
Also I made my own code. See if it works. You don't have to use it if you don't want to.
My code >
edited 3×, last 06.12.16 07:21:45 am

old Re: Only hats for a menu

ead
User Off Offline

Quote
@user Dousea: When I select a hat, this error appears here:

IMG:https://hostfreeimg.com/image.php?di=O85V


The script:
Spoiler >

old Re: Only hats for a menu

Dousea
User Off Offline

Quote
@user ead: Sorry mate, already fixed. But you could've fixed it by your own because it's just small issue (different name). Also did the menu work?

old Re: Only hats for a menu

GeoB99
Moderator Off Offline

Quote
In 63 line:
1
local page = t:match("Hats Menu %[(%d+)%]")
The parameter of cs2d lua hook menu hook is named as
title
whilst in the local variable there's
t
. As long it is not defined anywhere in the code, Lua thinks
t
as nil hence the error. Therefore it should be like this:
1
local page = title:match("Hats Menu %[(%d+)%]")

old Re: Only hats for a menu

ead
User Off Offline

Quote
@user GeoB99: I changed but appeared another error. This error appears when I select a hat

IMG:https://i.imgur.com/1VChR52.png


The current script:
Spoiler >

old something like this?

Scott
BANNED Off Offline

Quote
@user ead: something like this?

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
--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

old No problem.

Scott
BANNED Off Offline

Quote
No proble André, If you need anything else send me PM..

old Re: Only hats for a menu

Rainoth
Moderator Off Offline

Quote
My heart aches when I see code like that being used. The weird part is that back when I posted my code in the original thread I linked, it worked fine. Oh well...

old Re: Only hats for a menu

GeoB99
Moderator Off Offline

Quote
@user Scott: Besides of what user VADemon said, your code indentation is a mess, you have got to fix that and cs2d lua hook serveraction doesn't return any values so the
return 1
in 7 line is useless.

@user ead: I won't recommend the user 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 user Rainoth's code instead.
The Code >

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 cs2d lua hook leave hook in case when a player leaves from the server, the image gets faded and the image ID removed.
To the start Previous 1 2 3 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview