Forum

> > CS2D > Scripts > image for each team
Forums overviewCS2D overview Scripts overviewLog in to reply

English image for each team

19 replies
To the start Previous 1 Next To the start

old image for each team

lennon
User Off Offline

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

old Re: image for each team

DaisukeOno
User Off Offline

Quote
Startround Hook function : "_round"
Why function code below that hook is "_checkteam" ?
edited 1×, last 05.07.15 05:03:50 pm

old Re: image for each team

Rainoth
Moderator Off Offline

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

old Re: image for each team

lennon
User Off Offline

Quote
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

old Re: image for each team

gamus
User Off Offline

Quote
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

old Re: image for each team

gamus
User Off Offline

Quote
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

old Re: image for each team

lennon
User Off Offline

Quote
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

old Re: image for each team

Rainoth
Moderator Off Offline

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

old Re: image for each team

lennon
User Off Offline

Quote
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

old Re: image for each team

gamus
User Off Offline

Quote
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

old Re: image for each team

Dousea
User Off Offline

Quote
Don't forget to write the ID of the player at the last parameter of cs2d lua cmd image function if you want to show an image to a certain player. And cs2d lua hook 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 cs2d lua cmd 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 cs2d lua hook kill hook instead of cs2d lua hook die? Because cs2d lua hook 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 cs2d lua hook 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.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview