Forum

> > CS2D > Scripts > [Images] Lua freeimage.
Forums overviewCS2D overview Scripts overviewLog in to reply

English [Images] Lua freeimage.

9 replies
To the start Previous 1 Next To the start

old [Images] Lua freeimage.

Fehu
User Off Offline

Quote
Hey guys and girls. Today I'm getting insane by Lua. I mean freeimage option. When for example, two players spawn at the same time, they will gain an image:
1
2
3
4
5
function _mmorpg.hud(id)
	imagetop=image("gfx/(F)ehuziom Folder Sprite/rpg_mod/Okienko prawo dol.png",0,0,2,id)
	imagepos(imagetop,610,430,0)
	imagealpha(imagetop,0.9)
end
And then, when one of 'em will want to remove an image by writing command "remimg" it will use a code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
_mmorpg={}
_mmorpg.words = {"removeimage","remimg"}

function _mmorpg.chat(id,t)
	for i = 1,#_mmorpg.words do
		if (string.find(t,_mmorpg.words[i])~=nil) then
			msg2(id,os.date("©200200200[%I:%M %p]©255000000 [Warning!] ©200200200Successfull removed an image!"))
			freeimage(imagetop)
			return 1
		else
			msg(os.date("©200200200[%I:%M %p] ©170170255"..player(id,"name")..": ©200200200"..t))
			return 1
		end
	end
	return 1
end
And it remove the 2nd player image too. And both players doesn't have an image, when only one of them wanted to remove it.

The hell.. Anyone have suggestion how to fix it?
I want this command to make only ONE of them delete image.

//Edit
Well it's hard to copy the important pieces of script, cause this script is already huge.
I'm aloso using pl-parameter of image func. and.. just nothing. I wanted to make table by using:
Spoiler >

But it shows me error when I edited the script:
Spoiler >

Error in console:
Spoiler >

Any suggestions?

//Edit 2nd
Anyone can help me with table function? :c
edited 4×, last 22.12.13 02:50:53 pm

old Re: [Images] Lua freeimage.

DC
Admin Off Offline

Quote
The code you provided is incomplete (hooks etc. missing) so it's not possible to fully understand what exactly you are doing and especially HOW you are doing it.

One point for example is that you need a Lua variable / table entry for each individual image and not just one variable (in your sample opn) for all images.

Edit:
Maybe you have to create an individual image for/at each player using the optional pl-parameter of the cs2d lua cmd image command. You can't remove an image for only one player and keep it for others unless you create one individual image for each player.

Edit 2:
You seem to use the (global?) variable "imagetop" for multiple different images which is of course a mistake. I don't know when the functions are called (no addhook shown in the code) so it's not possible to fully comprehend how your code works but you should use a Lua table to save each image ID separately. This is the only way to be able to address (and delete) individual images.
edited 1×, last 22.12.13 03:00:19 pm

old Re: [Images] Lua freeimage.

Flacko
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
_mmorpg.images = {}
for i = 1, 32 do
	_mmorpg.images[i] = {}
end

function _mmorpg.hud(id)
	local img = image(etc...)
	_mmorpg.images[id].top = img
	imagepos(img, etc)
	imagealpha(img, etc)
end

function _mmorpg.removehud(id)
	freeimage(_mmorpg.images[id].top)
end
edited 1×, last 22.12.13 05:07:19 pm

old Re: [Images] Lua freeimage.

Fehu
User Off Offline

Quote
user Flacko has written
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
_mmorpg.images = {}
for i = 1, 32 do
	_mmorpg.images[i] = {}
end

function _mmorpg.hud(id)
	local img = image(etc...)
	_mmorpg.images[i].top = img
	imagepos(img, etc)
	imagealpha(img, etc)
end

function _mmorpg.removehud(id)
	freeimage(_mmorpg.images[i].top)
end

user DC has written
Edit 2:
You seem to use the (global?) variable "imagetop" for multiple different images which is of course a mistake. I don't know when the functions are called (no addhook shown in the code) so it's not possible to fully comprehend how your code works but you should use a Lua table to save each image ID separately. This is the only way to be able to address (and delete) individual images.

Thank you so much Flacko and DC. Now I can easily continue mod. Thank you.
One last question to Flacko. If I want remove only one image img then:
Flacko has written
1
2
3
4
[...]
     local img = image(etc...)
     _mmorpg.images[i].top = img
[...]

I need to use:
1
freeimage(_mmorpg.images[i].top.img)
Right?

old Re: [Images] Lua freeimage.

Fehu
User Off Offline

Quote
Uh. I changed script like Flacko says:
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
_mmorpg.images = {}

for i = 1, 32 do
     _mmorpg.images[i] = {}
end

function _mmorpg.hud(id)
	local imgpd = image("gfx/(F)ehuziom Folder Sprite/rpg_mod/Okienko prawo dol.png",0,0,2,id)
	_mmorpg.images[i].botp = imgpd
	imagepos(imgpd,610,430,0)
	imagealpha(imgpd,0.9)

	local imgpg = image("gfx/(F)ehuziom Folder Sprite/rpg_mod/Okienko prawo gora.png",0,0,2,id)
	_mmorpg.images[i].topp = imgpg
	imagepos(imgpg,582,45,0)
	imagealpha(imgpg,0.9)

	local imglg = image("gfx/(F)ehuziom Folder Sprite/rpg_mod/Okienko lewo gora.png",0,0,2,id)
	_mmorpg.images[i].topl = imglg
	imagepos(imglg,58,45,0)
	imagealpha(imglg,0.9)

	local imgld = image("gfx/(F)ehuziom Folder Sprite/rpg_mod/Okienko lewo dol.png",0,0,2,id)
	imagepos(imgld,30,430,0)
	imagealpha(imgld,0.9)
end

function _mmorpg.removehud(id)
     freeimage(_mmorpg.images[i].botp)
end
But now it display me error:
1
LUA ERROR: sys/lua/mmorpg/mmo_hud.lua:9: attempt to index field '?' (a nil value)
I have no idea how to fix it. What I've done wrong?

old Re: [Images] Lua freeimage.

Avo
User Off Offline

Quote
In function _mmorpg.hud there's argument "id", not "i", which is used for example here:
1
_mmorpg.images[i].botp = imgpd

More >

old Re: [Images] Lua freeimage.

mafia_man
User Off Offline

Quote
@user Avo:
There's also id at end of the function so this will throw him another error.
1
local imgpd = image("gfx/(F)ehuziom Folder Sprite/rpg_mod/Okienko prawo dol.png",0,0,2,id) <---
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview