Forum

> > CS2D > Scripts > attempt to index golabel img (a nill value)
Forums overviewCS2D overview Scripts overviewLog in to reply

English attempt to index golabel img (a nill value)

11 replies
To the start Previous 1 Next To the start

old attempt to index golabel img (a nill value)

J4x
User Off Offline

Quote
Hi, I Make this script with some help, but when i open the console in cs2d it says me: Attempt to index global img (a nil value)

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
33
34
for pl = 1,32 do
image[pl] = {x = 0,y = 0,id = 0}
end

addhook("say","air")
function air(id,text)
if (text=="I need help") then
if player(id,"score") == 7 then
if player(id,"deaths") <= 2 then
msg2(id,"©000255000You recieved an Stealth Bomber")
msg2(id,"©000255000press f2 to mark your objective")
msg2(id,"©000255000Say ready to destroy your objective")
end
end
end
end

addhook("serveraction","boom")
function boom(id,action)
if action == 1 then
freeimage(img[id].i)
local x,y = player(id,"x"),player(id,"y")
img[id].i=image("gfx/weapons/bomb.bmp",x,y,0)
img[id].x = x
img[id].y = y
end
end

addhook("say","ready")
function ready(id,text)
if(text=="ready") then
parse([[explosion ]]..img[id].x..[[ ]]..img[id].y..[[ 20 100 ]]..id)
end
end

old Re: attempt to index golabel img (a nill value)

The Camo
User Off Offline

Quote
for pl = 1,32 do
image[pl] = {x = 0,y = 0,id = 0}
end

that wont work, didn't work for me too, you have to place it inside function.

1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("serveraction","boom")
function boom(id,action)
for pl = 1,32 do
img[pl] = {x = 0,y = 0,id = 0}
if action == 1 then
freeimage(img[id].i)
local x,y = player(id,"x"),player(id,"y")
img[id].i=image("gfx/weapons/bomb.bmp",x,y,0)
img[id].x = x
img[id].y = y
end
end
end
I think it will work, didn't test it maybe some ends are missing.

old Re: attempt to index golabel img (a nill value)

Banaan
User Off Offline

Quote
eww your code won't really work anyway. And I wouldn't use The Camo's code either, it'll totally screw everything up.

1:
Suppose I just joined the server and immediately press F2. The server will try to remove my image (img[myid].i), but it will come across a nil value as the image has not been created yet. Result: error.

2:
That will be fixed with what Yasday said. Still, you might come across some trouble there, you'd better check if an image has been created already.

3:
Anyone can just spawn bombs. I think you want to prevent that with your 'air' function, don't you?

4:
Please read the info.txt carefully.
info.txt has written
                    x<=0: do not rotate with player, x>0: rotate img with player
                    y<=0: only draw if not covered by fog of war, y>0: draw always

x and y do not represent the location of the image. Use cs2d lua cmd imagepos for this.

5:
I might still miss a few things in there, but I'll also cover The Camo's function:
Every time someone presses F2, all the image data of all players will be overwritten. This will create a huge amount of useless pictures with lost id's so they're hard to remove and it can only be done manually.

+ he puts an end at the wrong position; it will now try to free the image (of which the id has just been overwritten), create a new one (once again overwriting the id) and set the x and y 32 times. That means 32 images for each keypress! Madness!

old Re: attempt to index golabel img (a nill value)

J4x
User Off Offline

Quote
@Ysday this wwas the original code that you made, i used it and stilll the same error
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
for pl = 1,32 do
img[pl] = {x = 0,y = 0,i = 0}
end
addhook("say","air")
function air(id,text)
if (text=="I need help")then
if player(id,"score") == 10
msg2(id,"You recieved an airstrike")
msg2(id,"press f2 to mark your objective")
msg2(id,"Say objective ready to destroy your objective")
end
end

addhook("serveraction","boom")
function boom(id,action)
if action == 1 then
freeimage(img[id].i)
local x,y = player(id,"x"),player(id,"y")
img[id].i=image("gfx/weapons/bomb.bmp",x,y,0)
img[id].x = x
img[id].y = y
end
end

addhook("say","ready")
function ready(id,text)
if(text=="objective ready") then
parse([[explosion ]]..img[id].x..[[ ]]..img[id].y..[[ 1 1 ]]..id)
end
end

Thanks averyone for the answers
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview