Forum

> > CS2D > Scripts > Remove Hats
Forums overviewCS2D overview Scripts overviewLog in to reply

English Remove Hats

13 replies
To the start Previous 1 Next To the start

old Remove Hats

Bozo_
User Off Offline

Quote
Hi;
I have a Remove Hat script but since I don't know how to put it on 2 scripts: Well, I have a Menu, the Menu contains 2 more Menus, and the first one says, Hat 1 and the second Hat 2, Well, I want to know how to put the remove hat function to each one, If I press Remove Hat on Hat 1, the first Hat removes, and then on Hat 2, the second hat removes and when I removes one, I can wear another hat but I can't remove again (example: I wear a 1 Hat, I press Remove, ok, it's works. I put 2 Hats, It removes one, and when I press Remove again but on the 2nd Hat Menu, It doesn't remove). Here is my code:
Spoiler >

old Re: Remove Hats

GeoB99
Moderator Off Offline

Quote
Dunno if it works, not tested it.
1
2
3
4
if button == 9 then
   freeimage(hat[id])
   hat[id] = nil
end
Additionally, you have to add a title for that button (I think you know how to). Maybe it will work somehow.

old Re: Remove Hats

Yates
Reviewer Off Offline

Quote
1
2
3
4
if button >= 1 and button <= 8 then
	freeimage(hat[id])
	hat[id] = nil
end
Put that above all button checks.

old Re: Remove Hats

Yates
Reviewer Off Offline

Quote
Show the full code then. You are obviously not showing us a crucial part.

old Re: Remove Hats

Bozo_
User Off Offline

Quote
Spoiler >

old Re: Remove Hats

GeoB99
Moderator Off Offline

Quote
Telling only that it doesn't work is not an enough information for us. If you feel that it doesn't work, CHECK the Console for "LUA ERROR" messages highlighted in red colour if there are any. This will help us at least to check it and fix your problem.

And I think, the second hook menu part which contains all the button checks must be changed with this code below:
1
2
3
4
5
6
7
8
9
addhook("menu","menuaction")
function menuaction(id, m, b)
     if m == "Select A Hat 1" then
          if b == 1 then -- Devil
            freeimage(hat[id])
            hat[id] = nil
            hat[id] = image("gfx/iran-town/Angel.png",1,1,200+id)
          end
	-- And so on...
This is not finished though. For the rest of hat images, I'm sure you can do it yourself as I've shown this code as an example. What you have to do is just continuing like this with other hat images.

If any issue or error still occurs, post them here.

old Re: Remove Hats

Bozo_
User Off Offline

Quote
Well, here is my error with your code ZxC...
Spoiler >

old Re: Remove Hats

RIP-HereRestsPlookerbooy
BANNED Off Offline

Quote
1
2
3
4
5
6
7
addhook("menu","menuaction")
function menuaction(id, m, b)
     if m == "Select A Hat 1" then
          if b == 1 then -- Devil
            if (hat[id]) then freeimage(hat[id]) end
            hat[id] = image("gfx/iran-town/Angel.png",1,1,200+id)
          end

I don't know,this must work
edited 1×, last 19.11.15 10:35:33 pm

old Re: Remove Hats

Bozo_
User Off Offline

Quote
Nvm, Nothing is working to me, anyway, thanks you all to try to do this thing.

And I'm meaning that the 1st Menu (Hat 1) need to have a Remove function to the hats that are inside there, And on (Hat 2) the same thing, but only on Hat 2 Menu.

If you aren't understanding me: On Hat 1 I wear a Hat, Well, I click on remove hat button, and then the Hat that I chose on Hat 1 will remove. The same thing will occur on Hat 2 but just the hat of Hat 2 will remove

old Re: Remove Hats

RedizGaming
GAME BANNED Off Offline

Quote
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
hat={}

for id 1,32 do
	hat[id] = nil
end

addhook("menu","_2menuaction")
function _2menuaction(id,m,b)
     if m=="Select A Hat 2" then
          if b==1 then --Angel
             if hat[id] then freeimage(hat[id]) end --
          end
          if b==2 then --Devil
               hat[id]=image("gfx/iran-town/Devil.png",1,1,200+id)
          end
          if b==3 then --Pirate
               hat[id]=image("gfx/iran-town/Pirate.png",1,1,200+id)
          end
          if b==4 then --Santa
               hat[id]=image("gfx/iran-town/Santa.png",1,1,200+id)
          end
          if b==5 then --Police
               hat[id]=image("gfx/iran-town/Police.png",1,1,200+id)
          end
          if b==6 then --Pumpkin
               hat[id]=image("gfx/iran-town/Pumpkin.png",1,1,200+id)
          end
          if b==7 then --Gandalf
               hat[id]=image("gfx/iran-town/Gandalf.png",1,1,200+id)
          end
          if b==8 then --Spear
               hat[id]=image("gfx/iran-town/Spear.png",1,1,200+id)
       end
     end
