Forum

> > CS2D > Scripts > Freeimage
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Freeimage

7 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Freeimage

tos12345678
User Off Offline

Zitieren
Hi us
how use freeimage (delete image) to DELETE ALL IMAGE

Type √

elseif sel == 3 then
SkullHat=image("gfx/ims/as/skul.png",10,10,200+id)
elseif sel == 4 then
PinkHat=image("gfx/ims/as/pink.png",10,10,200+id)
elseif sel == 5 then
freeimage(SkullHat)
freeimage(PinkHat)


How use freeimage to delete all id image?

alt Re: Freeimage

GeoB99
Moderator Off Offline

Zitieren
It's actually told in cs2d lua cmd freeimage's info how to.
1
2
3
4
5
if title == ("Remove Hat!") then
	if button == 5 then
		freeimage(id)
	end
end
This is only a little example. Let's say the 5 button we'll call it "Remove Hat!", whenever you click it the specific hat will be removed. It can also be done in another way, though I dunno how to.
1× editiert, zuletzt 07.11.15 14:37:18

alt Re: Freeimage

Bowlinghead
User Off Offline

Zitieren
You could use an array and save all images there.
Then you could delete all images with something like this:
1
2
3
4
for i=1,#array do
	freeimage(array[i])
	--array[i] = nil -- depending on your code
end
1× editiert, zuletzt 07.11.15 14:38:27

alt Re: Freeimage

VADemon
User Off Offline

Zitieren
I'm assuming you want to make a hat script, and you need a different approach.

• Each player can only wear one hat at a time
> It makes sense to create a table that saves images for all players:

1
2
hat_images = {}
-- hat_image[ playerID ] = image

You have a menu, so you need to do something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
elseif sel == 3 then

-- first check if this player is wearing a hat already:
if hat_image[ id ] then
	-- remove this image before making a new one
	freeimage( hat_image[ id ] )
	hat_image[id] = nil -- and remove the stored value
end

-- now we can make a new image
hat_image[ id ] = image("gfx/ims/as/skul.png",10,10,200+id)


elseif sel == 4 then  -- and so on
-- ...

alt Re: Freeimage

tos12345678
User Off Offline

Zitieren
Thanks all for help.
VADemon √
1
2
hat_images = {}
-- hat_image[ playerID ] = image

I corrected: hat_image - hat_images (VADemon code)

and

everything works.

× • Each player can only wear one hat at a time

√ > It makes sense to create a table that saves images for all players:

alt Re: Freeimage

Yates
Reviewer Off Offline

Zitieren
Make sure to set the variable to nil after freeimage to make sure no random ids are still set in them. Otherwise you end up with magically disappearing images (which is quite logical but won't happen if you set the variable to nil).
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht