Forum

> > CS2D > Scripts > [player] ID in image
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch [player] ID in image

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt [player] ID in image

mrc
User Off Offline

Zitieren
What I'm trying to do is show the HP bar for teammates only.

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

alt Re: [player] ID in image

Marcell
Super User Off Offline

Zitieren
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

alt Re: [player] ID in image

Gaios
Reviewer Off Offline

Zitieren
It's very good that you use a spritesheet to a reduce ping latency. Send me the spritesheet on Discord.

alt Re: [player] ID in image

Mami Tomoe
User Off Offline

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

Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht