Forum

> > CS2D > Scripts > Count players and if?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Count players and if?

31 replies
Page
To the start Previous 1 2 Next To the start

old Count players and if?

kRm
User Off Offline

Quote
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?

old Re: Count players and if?

script favor
User Off Offline

Quote
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

old Re: Count players and if?

script favor
User Off Offline

Quote
@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

old Re: Count players and if?

kRm
User Off Offline

Quote
@user j0kER aR: 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

old Re: Count players and if?

script favor
User Off Offline

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

old Re: Count players and if?

GeoB99
Moderator Off Offline

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

old Re: Count players and if?

Yates
Reviewer Off Offline

Quote
@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.
edited 1×, last 25.01.18 06:48:28 pm

old Re: Count players and if?

GeoB99
Moderator Off Offline

Quote
user Yates has written
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.

old Re: Count players and if?

Yates
Reviewer Off Offline

Quote
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.
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview