Loop problem
#1

Hello

I am trying to create an admin chat, where an admin will be able to chat simply by putting '@' infront of their message. However, ID 0 is able to see his message, and other messages from other admins, but ID 1 is not able to see his message or message from other admins. I've been scratching my head and getting frustrated for a while, but can't see to find the solution. Any ideas?

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(text[0] == '@')
    {
        foreach(Player, i)
        {
            if(PlayerInfo[i][adminlevel] >= 2)
            {
                format(ccstring, sizeof(ccstring), "[ADM CHAT] %s: %s", GetName(playerid), text[1]);
                SendClientMessage(i, CORANGE, ccstring);
                return 0;
            }
        }
    }
    return 1;
}
Reply
#2

Is ID 1 the only Player not able to see the messages?
Reply
#3

Quote:
Originally Posted by clarencecuzz
Посмотреть сообщение
Is ID 1 the only Player not able to see the messages?
ID 0 is the only one who can see the messages in the admin chat.
Reply
#4

Seeming how only id 0 can see this message, this might possible be the problem in the code.

if(text[0] == '@')

Try this
Код:
public OnPlayerText(playerid, text[])
{
    if(text[playerid] == '@')
    {
        foreach(Player, i)
        {
            if(PlayerInfo[i][adminlevel] >= 2)
            {
                format(ccstring, sizeof(ccstring), "[ADM CHAT] %s: %s", GetName(playerid), text[1]);
                SendClientMessage(i, CORANGE, ccstring);
                return 0;
            }
        }
    }
    return 1;
}
Reply
#5

Remove 'return 0;'

Here is what is happening.
  • Loop starts at zero.
  • ID 0 is admin, and the code continues to the clientmessage code.
  • The clientmessage code is run, and the loop stops running because returning a value instantly stops a block of code.
Reply
#6

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Remove 'return 0;'

Here is what is happening.
  • Loop starts at zero.
  • ID 0 is admin, and the code continues to the clientmessage code.
  • The clientmessage code is run, and the loop stops running because returning a value instantly stops a block of code.
Ah, there's the solution. Thanks for your help.

I actually had to put return 0; there to prevent the text from going into the main chat, but had put it in the wrong place. Thanks for the help.
Reply
#7

I was just about to say remove or change the return 0, but my computer had to restart.
Reply
#8

[nvm]

You should, however, format the message before you enter the loop.
Reply
#9

Also, with that code, any player can go into the admin chat.
pawn Код:
public OnPlayerText(playerid, text[])
{
    if(text[playerid] == '@' && PlayerInfo[playerid][adminlevel] >= 2)
    {
        format(ccstring, sizeof(ccstring), "[ADM CHAT] %s: %s", GetName(playerid), text[1]);
        foreach(Player, i)
        {  
            if(PlayerInfo[i][adminlevel] >= 2)
            {
                SendClientMessage(i, CORANGE, ccstring);
            }
        }
        return 0;
    }
    return 1;
}
Reply
#10

Quote:
Originally Posted by Vince
Посмотреть сообщение
[nvm]

You should, however, format the message before you enter the loop.
Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Also, with that code, any player can go into the admin chat.
pawn Код:
public OnPlayerText(playerid, text[])
{
    if(text[playerid] == '@' && PlayerInfo[playerid][adminlevel] >= 2)
    {
        format(ccstring, sizeof(ccstring), "[ADM CHAT] %s: %s", GetName(playerid), text[1]);
        foreach(Player, i)
        {  
            if(PlayerInfo[i][adminlevel] >= 2)
            {
                SendClientMessage(i, CORANGE, ccstring);
            }
        }
    }
    return 1;
}
Ah, yes, thanks for catching that. Appreciate it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)