Forum

> > CS2D > Scripts > Freeimage
Forums overviewCS2D overview Scripts overviewLog in to reply

English Freeimage

7 replies
To the start Previous 1 Next To the start

old Freeimage

tos12345678
User Off Offline

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

old Re: Freeimage

GeoB99
Moderator Off Offline

Quote
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.
edited 1×, last 07.11.15 02:37:18 pm

old Re: Freeimage

Bowlinghead
User Off Offline

Quote
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
edited 1×, last 07.11.15 02:38:27 pm

old Re: Freeimage

VADemon
User Off Offline

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

old Re: Freeimage

tos12345678
User Off Offline

Quote
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:

old Re: Freeimage

Yates
Reviewer Off Offline

Quote
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).
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview