MadnessReloaded

Add exceptions to the "max players"

Recommended Posts

So, I want to let some players enter the server despite it being full. So if there's 48/48 players, set it to 49 max players so the player with a specific serial can enter. Is it possible?

I know I can use setMaxPlayers and the "onPlayerConnect" event, but it seems like onPlayerConnect gets cancelled before the max player count updates. Is there any way or workaround to that?

Share this post


Link to post

How about you set it at 49 players and add in the description that it is for 48 players only?

The only way to do this, is by using a second server which will redirect you to the main server.

Share this post


Link to post
MaxPlayers = 48

allowedSerials = {
	[""]=true,
}

function playerJoinKick()
	serial = getPlayerSerial(source)
	if not allowedSerials[serial] and getPlayerCount() >= MaxPlayers then
		kickPlayer(source, "Console", "You tried joining in a reserved slot!")
	end
end
addEventHandler("onPlayerJoin", root, playerJoinKick)

setTimer(function()
	if getPlayerCount() >= MaxPlayers then
    	setMaxPlayers(getPlayerCount() + 1)
    else
      	setMaxPlayers(MaxPlayers)
    end
end,50,0)

Try this.

Edited by DREFTHUN
Added setTimer

Share this post


Link to post
2 minutes ago, DREFTHUN said:

MaxPlayers = 48

allowedSerials = {
	[""]=true,
}

function playerJoinKick()
	serial = getPlayerSerial(source)
	if not allowedSerials[serial] and getPlayerCount() >= MaxPlayers then
		kickPlayer(source, "Console", "You tried joining in a reserved slot!")
	end
end
addEventHandler("onPlayerJoin", root, playerJoinKick)

Try this.

Yeah, I'll try that, although using onPlayerConnect and cancelEvent() will do the trick better. Thank you.

Share this post


Link to post
Just now, MadnessReloaded said:

Yeah, I'll try that, although using onPlayerConnect and cancelEvent() will do the trick better. Thank you.

It won't do the trick better. The method I wrote down is easier then almost anything else.

And check out the edited script too.

  • Confused 2

Share this post


Link to post

onPlayerConnect + cancelEvent () is more appropriate and it will not kick the player from server.

Edited by DNL291
  • Thanks 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.