Forum

> > CS2D > Scripts > Hats script 'bugs'
Forums overviewCS2D overview Scripts overviewLog in to reply

English Hats script 'bugs'

15 replies
To the start Previous 1 Next To the start

old Hats script 'bugs'

krabob
User Off Offline

Quote
Hello, my first problem is that if a hat is selected, I can select many more hats at the same time so I can wear 8hats at the same time.
My second problem is that the nohat option (buton==9) doesn't work; the hat still stays on.

I'm not really sure if these are actual bugs or anything but if there's a way to 'solve' these then I'd really appreciate it.

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
if title=="Hats" then
if buton==1 then
freeimage(id) 
id=image("gfx/hats/armor.bmp",1,1,200+id)
elseif buton==2 then
freeimage(id) 
id=image("gfx/hats/blackdragon.png",1,1,200+id) 
elseif buton==3 then
freeimage(id) 
id=image("gfx/hats/fire.png",1,1,200+id)
elseif buton==4 then
freeimage(id) 
id=image("gfx/hats/phoenix.png",1,1,200+id)
elseif buton==5 then
freeimage(id) 
id=image("gfx/hats/pinocchio.png",1,1,200+id)
elseif buton==6 then
freeimage(id) 
id=image("gfx/hats/sonic.png",1,1,200+id)
elseif buton==7 then
freeimage(id) 
id=image("gfx/hats/spikes.png",1,1,200+id)
elseif buton==8 then
freeimage(id) 
id=image("gfx/hats/wizard.png",1,1,200+id)
elseif buton==9 then
freeimage(id) 
end
end

*Note*: This has been made using other scripts but only for educational purposes in the areas of scripting.

old Re: Hats script 'bugs'

Alistaire
User Off Offline

Quote
Maybe you should make a table like;

1
2
3
4
Hats = {}

freeimage(Hats[id])
Hats[id] = image(...)

and put a hook before the if title == thing;

1
2
3
4
5
6
addhook('menu','Hatsmenu')

function Hatsmenu(id)
	if (...)
	end
end

old Re: Hats script 'bugs'

krabob
User Off Offline

Quote
Well, it didn't work, might have been my error in editing 'cause when i clicked on a hat there came up a lua error:

"bad argument #1 to 'freeimage' (number expected, got nil)"


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
Hats = {}
addhook('menu','bmenu')
function bmenu(id)
if title=="Hats" then
if buton==1 then
freeimage(Hats[id])
Hats[id] = image("gfx/nopainhats/armor.bmp",1,1,200+id)
elseif buton==2 then
freeimage(Hats[id])
Hats[id] = image("gfx/nopainhats/blackdragon.png",1,1,200+id)
elseif buton==3 then
freeimage(Hats[id])
Hats[id] = image("gfx/nopainhats/fire.png",1,1,200+id)
elseif buton==4 then
freeimage(Hats[id])
Hats[id] = image("gfx/nopainhats/phoenix.png",1,1,200+id)
elseif buton==5 then
freeimage(Hats[id])
Hats[id] = image("gfx/nopainhats/pinocchio.png",1,1,200+id)
elseif buton==6 then
freeimage(Hats[id])
Hats[id] = image("gfx/nopainhats/sonic.png",1,1,200+id)
elseif buton==7 then
freeimage(Hats[id])
Hats[id] = image("gfx/nopainhats/spikes.png",1,1,200+id)
elseif buton==8 then
freeimage(Hats[id])
Hats[id] = image("gfx/nopainhats/wizard.png",1,1,200+id)
elseif buton==9 then
freeimage(Hats[id])
end
end

old Re: Hats script 'bugs'

DarkLight66
User Off Offline

Quote
The problem is that you try to delete the hat you are wearing very time you want to put on another one, when you don´t have any hats to delete. You need to check if you have a hat first before deleting it, maybe like:

1
2
3
if Hat[id] ~= 0 then
      freeimage(Hat[id])
end

old Re: Hats script 'bugs'

Alistaire
User Off Offline

Quote
Better would be if you put that in front of 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
Hats = {}
Stpth = 'gfx/nopainhats/'

