English Team Hats

11 replies
Goto Page
To the start Previous 1 Next To the start
15.12.12 12:16:29 am
Up
Computerguy419
User
Offline Off
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
-=8BA=- Computerguy419
15.12.12 12:19:15 am
Up
Cure Pikachu
User
Offline Off
Code:
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.
IMG:https://i.imgur.com/uUrye71.png
IMG:https://i.imgur.com/xpsyQRX.png
15.12.12 12:26:13 am
Up
Computerguy419
User
Offline Off
Code:
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
-=8BA=- Computerguy419
15.12.12 12:54:41 am
Up
sheeL
User
Offline Off
Like This?

Code:
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
15.12.12 01:12:24 am
Up
Computerguy419
User
Offline Off
Ok... this is my whole script:
Code:
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
-=8BA=- Computerguy419
15.12.12 01:35:07 am
Up
sheeL
User
Offline Off
Like 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


if you need help, send pm to me...
15.12.12 02:09:29 am
Up
Computerguy419
User
Offline Off
Using
Code:
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
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


it doesn't but it also doesn't add the image over lay into the game.
-=8BA=- Computerguy419
15.12.12 02:31:32 am
Up
sheeL
User
Offline Off
@user Computerguy419: Looks, Works Perfect Here
Delete all scripts in your archive and put this code

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 !
15.12.12 10:23:04 am
Up
Cure Pikachu
User
Offline Off
This is better. No arguments.
Code:
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
IMG:https://i.imgur.com/uUrye71.png
IMG:https://i.imgur.com/xpsyQRX.png
15.12.12 10:33:30 am
Up
Suprise
BANNED
Offline Off
@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:
Code:
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
15.12.12 11:18:52 am
Up
Cure Pikachu
User
Offline Off
@user Suprise: So this would be better.
Code:
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
IMG:https://i.imgur.com/uUrye71.png
IMG:https://i.imgur.com/xpsyQRX.png
15.12.12 12:17:28 pm
Up
Infinite Rain
Reviewer
Offline Off
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')"
A thousand may fall at your side, ten thousand at your right hand, but it will not come near you. You will only look with your eyes and see the recompense of the wicked. - Psalm 91:7-8 ESV
To the start Previous 1 Next To the start