end

try to use it

old Re: Remove Hats

Cure Pikachu
User Off Offline

Quote
Now that I understand what you are talking about, try 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
hat = {}

for i = 1, 32 do
	hat[i] = {}
end

addhook("menu","_menu")
function _menu(id,t,b)
	if t=="Player Menu 1/3" then
		if b==1 then
			menu(id,"Hats,Hat 1,Hat 2")
		end
	elseif t=="Hats" then
		if b==1 then
			menu(id,"Select A Hat 1,Angel|Hat,Devil|Hat,Pirate|Hat,Santa|Hat,Police|Hat,Pumpkin|Hat,Gandalf|Hat,Remove Hat|X,Next Page |>>")
		elseif b==2 then
			menu(id,"Select A Hat 2,Angel|Hat,Devil|Hat,Pirate|Hat,Santa|Hat,Police|Hat,Pumpkin|Hat,Gandalf|Hat,Remove Hat|X,Next Page |>>")
		end
	elseif m=="Select A Hat 1" then
		if b==1 then
			if hat[id][1] then freeimage(hat[id][1]) end
			hat[id][1]=image("gfx/iran-town/Angel.png",1,1,200+id)
		elseif b==2 then
			if hat[id][1] then freeimage(hat[id][1]) end
			hat[id][1]=image("gfx/iran-town/Devil.png",1,1,200+id)
		elseif b==3 then
			if hat[id][1] then freeimage(hat[id][1]) end
			hat[id][1]=image("gfx/iran-town/Pirate.png",1,1,200+id)
		elseif b==4 then
			if hat[id][1] then freeimage(hat[id][1]) end
			hat[id][1]=image("gfx/iran-town/Santa.png",1,1,200+id)
		elseif b==5 then
			if hat[id][1] then freeimage(hat[id][1]) end
			hat[id][1]=image("gfx/iran-town/Police.png",1,1,200+id)
		elseif b==6 then
			if hat[id][1] then freeimage(hat[id][1]) end
			hat[id][1]=image("gfx/iran-town/Pumpkin.png",1,1,200+id)
		elseif b==7 then
			if hat[id][1] then freeimage(hat[id][1]) end
			hat[id][1]=image("gfx/iran-town/Gandalf.png",1,1,200+id)
		elseif b==8 then --Remove hat
			if hat[id][1] then freeimage(hat[id][1]) end
			hat[id][1] = nil
		end
	elseif m=="Select A Hat 2" then
		if b==1 then
			if hat[id][2] then freeimage(hat[id][2]) end
			hat[id][2]=image("gfx/iran-town/Angel.png",1,1,200+id)
		elseif b==2 then
			if hat[id][2] then freeimage(hat[id][2]) end
			hat[id][2]=image("gfx/iran-town/Devil.png",1,1,200+id)
		elseif b==3 then
			if hat[id][2] then freeimage(hat[id][2]) end
			hat[id][2]=image("gfx/iran-town/Pirate.png",1,1,200+id)
		elseif b==4 then
			if hat[id][2] then freeimage(hat[id][2]) end
			hat[id][2]=image("gfx/iran-town/Santa.png",1,1,200+id)
		elseif b==5 then
			if hat[id][2] then freeimage(hat[id][2]) end
			hat[id][2]=image("gfx/iran-town/Police.png",1,1,200+id)
		elseif b==6 then
			if hat[id][2] then freeimage(hat[id][2]) end
			hat[id][2]=image("gfx/iran-town/Pumpkin.png",1,1,200+id)
		elseif b==7 then
			if hat[id][2] then freeimage(hat[id][2]) end
			hat[id][2]=image("gfx/iran-town/Gandalf.png",1,1,200+id)
		elseif b==8 then --Remove hat
			if hat[id][2] then freeimage(hat[id][2]) end
			hat[id][2] = nil
		end
	end
end

-- Extra
addhook("leave","clearimage")
function clearimage(id)
	for a = 1, 2 do
		if hat[id][a] then freeimage(hat[id][a])
		hat[id][a] = nil
	end
end
edited 1×, last 20.11.15 07:28:06 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview