Forum

> > CS2D > Scripts > Detect amount of players in server
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Detect amount of players in server

3 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Detect amount of players in server

SkullFace
User Off Offline

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

alt Re: Detect amount of players in server

GeoB99
Moderator Off Offline

Zitieren
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

alt Re: Detect amount of players in server

SkullFace
User Off Offline

Zitieren
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

alt Re: Detect amount of players in server

Masea
Super User Off Offline

Zitieren
@user SkullFace: 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.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht