English Detect amount of players in server

3 replies
Goto Page
To the start Previous 1 Next To the start
Up
SkullFace
User
Offline Off
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.
IMG:https://i.imgur.com/kZBVkjM.gif
P.S. - I've been extracting recently enviromental sound files from other games, if anyone is interested in them for adding them to their maps, scripts, PM me
14.03.18 07:15:35 pm
Up
Fraizeraust
Moderator
Offline Off
See if that helps. Note that you have to change the cs2d cmd mp_kickpercent setting back though if necessary.
Code:
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
14.03.18 07:56:08 pm
Up
SkullFace
User
Offline Off
Thanks, Fraizer!

This helped a lot!

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

Code:
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
IMG:https://i.imgur.com/kZBVkjM.gif
P.S. - I've been extracting recently enviromental sound files from other games, if anyone is interested in them for adding them to their maps, scripts, PM me
14.03.18 08:27:33 pm
Up
Masea
Super User
Offline Off
@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.

Code:
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.
Create and design your GUI easy and fast: file cs2d GUI Framework (12) | Go deep of the darkness and try your intrepidity: file cs2d Outlast 2 Modification (25)
To the start Previous 1 Next To the start