Forum

> > CS2D > Scripts > Hats script 'bugs'
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Hats script 'bugs'

15 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Hats script 'bugs'

krabob
User Off Offline

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

alt Re: Hats script 'bugs'

Alistaire
User Off Offline

Zitieren
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

alt Re: Hats script 'bugs'

krabob
User Off Offline

Zitieren
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

alt Re: Hats script 'bugs'

DarkLight66
User Off Offline

Zitieren
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

alt Re: Hats script 'bugs'

Alistaire
User Off Offline

Zitieren
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

alt Re: Hats script 'bugs'

Apache uwu
User Off Offline

Zitieren
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
1× editiert, zuletzt 02.02.12 08:54:42

alt Re: Hats script 'bugs'

kalis
User Off Offline

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

alt Re: Hats script 'bugs'

krabob
User Off Offline

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

Thanks though guys.

alt Re: Hats script 'bugs'

Apache uwu
User Off Offline

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

alt Re: Hats script 'bugs'

kalis
User Off Offline

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

alt Re: Hats script 'bugs'

EngiN33R
Moderator Off Offline

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

1
sp..images[max]

Because you can't see.

alt Re: Hats script 'bugs'

kalis
User Off Offline

Zitieren
OMG ok
thank you
i forgot to make level[id] = number (1,2,3,4)
1× editiert, zuletzt 03.02.12 11:06:05
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht