SendRadioMessage, problem. -
Biesmen - 10.12.2010
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;
}
}
}
Re: SendRadioMessage, problem. -
Jochemd - 10.12.2010
Delete these continue;
Re: SendRadioMessage, problem. -
Biesmen - 10.12.2010
Quote:
Originally Posted by Jochemd
Delete these continue;
|
Are you sure that's the problem?
Re: SendRadioMessage, problem. -
Scenario - 10.12.2010
It would be one of the issues.
Re: SendRadioMessage, problem. -
Hiitch - 10.12.2010
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.
Re: SendRadioMessage, problem. -
Vince - 10.12.2010
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;
Re: SendRadioMessage, problem. -
Mokerr - 10.12.2010
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
Re: SendRadioMessage, problem. -
Biesmen - 10.12.2010
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.
Re: SendRadioMessage, problem. -
Scenario - 10.12.2010
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);
}
}
}
}
}
Re: SendRadioMessage, problem. -
Mokerr - 10.12.2010
Updated mine
EDIT: same as RealCop's one.