[Tutorial] How to execute a Joining Counter [C-Projects]
#1

How to create a Joining Counter

Most servers will not have a feature that limits the ability for you to be able to select and choose how many people you would like to join your server at a time. This feature I will be explaining how you will be able to reject players if to many have joined all at once.

Please follow the simple steps below and be warned that this code has not been tested, so use at your own risk.


Step 1: Creating the Variable Required

The variables you will need will be around 3 - 4 that will allow the server to pinpoint and give the correct player the correct value.

Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS 10

#define MAX_JOINING 5

new PlayersJoining;
Step 2: Creating the system itself

This code you will need to alter and place where you have your Players connecting too. Is will refuse if there are more then 5 players trying to connect and kick the ones that are waiting to join.

Код:
public OnPlayerConnect(playerid)
{
	for(new i=0; i<MAX_PLAYERS; i++)
	{
		if(PlayersJoining == 0)
		{
			if(IsPlayerConnected(i))
			{
				PlayersJoining++;
				return 1;
			}
		}
		else if(PlayersJoining == MAX_JOINING)
		{
			if(IsPlayerConnected(i))
			{
				SendClientMessage(i, -1, "Server Notice: You cannot join the server yet, due to high demand of connections");
				Kick(i);
				return 1;
			}
		}
	}
	return 1;
}

public OnPlayerSpawn(playerid)
{
	if(IsPlayerConnected(playerid))
	{
		PlayersJoining--;
	}
	return 1;
}
This is kind of my first sort of tutorial to explain how to make this, not going into every detail but when you see it you will under what section does what.
Reply
#2

If you're not going on detail, it means this is just another snippet. There's many newbies around forums who couldn't understand this one. It's better if you're trying to detail every part of your code. Also, looping always when a player joins is unnecessary. You could increase and decrease the count under OnPlayerConnect and OnPlayerDisconnect which makes things easier as well as on performance wise.

A loop while loading only could be used in case if player has joined before the script got executed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)