Forum

> > CS2D > Scripts > Team Hats
Forums overviewCS2D overview Scripts overviewLog in to reply

English Team Hats

11 replies
To the start Previous 1 Next To the start

old Team Hats

Computerguy419
User Off Offline

Quote
Hello,

     I am returning to this game. I used to make scripts all the time, but I am a little rusty. I seem to remember a way to check which team the player is on and need help with the function. I am trying to make a small script that gives each team a different hat. The CT will have police masks and the T will have some sort of hood. My main question is: Which command do I use to check which team the player is on. I think I can handle it from there

√ Will add helper credit (if wanted)

Thanks,
Computerguy419

old Re: Team Hats

Cure Pikachu
User Off Offline

Quote
1
2
3
4
if player(id,"team") == 0 then -- If player is Spectator
if player(id,"team") == 1 then -- If player is T
if player(id,"team") == 2 then -- If player is CT
if player(id,"team") == 3 then -- If player is VIP
Where id is of course, the player ID.

old Re: Team Hats

Computerguy419
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
function cpuguy.hat.giveallhats()
	for i=1,32,1 do
		if player(id,"team") == 1 then                    -- If player is T
			id=image("gfx/hat/helmet.bmp",1,1,200+i)	-- Create hat @ Player
			else
			id=image("gfx/hat/police.bmp",1,1,200+i)
		end
	end
end

LUA ERROR: sys/lua/cpuguy419/hats.lua:16: bad argument #1 to 'player' (number expected, got nil)

I used to know how to do this stuff. A lil help please?
edited 1×, last 15.12.12 12:43:19 am

old Re: Team Hats

sheeL
User Off Offline

Quote
Like This?

1
2
3
4
5
6
7
8
9
10
11
if cpuguy == nil then cpuguy = {} end

function cpuguy.Hat(id)
     for i=1,32 do
          if player(id,"team") == 1 then                    -- If player is T
               id=image("gfx/hat/helmet.bmp",1,1,200+i)     -- Create hat @ Player
               else
               id=image("gfx/hat/police.bmp",1,1,200+i)
          end
     end
end

old Re: Team Hats

Computerguy419
User Off Offline

Quote
Ok... this is my whole script:
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
if cpuguy==nil then cpuguy={} end
cpuguy.Hat={}

---------
-- Hat --
---------

-- Add Hat Function
function cpuguy.Hat(id)
     for i=1,32 do
          if player(id,"team") == 1 then                    -- If player is T
               id=image("gfx/hat/helmet.bmp",1,1,200+i)     -- Create hat @ Player
               else
               id=image("gfx/hat/police.bmp",1,1,200+i)
          end
     end
end

-- Give Hat instantly afrer starting server
cpuguy.Hat()

-- Give Hat after roundstart (because hats are deleted on roundstart!)
addhook("startround","cpuguy.hat.startround")
function cpuguy.Hat.startround()
	cpuguy.Hat()
end

Same error message... I'm a noob lol
edited 1×, last 15.12.12 01:29:44 am

old Re: Team Hats

sheeL
User Off Offline

Quote
Like this?

1
2
3
4
5
6
7
8
9
10
11
12
13
if cpuguy==nil then cpuguy={} end

addhook("startround","cpuguy.Hat")
function cpuguy.Hat(id)
team=player(id,"team")
     for i=1,32 do
          if team == 1 then                -- If player is T
               id=image("gfx/hat/helmet.bmp",1,1,200+i)     -- Create hat @ Player
               else
               id=image("gfx/hat/police.bmp",1,1,200+i)
          end
     end
end

if you need help, send pm to me...

old Re: Team Hats

Computerguy419
User Off Offline

Quote
Using
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
if cpuguy==nil then cpuguy={} end
cpuguy.Hat={}

---------
-- Hat --
---------

