Occupied Rooms ???
#1

Hello,

I wanted to create an interior (in which you go with /enter) but i want the script to check if someone is already inside.

So if someone is inside they would get a message like "Can't go inside right now, it's occupied!" so i started it like this:

On the top of my script i put:

new InRoom[MAX_PLAYERS];

Then i put this in OnPlayerConnect:

InRoom[playerid] = 0;

And then i made my check like this:
pawn Код:
if(InRoom[playerid] == 1)
     {
      SendClientMessage(playerid, 0xF6345BAA, "Can't go inside sorry ..");
      return 1;
     }
It worked when i was alone on the server, but will it work for others ?

For instance, if i enter that interior could another player enter aswell ? (with my code)

Please tell my if this code is ok, or if it's not please tell me how to fix it. THANKS
Reply
#2

I'm no expert coder, but I'm guessing this might work

Код:
for(new i=0; i<MAX_PLAYERS; i++)
{
	if(IsPlayerConnected(i))
	{
		if(InRoom[i] == 1)
		{
			SendClientMessage(playerid, 0xF6345BAA, "This room is already occupied. Try again later.");
			return 1;
		}
	}
}
Reply
#3

I think this would work, but as i don't have the oportunity to test this, with 2 or more players right now, could someone confirme this ? thanks
Reply
#4

None of those will work, since you use InRoom is an array for playerids. And because two players can't have the same id, the room will be open for everyone
Reply
#5

You have to do a check if anyone else is in the room

pawn Код:
for(new i; i<MAX_PLAYERS; i++)if(InRoom[i])return SendClientMessage(playerid,0xFF0000FF,"OCCUPADO!");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)