Loop problem
#1

Hi all again..
In my bank robbery (almost finished) i using loop for players who are cop if they connect to the server, if they dont so it won't count them as cop.
when player connects as cop all works perfect but when he disconnect the counting still counts him as cop also if he logged out.
So... here my code with the loop - i tried put LEOOnline--; under public OnPlayerDisconnect but still keep counting :/
What's wrong with this code ? and why after disconnect its -1 ? its IsPlayerConnected(i) so..

Код:
#pragma unused params
		if(IsPlayerConnected(playerid))
		{
	 		for (new i = 0; i < MAX_PLAYERS; i++)
  	 		if (IsPlayerConnected(i) && (PlayerInfo[i][pMember] == 1 || PlayerInfo[i][pLeader] == 1))
            LEOOnline++;

    			if(LEOOnline < 4)
    			{
					SendClientMessage(playerid, COLOR_GRAD3, "You need at least 4 Law Enforcement officers!");
					return 1;
				}
maybe instead of LEOOnline++; i should use LEOOnline += 1; ?
Reply
#2

Anyone? please....
Reply
#3

Try this:

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i ++)
{
    if(IsPlayerConnected(i))
    {
        if(PlayerInfo[i][pMember] == 1 || PlayerInfo[i][pLeader] == 1)
        {
            LEOOnline++;
        }
    }
}
if(LEOOnline < 4) return SendClientMessage(playerid, COLOR_GRAD3, "You need at least 4 Law Enforcement Officers!");
Reply
#4

What about LEOOnline--; ? i dont need it because IsPlayerConnected(i) already takes care of it when player leaves the server?
Reply
#5

No you will need to add that, just change ++ to --
Reply
#6

Add it under pulic OnPlayerDisconnect ? where to add same but with --?
Reply
#7

Yep, it will come at OnPlayerDisconnect callback with --.
Reply
#8

Under what callback is this code? OnPlayerDisconnect? If so try this:
pawn Код:
if(PlayerInfo[playerid][pMember] == 1 || PlayerInfo[playerid][pLeader] == 1) LEOOnline--;
Edit: Do not loop this code!
Reply
#9

Okay i will try that with my friends
Reply
#10

Quote:
Originally Posted by Dragonsaurus
Посмотреть сообщение
Under what callback is this code? OnPlayerDisconnect? If so try this:
pawn Код:
if(PlayerInfo[playerid][pMember] == 1 || PlayerInfo[playerid][pLeader] == 1) LEOOnline--;
Edit: Do not loop this code!
Its under ZCMD command, should i put it under OnPlayerConnect and the other one OnPlayerDisconnect and not under ZCMD commmand?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)