addhook("startround","cpuguy.Hat")
function cpuguy.Hat(id)
team=player(id,"team")
     for i=1,32 do
          if team == 1 then                -- If player is T
               id=image("gfx/hat/helmet.bmp",1,1,200+i)     -- Create hat @ Player
               else
               id=image("gfx/hat/police.bmp",1,1,200+i)
          end
     end
end

-- Give Hat instantly afrer starting server
cpuguy.Hat()

-- Give Hat after roundstart (because hats are deleted on roundstart!)
function cpuguy.Hat.startround()
	cpuguy.Hat()
end

It comes up with the same error, but if I use only what you have
1
2
3
4
5
6
7
8
9
10
11
12
13
if cpuguy==nil then cpuguy={} end

addhook("startround","cpuguy.Hat")
function cpuguy.Hat(id)
team=player(id,"team")
     for i=1,32 do
          if team == 1 then                -- If player is T
               id=image("gfx/hat/helmet.bmp",1,1,200+i)     -- Create hat @ Player
               else
               id=image("gfx/hat/police.bmp",1,1,200+i)
          end
     end
end

it doesn't but it also doesn't add the image over lay into the game.

old Re: Team Hats

sheeL
User Off Offline

Quote
@user Computerguy419: Looks, Works Perfect Here
Delete all scripts in your archive and put this code

1
2
3
4
5
6
7
8
9
10
11
12
13
if cpuguy==nil then cpuguy={} end

addhook("startround","cpuguy.Hat")
function cpuguy.Hat(id)
team=player(id,"team")
     for i=1,32 do
          if team == 1 then                -- If player is T
               id=image("gfx/hat/helmet.bmp",1,1,200+i)     -- Create hat @ Player
               else
               id=image("gfx/hat/police.bmp",1,1,200+i)
          end
     end
end

Fine Works !

old Re: Team Hats

Cure Pikachu
User Off Offline

Quote
This is better. No arguments.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
if cpuguy==nil then cpuguy={} end

-- This will let you freely remove images should you want to
hatimage = {}
for a = 1, 32 do
	hatimage[a] = 0
end

addhook("startround","cpuguy.Hat")
function cpuguy.Hat()
	for _, i in ipairs(player(0,"table")) do
		if player(i,"team") == 1 then                -- If player is T
			hatimage[i]=image("gfx/hat/helmet.bmp",1,1,200+i)     -- Create hat @ Player
		elseif player(i,"team") >= 2 then
			hatimage[i]=image("gfx/hat/police.bmp",1,1,200+i)
		end
	end
end

old Re: Team Hats

Suprise
BANNED Off Offline

Quote
@user Cure Pikachu: I think add spawn hook, bcuz if a terrorist join CT team, he will still have Terrorist hat.

add this if you want:
1
2
3
4
5
6
7
8
9
10
11
addhook("spawn","cpuguy.spawn")
function cpuguy.spawn()
	for _, id in ipairs(player(0,"table")) do
		freeimage(hatimage[id])
		if player(id,"team") == 1 then
			hatimage[id]=image("gfx/hat/helmet.bmp",1,1,200+id)
		elseif player(id,"team") == 2 then
			hatimage[id]=image("gfx/hat/police.bmp",1,1,200+id)
		end
	end
end

old Re: Team Hats

Cure Pikachu
User Off Offline

Quote
@user Suprise: So this would be better.
1
2
3
4
5
6
7
8
9
addhook("spawn","cpuguy.spawn")
function cpuguy.spawn(id)
	freeimage(hatimage[id])
	if player(id,"team") == 1 then
		hatimage[id]=image("gfx/hat/helmet.bmp",1,1,200+id)
	elseif player(id,"team") >= 2 then
		hatimage[id]=image("gfx/hat/police.bmp",1,1,200+id)
	end
end

old Re: Team Hats

Infinite Rain
Reviewer Off Offline

Quote
You getting that error because player with this id isn't exists.

To check whether this player is exists or not use: "player(id, 'exists')"
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview