Forum

> > CS2D > Scripts > Count players and if?
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Count players and if?

31 Antworten
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

alt Count players and if?

kRm
User Off Offline

Zitieren
hello, code is like that
1
2
3
4
5
6
7
8
9
function zp_die(p)
local t = player(p,'team')
if (t == 2) then
parse('maket '..p)
end
	zp_hudtxt2(p,2,1,'',0,0,0)
	zp_hudtxt2(p,4,1,'',0,0,0)
	return 1
end

that means if a ct player die make him t.
but I just want to make like if player count > 1 (that means if more then 1 players is playing on server right now) what should I add on code?

alt Re: Count players and if?

script favor
User Off Offline

Zitieren
Here it is , Not tested.
1
2
3
4
5
6
7
8
9
10
function zp_die(p)
local t = player(p,'team')
local count = 1
if t == 2 and count==1 then
parse('maket '..p)
end
     zp_hudtxt2(p,2,1,'',0,0,0)
     zp_hudtxt2(p,4,1,'',0,0,0)
     return 1
end

alt Re: Count players and if?

script favor
User Off Offline

Zitieren
@user kRm: Now ?

1
2
3
4
5
6
7
8
9
10
11
function zp_die(p)
local t = player(p,'team')
for count = 1,32 do
if t == 2 and count > 1 then
parse('maket '..p)
	end
end
     zp_hudtxt2(p,2,1,'',0,0,0)
     zp_hudtxt2(p,4,1,'',0,0,0)
     return 1
end

alt Re: Count players and if?

kRm
User Off Offline

Zitieren
@user jerezinho: yes I think

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function zp_spawn(p)
	local t = player(p,'team')
	if (t == 1) then
		zp_p_health[p] = set_zm_val(zp_p_class[p],2)
		zp_zombie_set(p)
		zp_class_check(p)
		if (zp_t_tips > 0 and zp_on_tip > 0) then zp_msg2(p,8,'TIP: '..zp_t_tip[math.random(1,#zp_t_tip)]..'@C') end
	elseif (t == 2) then
		zp_wpn_menu_id[p] = 0
		parse('setmaxhealth '..p..' 100')
		if (zp_p_class[p] == -1) then
			parse('maket '..p)
			zp_msg2(p,4,'Nemesis Cant Change Teams!@C')
		end
		if (zp_on_tip > 0) then
			zp_menu_weapon(p)
			if (zp_buy_standart > 0) then zp_msg2(p,8,'Standart Buying Allowed!@C') end
			if (zp_ct_tips > 0) then zp_msg2(p,8,'TIP: '..zp_ct_tip[math.random(1,#zp_ct_tip)]..'@C') end
		end
		zp_p_weapons[p] = 0
	end
	zp_player_hud(p)
	if (zp_hud_flashlight > 0) then zp_light_set(p) end
end

alt Re: Count players and if?

script favor
User Off Offline

Zitieren
tested worked
1
2
3
4
5
6
7
8
9
10
11
function zp_die(p)
local t = player(p,'team')
for i = 1,1 do
if t == 2 then
parse('maket '..p)
     end
end
     zp_hudtxt2(p,2,1,'',0,0,0)
     zp_hudtxt2(p,4,1,'',0,0,0)
     return 1
end

Goodluck.

alt Re: Count players and if?

GeoB99
Moderator Off Offline

Zitieren
For the code to take effect, you have to actually hook the
zp_die
function depending on the conditions or events you want to achieve. In this case we'll take cs2d lua hook die. Please take a look at the documentation of cs2d lua cmd addhook.
1
2
3
4
5
6
7
8
9
10
function zp_die(victim)
  if ( player(victim, 'team') == 2 ) then
    parse('maket ' .. victim)
    zp_hudtxt2(victim, 2, 1, '', 0, 0, 0)
    zp_hudtxt2(victim, 4, 1, '', 0, 0, 0)
    return 0
  end
end

addhook('die', 'zp_die')
As for player counting, you'd simply implement a generic for loop which iterates over existing players and create a condition if the exact count of players is above 1.

alt Re: Count players and if?

Yates
Reviewer Off Offline

Zitieren
@user GeoB99: The function he posted is from file cs2d Zombie Plague Script (v 1.15) , it's already hooked. No need to tell him to hook it again as it will most likely break things rather than fix them.

Also telling someone to simply use the for statement when you can clearly see he has no idea what to do doesn't help (also that's the worst solution ever lol, CS2D has the cs2d lua cmd player function for this).

@user script favor: Please stop posting "solutions" as none of your code makes any sense.

@user kRm: What do you actually want to do? Make players zombies when they die if there is more than 1 person playing?

If so:
1
2
3
4
5
6
7
8
9
10
11
12
13
function zp_die(p)
	local t = player(p,'team')
	local count = #player(0, "table")

	if (t == 2) and count > 1 then
		parse('maket '..p)
	end

	zp_hudtxt2(p,2,1,'',0,0,0)
	zp_hudtxt2(p,4,1,'',0,0,0)

	return 1
end

You will probably break core functions if you use this though. So.. good luck.
1× editiert, zuletzt 25.01.18 18:48:28

alt Re: Count players and if?

GeoB99
Moderator Off Offline

Zitieren
user Yates hat geschrieben
Also telling someone to simply use the for statement when you can clearly see he has no idea what to do doesn't help

This is his problem, not mine. If he has no clue how to code then one should start learning Lua and reading the freaking manual. Just by looking at his erroneously indented code (which is the most prime basic thing for a scripter to learn) I seriously doubt if he can code at all.

alt Re: Count players and if?

Yates
Reviewer Off Offline

Zitieren
As I said, that's Simonas' code. If you don't want to provide sufficient help to people that need it then do what I usually do; don't post.
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht