Forum

> > CS2D > Scripts > Points for individual kills.
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Points for individual kills.

7 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Points for individual kills.

SkullFace
User Off Offline

Zitieren
I've been trying to get a points counter that when you kill an enemy, you get +1 point into that counter.
Now, I've created a shared/global counter.
I don't know how to create so that it is for each individual.
P.S. Only CT's get that counter, since T's are all bots.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
P = {}
P.points = 20

addhook("startround","add_counter")
function add_counter(mode)
	parse('hudtxt 1 "Points: '..P.points..'" 40 40')
end

addhook("kill","for_points")
function for_points(killer,victim,weapon,x,y,killoid,assistant)
	if player(killer,"team") == 2 then
	P.points = P.points + 1
	parse('hudtxt 1 "Points: '..P.points..'" 40 40')
	end
end

alt Re: Points for individual kills.

GeoB99
Moderator Off Offline

Zitieren
Use cs2d cmd hudtxt2 to display a hud text locally for certain players, not cs2d cmd hudtxt!

As for CTs having the counter, you must iterate over only Counter-Terrorist players by using a loop. Remember that cs2d cmd hudtxt2 expects
id
parameter at first which is the player's ID. Such parameter value must come from the loop.

For
add_counter
function, here is a little example:
1
2
3
4
5
function add_counter(mode)
  for _, id in pairs( player(0, 'team2') ) do
    parse('hudtxt2 ' .. id) -- Fill the rest of the parameters inside hudtxt2()
  end
end

alt Re: Points for individual kills.

SkullFace
User Off Offline

Zitieren
Hey, thanks for replying.
But now, every CT will need their own table if they are getting individual points by killing Ts. Because, if CT 1 kills a T, every other CT (2,3,4,...) will also get that point.
How do I go around that ?
I was thinking of adding more tables to the script and that each table is for each player/id.
Just that it seems more lines and messy.

This is my current script for it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
P = {}
P.points = 20

addhook("startround","add_counter")
function add_counter(mode)
	for _, id in pairs( player(0, 'team2') ) do
	parse('hudtxt2 '..id..' 0 "Points: '..P.points..'" 40 40')
	end
end

addhook("kill","for_points")
function for_points(killer,victim,weapon,x,y,killoid,assistant)
	if player(killer,"team") == 2 then
	P.points = P.points + 1
	parse('hudtxt2 '..killer..' 0 "Points: '..P.points..'" 40 40')
	end
end

alt Re: Points for individual kills.

SkullFace
User Off Offline

Zitieren
Thanks, Masea.
Groovy.

This is what I ended up with.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
P = {}

for i = 1, 32 do
	P[i] = 0
end

addhook("second","add_counter")
function add_counter(mode)
	for _, id in pairs( player(0, 'team2') ) do
	parse('hudtxt2 '..id..' 0 "Points: '..P[id]..'" 40 40')
	end
end

addhook("kill","for_points")
function for_points(killer,victim,weapon,x,y,killoid,assistant)
	if player(killer,"team") == 2 then
	P[killer] = P[killer] + 1
	parse('hudtxt2 '..killer..' 0 "Points: '..P[killer]..'" 40 40')
	end
end

alt Re: Points for individual kills.

GeoB99
Moderator Off Offline

Zitieren
Tip, always indent your line of code after
for
or
if
keywords as they're closed by the
end
block. This is to make your code cleaner and easier to read syntax wise.

alt Re: Points for individual kills.

SkullFace
User Off Offline

Zitieren
@user GeoB99: You mean like this ?

e.g. Without indenting
1
2
3
4
5
6
7
addhook("kill","for_points")
function for_points(killer,victim,weapon,x,y,killoid,assistant)
     if player(killer,"team") == 2 then
     P[killer] = P[killer] + 1
     parse('hudtxt2 '..killer..' 0 "Points: '..P[killer]..'" 40 40')
     end
end

With indenting
1
2
3
4
5
6
7
addhook("kill","for_points")
function for_points(killer,victim,weapon,x,y,killoid,assistant)
     if player(killer,"team") == 2 then
->   	P[killer] = P[killer] + 1
->   	parse('hudtxt2 '..killer..' 0 "Points: '..P[killer]..'" 40 40')
     end
end
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht