Forum

> > CS2D > Scripts > Detect amount of players in server
Forums overviewCS2D overview Scripts overviewLog in to reply

English Detect amount of players in server

3 replies
To the start Previous 1 Next To the start

old Detect amount of players in server

Casper-
User Off Offline

Quote
I was searching for a way to be able to detect if there is a certain amount of players in server.

My goal is to detect if there is e.g. 15 players on server, then the votekick would be enabled.
The reason why I'm trying to find this is because on empty servers, 2 players can join 1 server which has votekick enabled.
If a 3rd player joins, both of them can kick you out, just resulting in an abuse of power.

old Re: Detect amount of players in server

GeoB99
Moderator Off Offline

Quote
See if that helps. Note that you have to change the cs2d cmd mp_kickpercent setting back though if necessary.
1
2
3
4
5
6
7
function PlayerCount()
  local PlayerList = #player(0, 'table')

  if ( PlayerList >= 15 ) then
    parse('mp_kickpercent 0.5')
  end
end

old Re: Detect amount of players in server

Casper-
User Off Offline

Quote
Thanks, Fraizer!

This helped a lot!

Here's the code I've ended up with.

1
2
3
4
5
6
7
8
9
10
11
addhook("minute","PlayerCount")
function PlayerCount()

	local PlayerList = #player(0, 'table')

	if ( PlayerList >= 13 ) then
	parse('mp_kickpercent 0.5')	--ENABLED if more than 13
	elseif ( PlayerList <= 12 ) then
	parse('mp_kickpercent 0.0') --DISABLED if less than 13
	end
end

old Re: Detect amount of players in server

Masea
Super User Off Offline

Quote
@user Casper-: Ah, you actually didn't need to bother with writing that long after the
else
. Because there is no other thing that could happen anyway.

1
2
3
4
5
6
7
8
9
10
11
addhook("minute","PlayerCount")
function PlayerCount()

     local PlayerList = #player(0, 'table')

     if ( PlayerList >= 13 ) then
     	parse('mp_kickpercent 0.5')     --ENABLED if more than 13
     else
     	parse('mp_kickpercent 0.0') --DISABLED if less than 13
     end
end
It now is cleaner - just in case.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview