Forum

> > CS2D > Scripts > freeimage and table
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch freeimage and table

4 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt freeimage and table

SkullFace
User Off Offline

Zitieren
I've been trying to make classes with specific images on them.

I've been searching on forums for freeimage related threads.
These were my examples :


From these forums I came to conclude that this was the solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
local hat_images = {}
	-- SOLDIER
	if (sample.classes.class[id]==1) then
		if (hat_images[pl]) then
		freeimage(pl)
		hat_images[pl]=nil
		hat_images[pl]=image("gfx/sprites/flare2.bmp",1,1,100+id)
		parse ("setmaxhealth "..id.." 140")
		parse ("speedmod "..id.." 0")
		parse ("strip "..id.." 50")
		parse ("setmoney "..id.." 16000")
		return "3,69"; --Deagle, Machete
	end
	end
Before I modified the script, it loaded the images properly but the images weren't removed when I changed class
I've also wanted to addhook on die but that still didn't fix the issue.

TL;DR - Images keep on spawning on top of another when I change class.

alt Re: freeimage and table

Devil-Thanh
GAME BANNED Off Offline

Zitieren
this is the wrong line
1
freeimage(pl)

the ID in cs2d lua cmd freeimage work with image id which is returned from cs2d lua cmd image

So it must be
1
freeimage(hat_images[pl])

and you also need to chanhe pl to id

The code somehow look like this, with id is player's ID
1
2
3
4
5
6
7
8
9
10
11
12
13
local hat_images = {}
     -- SOLDIER
if (sample.classes.class[id]==1) then
	if (hat_images[id]) then
		freeimage(hat_images[id])
		hat_images[id]=image("gfx/sprites/flare2.bmp",1,1,100+id)
		parse("setmaxhealth "..id.." 140")
		parse("speedmod "..id.." 0")
		parse("strip "..id.." 50")
		parse("setmoney "..id.." 16000")
		return "3,69"; --Deagle, Machete
	end
end

alt Re: freeimage and table

SkullFace
User Off Offline

Zitieren
Uhh, idk what I did but this current code (below) didnt work for me before.
Now it works.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function sample.classes.spawn(id)
--local hat_images = {}
	-- SOLDIER
	if (sample.classes.class[id]==1) then
		--if (hat_images[id]) then
		freeimage(id)
		--hat_images[id]=nil
		id=image("gfx/sprites/flare2.bmp",1,1,100+id)
		
		parse ("setmaxhealth "..id.." 140")
		parse ("speedmod "..id.." 0")
		parse ("strip "..id.." 50")
		parse ("setmoney "..id.." 16000")
		return "3,69"; --Deagle, Machete
	end
Thanks for the help!

EDIT :Must be the id and pl thing mess up.

alt Re: freeimage and table

Rainoth
Moderator Off Offline

Zitieren
If it really properly works, I want someone to explain to me how cause it makes no sense to me.
My guess is that the guy thinks it works when in reality it probably doesn't.

here's a bit of code to help you out:
1
2
3
4
5
6
hats = {} -- add this outside your functions.

hats[id] = image("gfx/sprites/flare2.bmp",1,1,100+id) -- add this where you want to create the image

freeimage(hats[id]) -- add this where you want to delete the image
hats[id] = nil

alt Re: freeimage and table

Devil-Thanh
GAME BANNED Off Offline

Zitieren
Yeah it works if there's only 1 player on server, the image will jump to other players when there're more than 1 player
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht