Forum

> > CS2D > Scripts > Why doesn't it work?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Why doesn't it work?

47 replies
Page
To the start Previous 1 2 3 Next To the start

old Why doesn't it work?

Mami Tomoe
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
addhook("startround","_rp_startround")

function _rp_startround(id)
		for ids = 1,32 do
			local id=image("gfx/7hud/full.png",555,300,2)
				imagecolor(id,255,255,255)
			imagealpha(id,0.5)
		end
	end
end

There is no error.
The script should do the local id=image thing every round restart.

Thanks.

old Re: Why doesn't it work?

GeoB99
Moderator Off Offline

Quote
Now it must shall work at least I hope and there was also an useless "end" in the 9 line. Here's the code.
1
2
3
4
5
6
7
8
9
addhook("startround","_rp_startround")

function _rp_startround(id)
          for ids = 1,32 do
               local hud_img = image("gfx/7hud/full.png",555,300,2)
                    imagecolor(id,255,255,255)
               imagealpha(id,0.5)
 		end
end

old Re: Why doesn't it work?

Mami Tomoe
User Off Offline

Quote
@user GeoB99: Doesn't work... also it will only work if I use this code:

1
2
3
local hud_img = image("gfx/7hud/full.png",555,300,2)
imagecolor(id,255,255,255)
imagealpha(id,0.5)

But this code will remove the image on round start...

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
addhook("startround","_rp_startround")

function _rp_startround(mode)
	for ids = 1,32 do
		local id=image("gfx/7hud/full.png",555,300,2)
		imagecolor(id,255,255,255)
		imagealpha(id,0.5)
	end
end

Notable mistakes:
1. Startround hook provides round mode, not player IDs
2. You're looping all player IDs yet you're not using them anywhere inside the loop
3. Despite running the loop 32 times, you create an image and place it at the same spot 32 times. What's the point of that?
4. You come to the forum and say 'Doesn't work' but don't explain what you're trying to achieve here.

What I would advise using my great powers of assumption:
1. Use a table to store images for players
2. Loop living players table instead of a static number 32 to decrease the amount of iterations
3. Do not try to recolor into RGB 255255255 cause that equals white which produces no effect on the image color whatsoever
4. Try to tab properly and put 'end's

Further speaking, by the file path, I'm assuming that the image is supposed to be like a hud element for each player so if that's true, say it so I could further help you out.

P.S. The title 'Why doesn't it work?' does not say anything useful. Please try choosing a more proper title.

old Re: Why doesn't it work?

Mami Tomoe
User Off Offline

Quote
@user Rainoth: I tried the code but it didn't work... The image meant to show for all players no matter how many round starts there will be... also on the screen and not on the map.

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
Of course it didn't work. I just made your code work. It works as it was written. At least it WORKS.
Unfortunately, because you didn't know how to make it work like you WANT TO, you got this. Don't worry, I already anticipated what you wanted in my previous post so I'll write it for ya. Wait some time.

//Aight. See if this works:
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
Milk = {}

addhook("leave","_leave")
function _leave(id)
	if Milk[id] ~= nil then
		freeimage(Milk[id])
		Milk[id] = nil
	end
end

addhook("startround","_startround")
function _startround(mode)
	for k,v in pairs (player(0,"tableliving")) do
		if Milk[v] == nil then
			Milk[v] = image("gfx/7hud/full.png",555,300,2)
			imagealpha(Milk[v],0.5)
		end
	end
end

addhook("endround","_endround")
function _endround(mode)
	for k,v in pairs (player(0,"table")) do
		if Milk[v] ~= nil then
			freeimage(Milk[v])
			Milk[v] = nil
		end
	end
end
edited 4×, last 19.09.15 09:54:19 pm

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
You're very vague. Maybe you don't need to decrease the alpha to 0.5 and should have it at full alpha (1) instead. I need more information before I can determine the problem.

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
That shouldn't do anything wrong to this script. Can you explain more about how the image appears and disappears instantly..?

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
'Yeah' as in "It works!"
or 'Yeah' as in 'Yeah, it still doesn't work.' ?

If it still doesn't work. Try using only this:
1
2
3
4
5
6
7
8
Milk = {}

addhook("startround","_startround")
function _startround(mode)
	for k,v in pairs (player(0,"tableliving")) do
		Milk[v] = image("gfx/7hud/full.png",555,300,2)
	end
end

old Re: Why doesn't it work?

Rainoth
Moderator Off Offline

Quote
That doesn't make sense. It shouldn't even do anything but appear with the code I provided above. Unless you somehow, SOMEHOW wipe the images in other parts. If this continues, I might actually have to download the game and test myself >.>
To the start Previous 1 2 3 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview