Jump to content

Add exceptions to the "max players"


DRW

Recommended Posts

Posted

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?

tJ5zeFm.gif

Proud owner and developer of ZNEXT: Aftermath.

Enter a post-apocalyptic San Andreas and fight over 30 types of enemies and bosses with varying difficulties and skills, improve and customize your character by leveling up, completing challenges and a solid lootbox system with no Pay-to-Win mechanics that will break your experience.

Meet new characters, creatures and weapon metas, experience an innovative combo-based melee system, or join our solid PvP modes to show other survivors who’s boss. 

Español, Pусский, Türk, عربى, Polski, Português

IP: mtasa://104.36.110.227:22003 - Discord: https://discord.gg/CxMxjvC5pB

  • Moderators
Posted

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.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted (edited)
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
Posted
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.

tJ5zeFm.gif

Proud owner and developer of ZNEXT: Aftermath.

Enter a post-apocalyptic San Andreas and fight over 30 types of enemies and bosses with varying difficulties and skills, improve and customize your character by leveling up, completing challenges and a solid lootbox system with no Pay-to-Win mechanics that will break your experience.

Meet new characters, creatures and weapon metas, experience an innovative combo-based melee system, or join our solid PvP modes to show other survivors who’s boss. 

Español, Pусский, Türk, عربى, Polski, Português

IP: mtasa://104.36.110.227:22003 - Discord: https://discord.gg/CxMxjvC5pB

Posted
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
Posted (edited)

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

Edited by DNL291
  • Thanks 2

Please do not PM me with scripting related question nor support, use the forums instead.

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