addhook('menu','bmenu')
	function bmenu(id)
		if title=="Hats" then
			if Hats[id] ~= 0 then
      			 	freeimage(Hats[id])
 			end
			if buton==1 then
				Hats[id] = image(stpth..'armor.bmp',1,1,200+id)
			elseif buton==2 then
				Hats[id] = image(stpth..'blackdragon.png',1,1,200+id)
			elseif buton==3 then
				Hats[id] = image(stpth..'fire.png',1,1,200+id)
			elseif buton==4 then
				Hats[id] = image(stpth..'phoenix.png',1,1,200+id)
			elseif buton==5 then
				Hats[id] = image(stpth..'pinocchio.png',1,1,200+id)
			elseif buton==6 then
				Hats[id] = image(stpth..'sonic.png',1,1,200+id)
			elseif buton==7 then
				Hats[id] = image(stpth..'spikes.png',1,1,200+id)
			elseif buton==8 then
				Hats[id] = image(stpth..'wizard.png',1,1,200+id)
			elseif buton==9 then
			end
		end
	end
end

old Re: Hats script 'bugs'

Apache uwu
User Off Offline

Quote
Even more optimized:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Hats = {}
Stpth = 'gfx/nopainhats/'
hatImages={"armor.bmp",
			"blackdragon.png",
			"fire.png",
			"phoenix.png",
			"pinocchio.png",
			"sonic.png",
			"spikes.png",
			"wizard.png"
		}

addhook('menu','bmenu')

function bmenu(id,buton)
	if title=="Hats" then
		if Hats[id]~=0 then
			freeimage(Hats[id])
		end
		if buton~=0 then
			Hats[id]=image(stpth..hatImages[buton],1,1,200+id)
		end
	end
end
edited 1×, last 02.02.12 08:54:42 am

old Re: Hats script 'bugs'

kalis
User Off Offline

Quote
i have question :
1
Hats[id]=image(stpth..hatImages[id],1,1,200+id)
script auto choose ? image

old Re: Hats script 'bugs'

krabob
User Off Offline

Quote
I still get the msg:
"bad argument #1 to 'freeimage' (number expected, got nil)"

Thanks though guys.

old Re: Hats script 'bugs'

Apache uwu
User Off Offline

Quote
@user krabob: your own fault, you need to initialize the hats table with zeros...that's what you get for not posting the either source.

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
Hats = {}
Stpth = 'gfx/nopainhats/'
hatImages={"armor.bmp",
			"blackdragon.png",
			"fire.png",
			"phoenix.png",
			"pinocchio.png",
			"sonic.png",
			"spikes.png",
			"wizard.png"
		}

addhook('menu','bmenu')

function bmenu(id,buton)
	if title=="Hats" then
		if Hats[id]~=nil then
			freeimage(Hats[id])
			Hats[id]=nil
		end
		if buton~=0 then
			Hats[id]=image(stpth..hatImages[buton],1,1,200+id)
		end
	end
end

old Re: Hats script 'bugs'

kalis
User Off Offline

Quote
Array:
1
2
3
bankx = Array(32,0)
banky = Array(32,0)
level = Array(32,0)

1
2
3
4
5
6
7
8
_img = {}
sp = "gfx/sprites/"
images={
	       "flare.bmp",
	       "flare2.bmp",
	       "flare3.bmp",
	       "flare4.bmp",
          }
why it not work
1
2
3
4
5
6
7
8
9
addhook("build","_build")
function _build(id,type,x,y)
	if type == 7 then
		bankx[id] = x * 32 + 16
		banky[id] = y * 32 + 16
		max = level[id]
		_img[id] = image(sp..images[max],bankx[id]*32+16,banky[id]*32+16,1)
	end
end

error :
1
a nil value ?
hey i dont know why?

old Re: Hats script 'bugs'

EngiN33R
Moderator Off Offline

Quote
1
image(sp..images[max],bankx[id]*32+16,banky[id]*32+16,1)

1
sp..images[max]

Because you can't see.

old Re: Hats script 'bugs'

kalis
User Off Offline

Quote
OMG ok
thank you
i forgot to make level[id] = number (1,2,3,4)
edited 1×, last 03.02.12 11:06:05 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview