OnPlayerCommandPerformed - Read Commands
#1

This seem like it's not working

pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[])
{
    new str[128];
    if(sInfo[ReadCmds] == 1)
    {
        format(str, sizeof(str), "*** %s(ID:%d) : '%s'", GetName(playerid), playerid, cmdtext);
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(pInfo[i][Admin] >= 1)
                {
                    SendClientMessage(i, COLOR_GREY, str);
                }
            }
        }
    }
    return 1;
}
And plus. It makes the other scripts OnPlayerCommandText, OnPlayerCommandPerformed conflict.
Example i've error message when player enter a non-exist command it will show a message.
But when i added this code. It just doesn't said the error message.

Please help me.
Reply
#2

pawn Код:
stock SendMessageToAdmins(  const message[] )
{
        foreach ( new i:Player)
        {
                if(pInfo[i][Admin] >= 1)
                {
                    SendClientMessage(i, COLOR_GREY, message);
                }
         }
return 1;
}
pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    new str[70];
    if ( success )
    {
       format( str, 70, "%s used '%s'.", GetName(playerid), cmdtext);
       SendMessageToAdmins( str );
    }
   return 1;
}
I don't know why this should work, just check it out. Also, you missed the 'success' parameter.
Reply
#3

You forgot the ,,success" parametr in OnPlayerCommandPerformed. This callback should look like this:

pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    new str[128];
    if(sInfo[ReadCmds] == 1)
    {
        format(str, sizeof(str), "*** %s(ID:%d) : '%s'", GetName(playerid), playerid, cmdtext);
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(pInfo[i][Admin] >= 1)
                {
                    SendClientMessage(i, COLOR_GREY, str);
                }
            }
        }
    }
    return 1;
}
@up Damn it, one minut late x_x
Reply
#4

It works fine but one problem.
The error message such as "SERVER: Unknown Command" when typing wrong password is not showing..
Reply
#5

return 0 in OnPlayerCommandPerformed
pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    new str[128];
    if(sInfo[ReadCmds] == 1)
    {
        format(str, sizeof(str), "*** %s(ID:%d) : '%s'", GetName(playerid), playerid, cmdtext);
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(pInfo[i][Admin] >= 1)
                {
                    SendClientMessage(i, COLOR_GREY, str);
                }
            }
        }
    }
    return 0; //This will show the Unknown Command message
}
Reply
#6

@ Above poster, no.
You should keep a break in the loop or it will always return 0. It should be:
pawn Код:
if ( condition )
{
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                if(pInfo[i][Admin] >= 1)
                {
                    SendClientMessage(i, COLOR_GREY, str);
                    continue;
                }
            }
        }
  break;
}
else return 0;
Reply
#7

Rajat it doesn't work it gives me error.
It saids "break" or "continue" might out of (i don't know what it saids).
Reply
#8

break is outside the loop
Reply
#9

pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    new str[128];
    if(sInfo[ReadCmds] == 1)
    {
        if(success)
        {
            format(str, sizeof(str), "*** %s(ID:%d) : '%s'", GetName(playerid), playerid, cmdtext);
            for(new i = 0; i < MAX_PLAYERS; i++)
            {
                if(IsPlayerConnected(i))
                {
                    if((pInfo[i][Admin] > pInfo[playerid][Admin]) && (pInfo[i][Admin] > 1) && (i != playerid))
                    {
                        SendClientMessage(i, COLOR_GREY, str);
                    }
                }
            }
            return 1;
        }
        else return 0;
    }
    return 1;
}
i think this works now.
I test other script's command and no error msgs it works fine now.
Reply
#10

Oh yeah, break was outta the loop, my bad
Cheers
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)