SA-MP Forums Archive
Loop problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Loop problem (/showthread.php?tid=357760)



Loop problem - DBan - 08.07.2012

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;
}



Re: Loop problem - clarencecuzz - 08.07.2012

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


Re: Loop problem - DBan - 08.07.2012

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.


Re: Loop problem - Slappybay - 08.07.2012

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;
}



Re: Loop problem - ReneG - 08.07.2012

Remove 'return 0;'

Here is what is happening.



Re: Loop problem - DBan - 08.07.2012

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.


Re: Loop problem - clarencecuzz - 08.07.2012

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


Re: Loop problem - Vince - 08.07.2012

[nvm]

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


Re: Loop problem - ReneG - 08.07.2012

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;
}



Re: Loop problem - DBan - 08.07.2012

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.