OnPlayerText
#9

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
if(pInfo[playerid][Adminlevel] >= 1)
{
    if(strcmp(text,"!warn",true,5) == 0)
    {
        new ID,reason[50];
        if(sscanf(text[6],"us[50]",ID,reason))
        {
            SendClientMessage(playerid,COLOR_ERROR,"USAGE: !warn (Player Name/ID) (Reason)");
            return 0;
        }
        if(ID == INVALID_PLAYER_ID)
        {
            format(string,sizeof(string),"ID %d is not connected to the server.",ID);
            SendClientMessage(playerid,COLOR_ERROR,string);
            return 0;
        }
        if(WarnTimes[ID] >= 2)
        {
            format(string,sizeof(string),"%s(%d) has been auto kicked from the server because he has reached maximum warnings [3/3 Warnings].",GetName(ID),ID);
            SendClientMessageToAll(COLOR_PINK,string);

            format(string, sizeof(string), "~W~You Have Been ~R~Kicked ~W~From The Server");
            GameTextForPlayer(ID ,string, 99999999999999999999999, 3);
            KickTime[ID] = 3;
            return 0;
        }
        else
        {
            ++WarnTimes[ID];
            format(string,sizeof(string),"%s(%d) has warned %s(%d) reason: %s. [%d/3 Warnings].",GetName(playerid),playerid,GetName(ID),ID,reason,WarnTimes[ID]);
            SendClientMessageToAll(COLOR_PINK,string);
        }
    }
    return 0;
}
or text[5] because it could be invalid memory access xd
That isn't an efficient way to do this. ^^

You should make OnPlayerText forward to a zcmd scripted command. Like below:

pawn Код:
new string[128], cmd[128], params[128]; // Define the parameters with their string size witch will be split.
sscanf(text, "s[128]s[128]", cmd, params); // Split the text into two parameters.
if(pInfo[playerid][AdminLevel] >= 1)
{
      if(strcmp(cmd, "!", true) == 0) return 0; // If player types !, it won't show anything just like when you type /.
      if(strcmp(cmd, "!", true, 1) == 0) // This is needed as it allows the player with admin status chat.
      {
             if(strcmp(cmd, "!nUllstrIngtonoTbeUseddpljmhuyf", true, 31) == 0) return 0; // This fixes the bug when you send a message with a space.
             if(strcmp(cmd, "!warn", true, 5) == 0) {cmd_acmdwarn(playerid, params); return 0;} // This forwards !warn to a zcmd command.
             else
             {
                    format(string,sizeof(string),"{A5FF00}Unknown admin command (%s) | Use !commands to list all available admin commands.", cmd);
                    SendClientMessage(playerid, COLOR_RED, string);
             }
      }
      return 0;
}
If you want to fix the bug with the space for players that don't possess admin status, here it is:
pawn Код:
if(pInfo[playerid][AdminLevel] == 0)
{
     if(strcmp(cmd, " ", true, 1) == 0)
     {
          if(strcmp(cmd, "!nUllstrIngtonoTbeUseddpljmhuyf", true, 31) == 0) return 0;
          return 0;
     }
}
NOTE: If you are going to use the function above put new cmd[128], params[128]; & sscanf(text, "s[128]s[128]", cmd, params); above it.

Good luck buddy!
PS: I'm the friend mentioned above .
Reply


Messages In This Thread
OnPlayerText - by DarkLored - 31.03.2014, 03:28
Re: OnPlayerText - by DarkLored - 31.03.2014, 03:59
Re: OnPlayerText - by LocMax - 31.03.2014, 05:31
Re: OnPlayerText - by DarkLored - 31.03.2014, 22:23
Re: OnPlayerText - by Vince - 31.03.2014, 22:29
Re: OnPlayerText - by DarkLored - 31.03.2014, 22:39
Re: OnPlayerText - by Jefff - 31.03.2014, 22:49
Re: OnPlayerText - by DarkLored - 31.03.2014, 23:13
Re: OnPlayerText - by SickAttack - 01.04.2014, 01:22
Re: OnPlayerText - by Threshold - 01.04.2014, 04:24

Forum Jump:


Users browsing this thread: 3 Guest(s)