I tried to make image for each team - other image for ct and other for tt displaying on screen somewhere.
If u change team u have other image of course
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
addhook('startround','_round')
function _checkteam(id)
xyz = player(id,"team")
if xyz == 1 then
	local id=image("gfx/b.png",322,30,2)
return 1
end
if xyz == 2 then
	local id=image("gfx/a.png",322,130,2)
return 1
end
end
function _round(id)
_checkteam(id)
end
Hooks are loaded but not displaying images. Startround Hook function : "_round"
Why function code below that hook is "_checkteam" ? edited 1×, last 05.07.15 05:03:50 pm
DaisukeOno: This is a stupid question.
creates a function called _checkteam
anyway, up to now image creates image for everyone. You could start by properly tabbing your code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
addhook('startround','_round')
function _checkteam(id)
	xyz = player(id,"team")
	if xyz == 1 then
		local id=image("gfx/b.png",322,30,2)
		return 1
	end
	if xyz == 2 then
		local id=image("gfx/a.png",322,130,2)
		return 1
	end
end
function _round(id)
	_checkteam(id)
end
Notes:
1. Startround hook does not provide id of players playing that round
2. You're overwriting player id (number) into an image
3. the "return 1" is needed for what reason..? 1
2
3
4
5
6
7
8
9
10
addhook("team" , ";look")
function Name hook(id,team, look)
if player(id,"team") == 1 then
	id=image("gfx/b.png",322,30,2)
	else
if player(id,"team") == 2 then
	id=image("gfx/a.png",110,420,2)
	end
end
Ye I aplicated changes but still something wrong btw. why were you redirecting it? o.o 1
2
3
4
5
6
7
8
9
addhook("spawn","checkif)
function checkif(i)
	if player(i,"team") == 1 then
		img=image("gfx/b.png",322,30,2)
	elseif player(i,"team") == 2 then
		img=image("gfx/a.png",110,420,2)
	end
end
gamus still its not working, we doing something bad @ lennon: The code you posted is messed up and makes no sense. The code gamus posted should work as long as you handle 'img' variable properly. lennon post the console screenshots/logs 1
addhook("spawn","checkif)
should be
1
addhook("spawn","checkif")
sry typo.
1
2
3
4
5
6
7
8
9
addhook("spawn","checkif")
function checkif(i)
if player(i,"team") == 1 then
img=image("gfx/b.png",322,30,2)
elseif player(i,"team") == 2 then
img=image("gfx/a.png",110,420,2)
end
end
ye its working thanks !
but when for example server is empty Iam in ct and I have image for ct, than if I add bot when someone join opposite team I have a both of images, any idea ?
When I am alone on server and i changing teams its ok, problem is when someone joining. So I don't think so hook spawn its good... edited 1×, last 05.07.15 07:41:35 pm
That's because you're not using an id based variable. It pains me to repeat this for 100th time but I'll say it again.
1
2
3
img = {}
-- then assigning a personal image like
img[id] = image("abc",1,2,3)
is better than assigning images like
1
img = image("abc",1,2,3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
addhook("spawn","checkif")
function checkif(i)
	if player(i,"team") == 1 then
		img[id]("gfx/b.png",322,430,2)
elseif player(i,"team") == 2 then
		img[id]("gfx/a.png",330,420,2)
end
end
so I have this and error
LUA ERROR: sys/lua/server.lua:7: attempt to index global 'img' (a nil value)
-> sys/lua/server.lua:7: in function <sys/lua/server.lua:3>
-> in Lua hook 'spawn', params: 1
what now ?
Admin/mod comment
don't abuse spoiler tags please. use code tags. you CAN use more tags if your code is VERY long but in most cases just code tags are the best choice! /DC 1
2
3
4
5
6
7
8
9
10
11
addhook("spawn","checkif")
img = {}
function checkif(i)
if player(i,"team") == 1 then
img[i]=image("gfx/b.png",322,30,2)
elseif player(i,"team") == 2 then
img[i]=image("gfx/a.png",110,420,2)
end
end
@ lennon: It's funny because you didn't even re-write the code even when I gave you an example how to do it. Thats true Rainoth
gamus still i have errors did u test this? Don't forget to write the ID of the player at the last parameter of image function if you want to show an image to a certain player. And startround hook doesn't pass player ID at first parameter but the mode of the start round.
1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("startround", "startroundhook")
function startroundhook(mode)
	for _, id in ipairs(player(0, "tableliving")) do
		local team = player(id, "team")
		
		if (team == 1) then
			image("gfx/b.png", 322, 30, 2, id)
		elseif (team == 2) then
			image("gfx/a.png", 322, 130, 2, id)
		end
	end
end
We don't need to save image return value if we don't manipulate the image. I don't know if it works but it may.
Code below is just in case if the code above doesn't work the way you want it to.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
local playerimage = {}
for id = 1, 32 do
	playerimage[id] = 0
end
addhook("spawn", "spawnhook")
function spawnhook(id)
	if (playerimage[id] == 0) then
		local team = player(id, "team")
		
		if (team == 1) then
			image("gfx/b.png", 322, 30, 2, id)
		elseif (team == 2) then
			image("gfx/a.png", 322, 130, 2, id)
		end
	end
end
And add this as well if you want to remove the image when player dies.
1
2
3
4
5
6
7
addhook("kill", "killhook")
function killhook(killer, victim)
	freeimage(playerimage[id])
	
	playerimage[id] = 0
end
Why do I use kill hook instead of die? Because die hook parameters is switched so.. you know. Also if you want to remove the image when player suicide.
1
2
3
4
5
6
7
addhook("suicide", "suicidehook")
function suicidehook(id)
	freeimage(playerimage[id])
	
	playerimage[id] = 0
end
I want to merge both when player dies or suicide but die hook parameters is switched so.. you know.
If it already fixed then I assume you know how to merge them into one.
I don't test code above neither. I haven't tested any of the above codes.