English [player] ID in image

6 replies
Goto Page
To the start Previous 1 Next To the start
27.05.22 04:32:39 am
Up
mrc
User
Online On
What I'm trying to do is show the HP bar for teammates only.

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function initArray(m)
     local array = {}
     for i = 1, m do
          array[i] = 0
     end
     return array
end

if hp == nil then hp = {} end

local hp = initArray(32,0)

addhook("startround","_startround")
function _startround(mode)
     local players = player(0,'table')
     for i = 1, #players do
          local id = players[i]
          local terrorist = player(0,'team1')
          for i = 1, #terrorist do
               local t = terrorist[i]
               if player(id,'team') == 1 then
                    hp[id] = image('<spritesheet:gfx/cs2dbr/hp/HP.png:32:64:n>',0,1,id+200,t)
                    imageframe(hp[id],1)
               end
          end
          local counterterrorist = player(0,'team2')
          for i = 1, #counterterrorist do
               local ct = counterterrorist[i]
               if player(id,'team') == 2 then
                    hp[id] = image('<spritesheet:gfx/cs2dbr/hp/HP.png:32:64:n>',0,1,id+200,ct)
                    imageframe(hp[id],1)
               end
          end
     end     
end

addhook("hit","_hit")
function _hit(id,source,weapon,hpdmg,apdmg,rawdmg,object)
     timer(0,"_HP")
     function _HP()
          local terrorist = player(0,'team1')
          for i = 1, #terrorist do
               local t = terrorist[i]
               if player(id,'team') == 1 then     
                    if player(id,'health') <= 30 then
                         freeimage(hp[id])
                         hp[id] = image('<spritesheet:gfx/cs2dbr/hp/HP.png:32:64:n>',0,1,id+200,t)
                         imageframe(hp[id],5)
                    elseif player(id,'health') >= 31 and player(id,'health') <= 47 then
                         freeimage(hp[id])
                         hp[id] = image('<spritesheet:gfx/cs2dbr/hp/HP.png:32:64:n>',0,1,id+200,t)
                         imageframe(hp[id],4)
                    elseif player(id,'health') >= 48 and player(id,'health') <= 64 then
                         freeimage(hp[id])
                         hp[id] = image('<spritesheet:gfx/cs2dbr/hp/HP.png:32:64:n>',0,1,id+200,t)
                         imageframe(hp[id],3)     
                    elseif player(id,'health') >= 65 and player(id,'health') <= 81 then
                         freeimage(hp[id])
                         hp[id] = image('<spritesheet:gfx/cs2dbr/hp/HP.png:32:64:n>',0,1,id+200,t)
                         imageframe(hp[id],2)
                    end
               end
          end
          local counterterrorist = player(0,'team2')
          for i = 1, #counterterrorist do
               local ct = counterterrorist[i]
               if player(id,'team') == 2 then     
                    if player(id,'health') <= 30 then
                         freeimage(hp[id])
                         hp[id] = image('<spritesheet:gfx/cs2dbr/hp/HP.png:32:64:n>',0,1,id+200,ct)
                         imageframe(hp[id],5)
                    elseif player(id,'health') >= 31 and player(id,'health') <= 47 then
                         freeimage(hp[id])
                         hp[id] = image('<spritesheet:gfx/cs2dbr/hp/HP.png:32:64:n>',0,1,id+200,ct)
                         imageframe(hp[id],4)
                    elseif player(id,'health') >= 48 and player(id,'health') <= 64 then
                         freeimage(hp[id])
                         hp[id] = image('<spritesheet:gfx/cs2dbr/hp/HP.png:32:64:n>',0,1,id+200,ct)
                         imageframe(hp[id],3)     
                    elseif player(id,'health') >= 65 and player(id,'health') <= 81 then
                         freeimage(hp[id])
                         hp[id] = image('<spritesheet:gfx/cs2dbr/hp/HP.png:32:64:n>',0,1,id+200,ct)
                         imageframe(hp[id],2)
                    end
               end
          end
     end
end
27.05.22 10:01:03 am
Up
Salad Fingers
Super User
Offline Off
Get your current team and use the IDs from the tables
• player(0,"team1"): a Lua table with all terrorist/zombie IDs
• player(0,"team2"): a Lua table with all counter-terrorist/survivor IDs
CS2DArchive - Version Database www.CS2DArchive.com - WebHosting: www.BroHosting.eu
27.05.22 03:25:44 pm
Up
mrc
User
Online On
For some reason it doesnt work.
edited 1×, last 27.05.22 03:53:35 pm
27.05.22 03:34:28 pm
Up
Gaios
Security Supporter
Offline Off
It's very good that you use a spritesheet to a reduce ping latency. Send me the spritesheet on Discord.
27.05.22 03:40:44 pm
Up
Mami Tomoe
User
Offline Off
For the sake of everyone, remove the redundant team checks within the for loops.

You're requesting a table of terrorists and then checking if every player in the table is a terrorist.
The same applies for the counter-terrorists.

Look at me standing, here on my own again
27.05.22 05:35:28 pm
Up
Gaios
Security Supporter
Offline Off
29.05.22 04:21:26 am
Up
mrc
User
Online On
nvm
To the start Previous 1 Next To the start