Forum

> > CS2D > Scripts > Only hats for a menu
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Only hats for a menu

43 Antworten
Seite
Zum Anfang Vorherige 1 2 3 Nächste Zum Anfang

alt Only hats for a menu

ead
User Off Offline

Zitieren
Hello again! I need a script that has several pages in a single menu, the down has this script but it uses the F2 F3 F4 I want only the F2 with all the hats.

Spoiler >


Good afternoon

alt Re: Only hats for a menu

Rainoth
Moderator Off Offline

Zitieren
Hi. Please use the search function. Not only are there multiple threads with your problem. I can recall a time when I personally wrote a script that did just that.
Here it is.

alt Re: Only hats for a menu

ead
User Off Offline

Zitieren
@user Rainoth: I did, but as I put a button on the player to remove the image

I tried....

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
hats = {}
hats.hooks = {"serveraction","menu","startround"}
hats.items = {
     ["Angel"] = {view = "2D", path = "angel.png"}, -- don't forget the commas
     ["Devil"] = {view = "2D", path = "devil.png"},
     ["removeHat"] = {view = "", path = "nil"}
}
--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 t == "Hats Menu" then
          removeHat(id)
          hats.player[id] = image("gfx/hats/"..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 -- in case of more than single digit page amount
               page = page .. t:sub(12,13)
          end
          page = tonumber(page)
          local ID = page*7+b-7
          if b <= 7 then
               removeHat(id)
               hats.player[id] = image("gfx/hats/"..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

function h_startround()
     for _,id in pairs (player(0,"tableliving")) do
          removeHat(id)
     end
end

hats.count = nil
hats.counter = nil
hats.hooks = nil

alt Re: Only hats for a menu

Rainoth
Moderator Off Offline

Zitieren
hats.items is just that. The hats. It only handles hat placement in a menu and their paths. Just because you make PATH nil doesn't mean you make the whole thing nil.
It's kinda simple, just
1. add "usebutton" in hats.hooks
2. add this function to handle whenever people press buttons.
1
2
3
4
5
function h_usebutton(id,x,y)
	if player(id,"team") == 1 then -- if terrorist then
		removeHat(id)
	end
end
3. If you want only certain button to do this, add IFs to check for x and y. They're in tiles (because button entities are placed based on tiles, not pixels)

alt Re: Only hats for a menu

Rainoth
Moderator Off Offline

Zitieren
Did you use the original code? Cause if you used the code you edited without removing what you added, it'll likely screw something up.

alt Re: Only hats for a menu

ead
User Off Offline

Zitieren
The 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
hats = {}
hats.hooks = {"usebutton","serveraction","menu","startround"}
hats.items = {
     ["Angel"] = {view = "2D", path = "angel.png"}, -- don't forget the commas
     ["Devil"] = {view = "2D", path = "16.png"},
}

-- hats.count = #hats.items
hats.counter = 0
hats.menus = {}
hats.player = {}

function h_usebutton(id,x,y)
     if player(id,"team") == 1 then -- if terrorist then
          removeHat(id)
     end
end

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 t == "Hats Menu" then
          removeHat(id)
          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 -- in case of more than single digit page amount
               page = page .. t:sub(12,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

function h_startround()
     for _,id in pairs (player(0,"tableliving")) do
          removeHat(id)
     end
end

hats.count = nil
hats.counter = nil
hats.hooks = nil

alt Re: Only hats for a menu

Rainoth
Moderator Off Offline

Zitieren
And you get error on line 80?
It only indexes button and player id. What did you do to have one of them to be non-number o.O ?

alt Re: Only hats for a menu

Rainoth
Moderator Off Offline

Zitieren
75 is a simple 'end'. I need the exact line where the error in the code is. If it's 80 as previously said, it indexes button pressed and id. Either one of those is nil (according to error). Which is WHY I'M ASKING what did you do when you got the error? I NEED to know.

alt Re: Only hats for a menu

ead
User Off Offline

Zitieren
This is the script, I put only hats for the T and also a button to remove the image. It does not appear on the menu, this hats script is essential for hide and seek

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
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 t == "Hats Menu" then
          removeHat(id)
          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 -- in case of more than single digit page amount
               page = page .. t:sub(12,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

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

alt Re: Only hats for a menu

Rainoth
Moderator Off Offline

Zitieren
Ok, your English is probably pretty bad if I need to repeat the same thing 3 times. What did you do when you got the error? Did you click something on the menu? Did you click serveraction to open menu? Did you just run the script and get the error?

alt Re: Only hats for a menu

Rainoth
Moderator Off Offline

Zitieren
Finally! Okay, in h_menu change it to this
1
2
3
function h_menu(id, t, b)
  if b > 0 and b < 10 then
    if t == "Hats Menu" then

Don't forget to add another 'end' at the end of h_menu function

alt Re: Only hats for a menu

ead
User Off Offline

Zitieren
When I close the menu of the script it appears another error...

IMG:https://ap.imagensbrasil.org/images/2016/12/04/erroragain.png


The 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 -- in case of more than single digit page amount
               page = page .. t:sub(12,13)
			   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
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

alt Re: Only hats for a menu

Yates
Reviewer Off Offline

Zitieren
Line 82,
page
does not exist there. It is defined as a local value within lines 76 and 81.
Zum Anfang Vorherige 1 2 3 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht