Jump to content

Add exceptions to the "max players"


DRW

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?

Link to comment
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
Link to comment
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.

Link to comment
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
Link to comment

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.
×
×
  • Create New...