SendRadioMessage, problem.
#1

Hello, I'm working on a radio system for a friend's GF server, but it doesn't really work well.
The problem is, everyone recieves the radio message, doesn't metter what their stats are. And, if they're not on duty, they will also still recieve the radio message.

Code:
pawn Код:
public SendRadioMessage(playerid, color, string[])
{
foreach(Player, i)
{
    if(!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
    if(PlayerInfo[i][pMember] == 1 || PlayerInfo[i][pLeader] == 1 && PlayerInfo[i][pOnDuty] == 1) // Police force
    {
    SendClientMessage(i, color, string);
    continue;
    }
    else if(PlayerInfo[i][pMember] == 2 || PlayerInfo[i][pLeader] == 2 && PlayerInfo[i][pOnDuty] == 1) // FBI
    {
    SendClientMessage(i, color, string);
    continue;
    }
    else if(PlayerInfo[i][pMember] == 3 || PlayerInfo[i][pLeader] == 3 && PlayerInfo[i][pOnDuty] == 1) // SASP
    {
    SendClientMessage(i, color, string);
    continue;
    }
    else if(PlayerInfo[i][pMember] == 4 || PlayerInfo[i][pLeader] == 4 && JobDuty[i] == 1) // firemen / medic
    {
    SendClientMessage(i, color, string);
    continue;
    }
    else if(PlayerInfo[i][pMember] == 5 || PlayerInfo[i][pLeader] == 5 && PlayerInfo[i][pOnDuty] == 1) // national
    {
    SendClientMessage(i, color, string);
    continue;
    }
    else if(PlayerInfo[i][pMember] == 6 || PlayerInfo[i][pLeader] == 6)
    {
    SendClientMessage(i, color, string);
    continue;
    }
    else if(PlayerInfo[i][pMember] == 7 || PlayerInfo[i][pLeader] == 7)
    {
    SendClientMessage(i, color, string);
    continue;
    }
    else if(PlayerInfo[i][pMember] == 8 || PlayerInfo[i][pLeader] == 8)
    {
    SendClientMessage(i, color, string);
    continue;
    }
    else if(PlayerInfo[i][pMember] == 9 || PlayerInfo[i][pLeader] == 9)
    {
    SendClientMessage(i, color, string);
    continue;
    }
    else if(PlayerInfo[i][pMember] == 10 || PlayerInfo[i][pLeader] == 10)
    {
    SendClientMessage(i, color, string);
    continue;
    }
 }
}
Reply
#2

Delete these continue;
Reply
#3

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
Delete these continue;
Are you sure that's the problem?
Reply
#4

It would be one of the issues.
Reply
#5

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
I would be one of the issues.
Err, you might wanna rephrase that. xD

But yes, the 'i's might be one of the issues, and maybe the continues too.
Reply
#6

The whole point of using foreach is to not have to call IsPlayerConnected. Though, I'm not entirely sure if that's the real problem. And yeah, since you're using an else-if structure, there's no need for the continue;
Reply
#7

You could do this:

pawn Код:
forward SendRadioMessage(membergroup, color, string[]);
pawn Код:
public SendRadioMessage(membergroup, color, string[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            new duty = PlayerInfo[i][pOnDuty];
            if(PlayerInfo[i][pMember] == membergroup && duty == 1 || PlayerInfo[i][pLeader] == membergroup && duty == 1)
            {
                SendClientMessage(i, color, string);
            }
        }
    }
}

And use this at /radio for example:
pawn Код:
SendRadioMessage(1, COLOR_COP, string); // COPS
SendRadioMessage(2, COLOR_COP, string); // FBI
Reply
#8

Alright, new code:

pawn Код:
public SendRadioMessage(playerid, color, string[])
{
foreach(Player, i)
{
    if(PlayerInfo[i][pMember] == 1 || PlayerInfo[i][pLeader] == 1 && PlayerInfo[i][pOnDuty] == 1) // Police force
    {
    SendClientMessage(i, color, string);
    }
    else if(PlayerInfo[i][pMember] == 2 || PlayerInfo[i][pLeader] == 2 && PlayerInfo[i][pOnDuty] == 1) // FBI
    {
    SendClientMessage(i, color, string);
    }
    else if(PlayerInfo[i][pMember] == 3 || PlayerInfo[i][pLeader] == 3 && PlayerInfo[i][pOnDuty] == 1) // SASP
    {
    SendClientMessage(i, color, string);
    }
    else if(PlayerInfo[i][pMember] == 4 || PlayerInfo[i][pLeader] == 4 && JobDuty[i] == 1) // firemen / medic
    {
    SendClientMessage(i, color, string);
    }
    else if(PlayerInfo[i][pMember] == 5 || PlayerInfo[i][pLeader] == 5 && PlayerInfo[i][pOnDuty] == 1) // national
    {
    SendClientMessage(i, color, string);
    }
    else if(PlayerInfo[i][pMember] == 6 || PlayerInfo[i][pLeader] == 6)
    {
    SendClientMessage(i, color, string);
    }
    else if(PlayerInfo[i][pMember] == 7 || PlayerInfo[i][pLeader] == 7)
    {
    SendClientMessage(i, color, string);
    }
    else if(PlayerInfo[i][pMember] == 8 || PlayerInfo[i][pLeader] == 8)
    {
    SendClientMessage(i, color, string);
    }
    else if(PlayerInfo[i][pMember] == 9 || PlayerInfo[i][pLeader] == 9)
    {
    SendClientMessage(i, color, string);
    }
    else if(PlayerInfo[i][pMember] == 10 || PlayerInfo[i][pLeader] == 10)
    {
    SendClientMessage(i, color, string);
    }
 }
}
But it's still exactly the same problem. :/

@Above,
that was the previous code, but I couldn't get the 'if is on duty' blabla working. But I might use your code though, I'll check it.
Reply
#9

Okay, give this a shot.

pawn Код:
public SendRadioMessage(membergroup, color, string[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][pOnDuty] == 1)
            {
                if(PlayerInfo[i][pMember] == membergroup || PlayerInfo[i][pLeader] == membergroup)
                {
                    SendClientMessage(i, color, string);
                }
            }
        }
    }
}
Reply
#10

Updated mine

EDIT: same as RealCop's one.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)