Count players and if?
31 replies25.01.18 12:56:41 am
hello, code is like that
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?
Code:
1
2
3
4
5
6
7
8
9
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
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?
Here it is , Not tested.
Code:
1
2
3
4
5
6
7
8
9
10
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
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
@
kRm: Now ?

Code:
1
2
3
4
5
6
7
8
9
10
11
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
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
@
jerelahorca: yes I think

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
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
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
tested worked
Goodluck.
Code:
1
2
3
4
5
6
7
8
9
10
11
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
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.
For the code to take effect, you have to actually hook the
die. Please take a look at the documentation of
addhook.
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.
zp_die
function depending on the conditions or events you want to achieve. In this case we'll take 

Code:
1
2
3
4
5
6
7
8
9
10
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')
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.
@
GeoB99: The function he posted is from
Zombie Plague Script (v 1.15) (203), 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
player function for this).
@
script favor: Please stop posting "solutions" as none of your code makes any sense.
@
kRm: What do you actually want to do? Make players zombies when they die if there is more than 1 person playing?
If so:
You will probably break core functions if you use this though. So.. good luck.



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

@

@

If so:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
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
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

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.
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.
Yeah sure he solved it just like he said:
kRm has written:
10/10 please help again. Go work on your shitty VPS service, thank you.

@
script favor: It didnt worked 


10/10 please help again. Go work on your shitty VPS service, thank you.
Admin/mod comment:

I send him the script on pm and stop flame , fucking kiddy.
Admin/mod comment:
